Commit 4e58e96
authored
fix: cp-8.3.0 Fix return undefined token fiat amount instead of locking 1 (MetaMask#33461)
## **Description**
In `useTokenFiatRates`, when a token's price was not found, the code was
falling back to `token?.price ?? 1`, which incorrectly used `1` as a
default price multiplier. This caused the fiat amount to silently return
`conversionRate` instead of indicating no price is available — making it
look like the token was worth 1 unit of the base currency.
This fix changes the behavior to return `undefined` when `token.price`
is falsy, so callers can distinguish between "price not found" and a
real fiat value. The test expectation is updated accordingly.
## **Changelog**
CHANGELOG entry: Fixed `useTokenFiatRates` returning an incorrect fiat
amount (using conversion rate × 1) when a token price is unavailable —
now returns `undefined` instead.
## **Related issues**
Fixes: cherry-pick of MetaMask#33447 (cp-8.3.0)
## **Manual testing steps**
1. Open MetaMask Mobile and navigate to a confirmation screen that
displays token fiat amounts (e.g. a token approval or transfer).
2. Use a token whose price is **not** available in the price feed.
3. Verify the fiat amount for that token shows as unavailable/empty
rather than an incorrect non-zero value.
4. Verify tokens **with** known prices still display the correct fiat
amount.
## **Screenshots/Recordings**
Before:
<img width="530" height="1008" alt="rc - before - send"
src="https://github.com/user-attachments/assets/fb3e58b9-0ae5-43b6-bcca-c39710c4c056"
/>
<img width="530" height="1008" alt="rc - before - mmpay"
src="https://github.com/user-attachments/assets/7778b8bd-fdd1-4203-b6d5-cfcc859b2eb0"
/>
After:
<img width="530" height="1008" alt="rc - after - send"
src="https://github.com/user-attachments/assets/f11099b7-014f-4a1a-a9ef-c64701172712"
/>
<img width="530" height="1008" alt="rc - after - mmpay"
src="https://github.com/user-attachments/assets/bcf9adce-9b26-4fe2-b56e-9165bc9f8a3c"
/>
## **Pre-merge author checklist**
- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/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-mobile/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]
> **Medium Risk**
> Touches MM Pay / confirmation amount and balance USD math when price
feeds are missing; behavior is safer but users may see zero/empty
conversions until prices load.
>
> **Overview**
> Stops **confirmation pay flows** from treating a missing token price
as **1** and showing a bogus fiat value (effectively `conversionRate`
alone).
>
> **`useTokenFiatRates`** now returns **`undefined`** when `token.price`
is absent instead of multiplying by a default `1`. The unit test
expectation is updated from the conversion rate to **`undefined`**.
>
> **`useTransactionCustomAmount`** no longer falls back with `?? 1` on
the pay-token fiat rate. Fiat→token conversion and USD balance helpers
(`amountHuman`, `useTokenBalance` for predict / money-account withdraw)
guard on a defined rate and use **`'0'`** or **`0`** when the rate is
missing, while mUSD still keeps its `?? 1` fallback for money-account
withdraw.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
1bb4320. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 6df2cbe commit 4e58e96
4 files changed
Lines changed: 36 additions & 13 deletions
File tree
- app/components/Views/confirmations/hooks
- tokens
- transactions
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
100 | | - | |
| 100 | + | |
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| |||
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
110 | | - | |
| 110 | + | |
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
| |||
Lines changed: 5 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
59 | 63 | | |
60 | 64 | | |
61 | 65 | | |
| |||
Lines changed: 16 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
18 | 32 | | |
19 | 33 | | |
20 | 34 | | |
21 | | - | |
| 35 | + | |
22 | 36 | | |
23 | 37 | | |
24 | 38 | | |
| |||
Lines changed: 13 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
98 | | - | |
99 | | - | |
| 98 | + | |
100 | 99 | | |
101 | 100 | | |
102 | 101 | | |
| |||
166 | 165 | | |
167 | 166 | | |
168 | 167 | | |
169 | | - | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
170 | 171 | | |
171 | 172 | | |
172 | 173 | | |
| |||
360 | 361 | | |
361 | 362 | | |
362 | 363 | | |
363 | | - | |
| 364 | + | |
364 | 365 | | |
365 | 366 | | |
366 | 367 | | |
| |||
372 | 373 | | |
373 | 374 | | |
374 | 375 | | |
375 | | - | |
376 | | - | |
377 | | - | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
378 | 381 | | |
379 | 382 | | |
380 | 383 | | |
| |||
396 | 399 | | |
397 | 400 | | |
398 | 401 | | |
399 | | - | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
400 | 405 | | |
401 | 406 | | |
402 | 407 | | |
| |||
0 commit comments