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

Commits on Oct 31, 2024

  1. fix: Prevent coercing small spending caps to zero (#28179)

    <!--
    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.
    pedronfigueiredo authored and Gudahtt committed Oct 31, 2024
    Configuration menu
    Copy the full SHA
    d267b4e View commit details
    Browse the repository at this point in the history
  2. Add toNonScientificString

    pedronfigueiredo authored and Gudahtt committed Oct 31, 2024
    Configuration menu
    Copy the full SHA
    3e3e10f View commit details
    Browse the repository at this point in the history