-
Notifications
You must be signed in to change notification settings - Fork 5k
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
fix: Error: new BigNumber() more than 15 digits feat: apply ellipsis #25741
Conversation
- calculation passed to BigNumber may result in over 15 digits which errors - preserve the precision up to formatAmount - currently formatAmount takes away precision after it transforms the value using toNumber to pass to Intl.Number
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
@@ -52,10 +53,15 @@ const PermitSimulation: React.FC<{ | |||
}, [exchangeRate, value]); | |||
|
|||
const { tokenValue, tokenValueMaxPrecision } = useMemo(() => { | |||
const valueBN = new BigNumber(value / Math.pow(10, tokenDecimals)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needed to split the BigNumber constants to use built in pow method since the result of value / Math.pow(10, tokenDecimals)
could lead to an unexpected lengthy number. If it is over 15 digits it would cause the error.
We are also not applying to string on the result of the equation to pass to BigNumber directly because this could also result in precision loss.
Builds ready [1182bb5]
Page Load Metrics (235 ± 236 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 changes look good
...ges/confirmations/components/confirm/info/typed-sign/permit-simulation/permit-simulation.tsx
Show resolved
Hide resolved
ab747cf
Builds ready [d82f208]
Page Load Metrics (153 ± 146 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Quality Gate passedIssues Measures |
Builds ready [fceba54]
Page Load Metrics (71 ± 10 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #25741 +/- ##
===========================================
+ Coverage 69.77% 69.97% +0.19%
===========================================
Files 1376 1390 +14
Lines 48403 48910 +507
Branches 13348 13456 +108
===========================================
+ Hits 33773 34221 +448
- Misses 14630 14689 +59 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Description
Plan is to cherry-pick this PR for V12.1
Note that the precision is lost through formatAmount. Fix will be added #25755
Most file updates are snapshot updates
Related issues
Fixes: https://github.com/MetaMask/MetaMask-planning/issues/2730 (ellipsis)
Fixes: #25751 (Error)
Technical Details
JSON.parse
coerces number values into scientific notation if they are greater than Number.MAX_SAFE_INTEGER, which is the max safe integer in JavaScript.e.g. 30001231231212312138768 → 3.0001231231212312e+22
JSON.parse
reviver cannot help since the value will be coerced by the time itreaches the reviver function.
JSON.parse
value. The preserved value should never be converted to a JavaScript number since it will lose its precision. Instead, we can preserve the value as a string, BigNumber, or Numeric type. BigInt also has rounding limitations.ui/pages/confirmations/components/simulation-details/formatAmount.ts
utilizes Intl.NumberFormat, which requires a BigInt or number passed to it causing a loss in precision when computing large numbers. It does not accept strings. Currently, it will display 0s for the digits after 15 digits.e.g. 30001231231212312138768 → 30,001,231,231,212,312,000,000
Issue ticket to address this [Bug]: Precision is lost displaying Permit value in simulation and data tree #25755
Manual testing steps
yarn storybook
Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist