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
Cherry-pick fix: decimals and fiat conversion crashes in simulation (#24422) into Version-v11.16.0 #24434
Merged
danjm
merged 1 commit into
Version-v11.16.0
from
Version-v11.16.0-cherry-pick-simulation-crash
May 20, 2024
Merged
Cherry-pick fix: decimals and fiat conversion crashes in simulation (#24422) into Version-v11.16.0 #24434
danjm
merged 1 commit into
Version-v11.16.0
from
Version-v11.16.0-cherry-pick-simulation-crash
May 20, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
@metamaskbot update-policies |
Policies updated |
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> This PR fixes 2 bugs in `useBalanceChanges` `NaN` `fetchErc20Decimals` uses `parseInt` to parse the return from getTokenStandardAndDetails. `parseInt` will return `NaN` if it cannot parse the string: ``` > parseInt('0x') NaN ``` This PR patches `fetchErc20Decimals` to try a couple methods of parsing and fall back to the default if none of them work. decimals The constructor and many methods on `BigNumber` will throw an error if you attempt to call them with a javascript number that has more than 15 decimal places. An [explanation can be found here, along with a workaround](MikeMcl/bignumber.js#11 (comment)): Converting these numbers to a string may loose some precision, but is a safe. **New tests added and fixed** ``` ● useBalanceChanges › with token balance changes › uses default decimals when token details are not valid numbers expect(received).toBe(expected) // Object.is equality Expected: 18 Received: 0 271 | await waitForNextUpdate(); 272 | > 273 | expect(result.current.value[0].amount.decimalPlaces()).toBe(18); | ^ 274 | }); 275 | }); 276 | ● useBalanceChanges › with token balance changes › handles token fiat rate with more than 15 significant digits BigNumber Error: times() number type has more than 15 significant digits: 0.1234567890123456 141 | const fiatRate = erc20FiatRates[tokenBc.address]; 142 | const fiatAmount = fiatRate > 143 | ? amount.times(fiatRate).toNumber() | ^ 144 | : FIAT_UNAVAILABLE; 145 | ``` [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/24422?quickstart=1) Fixes: #24336 1. Go to this page... 2. 3. <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> <!-- [screenshots/recordings] --> <!-- [screenshots/recordings] --> - [ ] I’ve followed [MetaMask Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
danjm
force-pushed
the
Version-v11.16.0-cherry-pick-simulation-crash
branch
from
May 20, 2024 21:42
6a527ac
to
cb6e599
Compare
Builds ready [cb6e599]
Page Load Metrics (1367 ± 508 ms)
|
metamaskbot
added
the
release-11.16.0
Issue or pull request that will be included in release 11.16.0
label
May 21, 2024
No release label on PR. Adding release label release-11.16.0 on PR, as PR was cherry-picked in branch 11.16.0. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
INVALID-PR-TEMPLATE
PR's body doesn't match template
release-11.16.0
Issue or pull request that will be included in release 11.16.0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Cherry-pick 603b1b5 (#24422) into Version-v11.16.0
Merge conflict resolved: