-
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
fix: cherry-pick: Prevent coercing small spending caps to zero (#28179) #28183
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. |
Builds ready [ad45e56]
Page Load Metrics (2042 ± 71 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
@@ -15,6 +15,15 @@ function isSpendingCapUnlimited(decodedSpendingCap: number) { | |||
return decodedSpendingCap >= UNLIMITED_THRESHOLD; | |||
} | |||
|
|||
function toNonScientificString(num: number): string { |
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.
Note for other reviewers, this function was ported here from this other recent PR: #27992
This will create a conflict when we merge this back into develop
; we'll need to update this file to import this function instead if using it inlined here (i.e. we'll need to accept the develop
version when it conflicts, as we typically would).
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!
Thanks for highlighting @hjetpoluru; the extra changes are to bring in a function that the cherry-picked code depends upon. I left a comment on this here: #28183 (comment) |
<!-- 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. --> ## **Description** Previously there was a bug that affected the approve screen. When users had a small spending cap (between 0.001 and 0.0001 or smaller), it was coerced to 0. This was caused by the method `new Intl.NumberFormat(locale).format(spendingCap)` that applied the `1,000` large number formatting, so the fix is to bypass it entirely for values smaller than 1. Additionally, these unformatted small numbers are presented in scientific notation, so we leverage `toNonScientificString(spendingCap)` to prevent that. <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/28179?quickstart=1) ## **Related issues** Fixes: [#28117](#28117) ## **Manual testing steps** See original bug report. ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [ ] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension 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. ## **Pre-merge reviewer checklist** - [ ] 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.
ad45e56
to
3e3e10f
Compare
Builds ready [3e3e10f]
Page Load Metrics (2233 ± 124 ms)
Bundle size diffs [🚀 Bundle size reduced!]
|
No release label on PR. Adding release label release-12.6.0 on PR, as PR was cherry-picked in branch 12.6.0. |
Cherry-pick: #28179
Description
Previously there was a bug that affected the approve screen. When users had a small spending cap (between 0.001 and 0.0001 or smaller), it was coerced to 0.
This was caused by the method
new Intl.NumberFormat(locale).format(spendingCap)
that applied the1,000
large number formatting, so the fix is to bypass it entirely for values smaller than 1.Additionally, these unformatted small numbers are presented in scientific notation, so we leverage
toNonScientificString(spendingCap)
to prevent that.Related issues
Fixes:
#28117
Manual testing steps
See original bug report.
Screenshots/Recordings
Before
After
Pre-merge author checklist
Standards.
Pre-merge reviewer checklist
Description
Related issues
Fixes:
Manual testing steps
Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist