Repository navigation
Commit 990941d
release(runway): cherry-pick fix(confirmations): compare Money Account pay-token balances as strings (#47981)
- fix(confirmations): compare Money Account pay-token balances as
strings (#47932)
## **Description**
`useAutomaticMoneyAccountPayToken` decides whether to default Pay with
to the Money Account by comparing its balance (a `bignumber.js` value)
with the highest token fiat balance and the minimum required balance.
Those two values are plain JS numbers, and `bignumber.js` 4 throws `gt()
number type has more than 15 significant digits` when it is given a
number with more than 15 significant digits. Fiat balances are computed
in floating point and often have more, so opening a Pay confirmation
(for example a Perps deposit) with such a token balance crashed the
confirmation.
This passes both values to `BigNumber` as strings, which `bignumber.js`
accepts at any precision, and adds a test with a 16-digit fiat balance
(it fails without the fix).
## **Changelog**
CHANGELOG entry: Fixed a crash when opening a MetaMask Pay confirmation
with a token balance that has many decimal places
## **Related issues**
Follow-up to #47836.
## **Manual testing steps**
1. Use an account with a Money Account balance and a token whose fiat
balance has more than 15 significant digits (most non-round balances).
2. Open Perps → Add funds.
3. Before: the confirmation crashes with "gt() number type has more than
15 significant digits". After: it opens, and Pay with defaults as
before.
## **Screenshots/Recordings**
### **Before**
The confirmation shows "MetaMask encountered an error" with `BigNumber
Error: gt() number type has more than 15 significant digits`.
### **After**
The Perps deposit confirmation opens and quotes.
## **Pre-merge author checklist**
- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.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.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Low Risk**
> Small, localized fix in pay-token auto-selection logic with a
regression test; no auth, payment execution, or broad API changes.
>
> **Overview**
> Fixes a **MetaMask Pay confirmation crash** when token fiat balances
exceed JavaScript’s ~15 significant-digit limit passed into
`bignumber.js` `gt()` / `gte()`.
>
> In **`useAutomaticMoneyAccountPayToken`**, the highest token fiat
balance and minimum required balance are now coerced with
**`String(...)`** before **`BigNumber`** comparison (Money Account
withdrawable balance was already a BigNumber). Selection behavior is
unchanged; only the comparison path is safe for high-precision fiat
values.
>
> Adds a hook test with a **16-digit** token fiat balance to ensure
**`shouldSelect`** still works without throwing.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
65878f0. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
[deb08d6](deb08d6)
Co-authored-by: Pedro Figueiredo <pedro.figueiredo@consensys.net>1 parent 76f35ff commit 990941d
2 files changed
Lines changed: 24 additions & 2 deletions
File tree
- ui/pages/confirmations/hooks/pay
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
178 | 178 | | |
179 | 179 | | |
180 | 180 | | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
181 | 197 | | |
182 | 198 | | |
183 | 199 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
99 | | - | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
100 | 104 | | |
101 | 105 | | |
102 | 106 | | |
| |||
107 | 111 | | |
108 | 112 | | |
109 | 113 | | |
110 | | - | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
111 | 117 | | |
112 | 118 | | |
113 | 119 | | |
| |||
0 commit comments