Skip to content
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

Merged
merged 2 commits into from
Oct 31, 2024

Conversation

pedronfigueiredo
Copy link
Contributor

@pedronfigueiredo pedronfigueiredo commented Oct 30, 2024

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 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.

Open in GitHub Codespaces

Related issues

Fixes:
#28117

Manual testing steps

See original bug report.

Screenshots/Recordings

Before

After

Pre-merge author checklist

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.

Description

Open in GitHub Codespaces

Related issues

Fixes:

Manual testing steps

  1. Go to this page...

Screenshots/Recordings

Before

After

Pre-merge author checklist

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.

@pedronfigueiredo pedronfigueiredo added the team-confirmations Push issues to confirmations team label Oct 30, 2024
@pedronfigueiredo pedronfigueiredo self-assigned this Oct 30, 2024
@pedronfigueiredo pedronfigueiredo requested a review from a team as a code owner October 30, 2024 15:01
Copy link
Contributor

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.

DDDDDanica
DDDDDanica previously approved these changes Oct 30, 2024
@metamaskbot
Copy link
Collaborator

Builds ready [ad45e56]
Page Load Metrics (2042 ± 71 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint56723651961352169
domContentLoaded17202356201715373
load17792366204214871
domInteractive289462168
backgroundConnect106424199
firstReactRender50130100188
getState56214157
initialActions01000
loadScripts12511870149113163
setupStore1277362512
uiStartup19802559226316177
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 3.1 KiB (0.06%)
  • ui: 1.13 KiB (0.01%)
  • common: 284 Bytes (0.00%)

@@ -15,6 +15,15 @@ function isSpendingCapUnlimited(decodedSpendingCap: number) {
return decodedSpendingCap >= UNLIMITED_THRESHOLD;
}

function toNonScientificString(num: number): string {
Copy link
Member

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).

Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@hjetpoluru
Copy link
Contributor

Is this needed as it was not present in the original PR merged to develop.
Screenshot 2024-10-31 at 3 52 36 PM

@Gudahtt
Copy link
Member

Gudahtt commented Oct 31, 2024

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.
@metamaskbot
Copy link
Collaborator

Builds ready [3e3e10f]
Page Load Metrics (2233 ± 124 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint31032532142521250
domContentLoaded187527552181227109
load189129342233259124
domInteractive33131602110
backgroundConnect10204465627
firstReactRender613011235024
getState64865010349
initialActions00000
loadScripts13552105163219493
setupStore13331577034
uiStartup209941062557460221
Bundle size diffs [🚀 Bundle size reduced!]
  • background: -168.37 KiB (-3.37%)
  • ui: 4.42 KiB (0.06%)
  • common: 107.58 KiB (1.36%)

@danjm danjm merged commit f644102 into Version-v12.6.0 Oct 31, 2024
72 checks passed
@danjm danjm deleted the pnf/cherry-pick-28179 branch October 31, 2024 21:49
@github-actions github-actions bot locked and limited conversation to collaborators Oct 31, 2024
@metamaskbot metamaskbot added the release-12.6.0 Issue or pull request that will be included in release 12.6.0 label Oct 31, 2024
@metamaskbot
Copy link
Collaborator

No release label on PR. Adding release label release-12.6.0 on PR, as PR was cherry-picked in branch 12.6.0.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-12.6.0 Issue or pull request that will be included in release 12.6.0 team-confirmations Push issues to confirmations team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants