fix: calcTokenAmount BigNumber more than 15 digits error#25799
fix: calcTokenAmount BigNumber more than 15 digits error#25799
Conversation
|
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. |
| : totalEthCost; | ||
|
|
||
| const decimalAdjustedDestinationAmount = calcTokenAmount( | ||
| destinationAmount, |
There was a problem hiding this comment.
It's expected that the destinationAmount of a Quote is either a string or null. If it was a null, null would be passed to calcTokenAmount. If it was undefined, it would have been a number type. This fixes the type and expected null handling
Builds ready [d960c70]
Page Load Metrics (262 ± 244 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #25799 +/- ##
========================================
Coverage 69.77% 69.77%
========================================
Files 1398 1398
Lines 49187 49187
Branches 13580 13580
========================================
+ Hits 34318 34319 +1
+ Misses 14869 14868 -1 ☔ View full report in Codecov by Sentry. |
Builds ready [229a5d5]
Page Load Metrics (227 ± 208 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
|
Builds ready [dbfb8b8]
Page Load Metrics (301 ± 314 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|



Description
This PR:
Explanation:
When certain large params are passed, e.g. when the decimal passed is 36, the calculation of
Math.pow(10, Number(decimals || 0))is → 9.999999999999999e+35. Then, when we pass this to BigNumber div() we get the error:new BigNumber(10).pow(decimals)does not have this rounding issue and can be passed to BigNumber div() without the error.We can see the bignumber.js#div code here
Other notes:
Related issues
Fixes: #13738
Related: #25741 (comment)
Manual testing steps
Screenshots/Recordings
Before
(divisor was previously called multiplier)

After
Pre-merge author checklist
Pre-merge reviewer checklist