Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve numeric precision with BigNumber.js #952

Merged
merged 16 commits into from
Aug 5, 2022
Merged

Improve numeric precision with BigNumber.js #952

merged 16 commits into from
Aug 5, 2022

Conversation

lukaw3d
Copy link
Member

@lukaw3d lukaw3d commented Aug 3, 2022

Fixes #436

Related #932 (comment)

@lukaw3d lukaw3d requested review from buberdds and pro-wh August 3, 2022 06:16
Comment on lines +72 to +78
/**
* `<input max="9000000000.111111111">` warns about <=9000000000.11111 so we
* round up to `<input max="9000000000.11112">`
*/
const roundedUpStringifiedFloatMaxAmount = new BigNumber(props.maxAmount)
.shiftedBy(-9) // / 10 ** 9
.toPrecision(15, BigNumber.ROUND_UP)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chrome seems to parse <input max=".."> into a double-float, so we need to be round up when it hits the limit of double-float precision. Is there a good way to describe this operation? And a better way to implement it?

This implementation relies on double-float having at least 15 significant decimal digits.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've heard other teams had to stop using <input type="number" because of this.

@@ -76,8 +89,8 @@ export const ReclaimEscrowForm = memo((props: Props) => {
placeholder={t('common.amount')}
type="number"
step="any"
min={0.0001}
max={Number(props.maxAmount) / 10 ** 9}
min="0"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there some minimum amount for ReclaimEscrow?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link

github-actions bot commented Aug 3, 2022

MegaLinter status: ✅ SUCCESS

Descriptor Linter Files Fixed Errors Elapsed time
✅ EDITORCONFIG editorconfig-checker 37 0 0.07s
✅ GIT git_diff yes no 0.01s
✅ JSON eslint-plugin-jsonc 1 0 0 0.9s
✅ JSON jsonlint 1 0 0.25s
✅ JSON prettier 1 0 0 0.49s
✅ JSON v8r 1 0 4.14s
✅ TSX eslint 19 0 0 8.16s
✅ TYPESCRIPT eslint 11 0 0 4.8s

See errors details in artifact MegaLinter reports on CI Job page
Set VALIDATE_ALL_CODEBASE: true in mega-linter.yml to validate all sources, not only the diff

@codecov
Copy link

codecov bot commented Aug 3, 2022

Codecov Report

Merging #952 (4f48193) into master (2b386f8) will increase coverage by 0.17%.
The diff coverage is 83.78%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #952      +/-   ##
==========================================
+ Coverage   88.31%   88.49%   +0.17%     
==========================================
  Files          97       98       +1     
  Lines        1678     1695      +17     
  Branches      388      390       +2     
==========================================
+ Hits         1482     1500      +18     
+ Misses        196      195       -1     
Flag Coverage Δ
cypress 58.45% <47.22%> (+0.21%) ⬆️
jest 79.25% <83.78%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/app/components/AddEscrowForm/index.tsx 92.30% <ø> (ø)
...ponents/Toolbar/Features/AccountSelector/index.tsx 100.00% <ø> (ø)
...ges/AccountPage/Features/SendTransaction/index.tsx 92.59% <ø> (ø)
...es/StakingPage/Features/CommissionBounds/index.tsx 94.44% <ø> (ø)
src/app/state/account/saga.ts 73.91% <ø> (+10.86%) ⬆️
src/types/StringifiedBigInt.ts 0.00% <0.00%> (ø)
...pages/StakingPage/Features/ValidatorList/index.tsx 67.64% <66.66%> (-0.93%) ⬇️
...ages/StakingPage/Features/DelegationList/index.tsx 83.78% <75.00%> (+0.92%) ⬆️
src/app/pages/AccountPage/index.tsx 96.29% <83.33%> (-1.75%) ⬇️
src/app/lib/helpers.ts 75.51% <85.71%> (+2.53%) ⬆️
... and 4 more

src/app/components/AmountFormatter/index.tsx Outdated Show resolved Hide resolved
@lukaw3d lukaw3d merged commit b96eb8f into master Aug 5, 2022
@lukaw3d lukaw3d deleted the lw/bignum branch August 5, 2022 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Validator fee rounding issue
3 participants