-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Ensure exchange rate is stringified before passing to bignumber in token confirm component #12550
Conversation
…nfirm-token-transaction component
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. |
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.
Do we know why bignumber.js
throws on numbers with more than 15 significant digits? If it's a matter of significant digits beyond 15 being unreliable due to floating point error, maybe we're better off truncating our conversion rate to 15 (e.g. using toPrecision(15)
) rather than keeping this additional precision.
Longer-term we should consider using BigInt to perform these calculations in the controllers repo so we don't lose precision from floating point errors, and truncating the calculated value to reflect the amount of precious that was input, and returning the value as a BigInt or at least a string.
Builds ready [d5d50a1]
Page Load Metrics (329 ± 37 ms)
highlights: |
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.
I'll approve for now since this seems like a quick and relatively harmless way to fix the crash, but we should follow up with a better solution that doesn't include spurious digits that give a false impression of how precise this value is.
For more information on that, see https://en.wikipedia.org/wiki/Significant_figures#Rules_to_identify_significant_figures_in_a_number
and https://en.wikipedia.org/wiki/Significant_figures#Multiplication_and_division
@Gudahtt A couple notes regarding big number. In the latest versions, it does not throw when significant digits are greater than 15, unless the Before the latest version, stringifying before passing to bignumber was the recommended approach: MikeMcl/bignumber.js#148 (comment) |
With this change, we introduced the possibility of exchange rate numbers having more than 15 significant digits: MetaMask/core#585
Our current version of
BigNumber
does not handle that well, but does if the number is stringified.Currently in prod, users will hit an error screen when this happens. Here is the associated error record in sentry https://sentry.io/organizations/metamask/issues/2745103173/?project=273505&query=is%3Aunresolved+firstRelease%3Alatest&statsPeriod=14d