Commit aafd5e0
authored
chore: remove usage of tokensChainsCache from useMusdConversionStatus (#28644)
<!--
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**
Removes the usage of `selectERC20TokensByChain` (which reads from
`tokensChainsCache`) in `useMusdConversionStatus`. This is part of a
broader effort to eliminate all usages of `tokensChainsCache` from the
codebase so it can eventually be removed from `TokenListController`.
Previously, `getTokenData` inside the hook's `useEffect` looked up a
token's `symbol` and `name` from the full `tokensChainsCache` via a
`useSelector` + `ref` pattern. This required subscribing to the entire
chain-indexed token list on every render.
The replacement uses `selectSingleTokenByAddressAndChainId` called
directly against `store.getState()` at the moment the transaction event
fires — the same point-in-time store access pattern already used in this
hook for `getTransactionPayQuotes`. Since `metamaskPay.tokenAddress` is
always a token the user holds in their wallet, it is tracked in
`TokensController.allTokens`, making the `tokensChainsCache` lookup
redundant.
Also removes the now-unnecessary `safeToChecksumAddress` import
(previously used to handle both checksummed and lowercase address
lookups, which `selectSingleTokenByAddressAndChainId` handles
internally), and drops the `tokensCacheRef` ref pattern along with the
`useSelector` / `react-redux` import.
<!--
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?
-->
## **Changelog**
<!--
If this PR is not End-User-Facing and should not show up in the
CHANGELOG, you can choose to either:
1. Write `CHANGELOG entry: null`
2. Label with `no-changelog`
If this PR is End-User-Facing, please write a short User-Facing
description in the past tense like:
`CHANGELOG entry: Added a new tab for users to see their NFTs`
`CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker`
(This helps the Release Engineer do their job more quickly and
accurately)
-->
CHANGELOG entry: remove usage of tokensChainsCache from
useMusdConversionStatus
## **Related issues**
Fixes: https://consensyssoftware.atlassian.net/browse/ASSETS-2956
## **Manual testing steps**
```gherkin
Feature: my feature name
Scenario: user [verb for user action]
Given [describe expected initial app state]
When user [verb for user action]
Then [describe expected outcome]
```
## **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 Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.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-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**
> Moderate risk because it changes how token metadata is resolved for
mUSD conversion toasts/metrics (switching data sources and lookup
behavior), which could alter displayed symbols and analytics properties
in edge cases.
>
> **Overview**
> `useMusdConversionStatus` no longer reads `tokensChainsCache` via
`react-redux`/`selectERC20TokensByChain`; it now pulls token
`symbol`/`name` on-demand from `store.getState()` using
`selectSingleTokenByAddressAndChainId`.
>
> Tests are updated to mock the new selector-based lookup, remove the
old chain token-cache setup (including lowercase/checksum fallback
coverage), and adjust the fallback case to treat missing wallet tokens
as `"Token"`.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
9de0418. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 96ee8a5 commit aafd5e0
File tree
2 files changed
+31
-118
lines changed- app/components/UI/Earn/hooks
2 files changed
+31
-118
lines changedLines changed: 22 additions & 101 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
| 21 | + | |
| 22 | + | |
26 | 23 | | |
27 | 24 | | |
28 | 25 | | |
| |||
32 | 29 | | |
33 | 30 | | |
34 | 31 | | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | 32 | | |
39 | 33 | | |
40 | 34 | | |
| |||
54 | 48 | | |
55 | 49 | | |
56 | 50 | | |
57 | | - | |
58 | | - | |
| 51 | + | |
59 | 52 | | |
60 | 53 | | |
61 | 54 | | |
62 | | - | |
63 | 55 | | |
64 | 56 | | |
65 | 57 | | |
| |||
79 | 71 | | |
80 | 72 | | |
81 | 73 | | |
82 | | - | |
83 | | - | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
84 | 77 | | |
85 | 78 | | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | 79 | | |
90 | 80 | | |
91 | 81 | | |
| |||
192 | 182 | | |
193 | 183 | | |
194 | 184 | | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | 185 | | |
199 | 186 | | |
200 | 187 | | |
| |||
223 | 210 | | |
224 | 211 | | |
225 | 212 | | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
| 213 | + | |
| 214 | + | |
236 | 215 | | |
237 | 216 | | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
248 | 225 | | |
249 | 226 | | |
250 | 227 | | |
| |||
364 | 341 | | |
365 | 342 | | |
366 | 343 | | |
367 | | - | |
368 | | - | |
369 | | - | |
370 | | - | |
371 | | - | |
372 | | - | |
373 | | - | |
374 | | - | |
| 344 | + | |
375 | 345 | | |
376 | 346 | | |
377 | 347 | | |
| |||
390 | 360 | | |
391 | 361 | | |
392 | 362 | | |
393 | | - | |
394 | | - | |
395 | | - | |
396 | | - | |
397 | | - | |
398 | | - | |
399 | | - | |
400 | | - | |
401 | | - | |
402 | | - | |
403 | | - | |
404 | | - | |
405 | | - | |
406 | | - | |
407 | | - | |
408 | | - | |
409 | | - | |
410 | | - | |
411 | | - | |
412 | | - | |
413 | | - | |
414 | | - | |
415 | | - | |
416 | | - | |
417 | | - | |
418 | | - | |
419 | | - | |
420 | | - | |
421 | | - | |
422 | | - | |
| 363 | + | |
423 | 364 | | |
424 | 365 | | |
425 | | - | |
426 | | - | |
427 | | - | |
| 366 | + | |
428 | 367 | | |
429 | 368 | | |
430 | 369 | | |
| |||
856 | 795 | | |
857 | 796 | | |
858 | 797 | | |
859 | | - | |
860 | | - | |
861 | | - | |
862 | | - | |
863 | | - | |
864 | | - | |
865 | | - | |
| 798 | + | |
866 | 799 | | |
867 | 800 | | |
868 | 801 | | |
| |||
902 | 835 | | |
903 | 836 | | |
904 | 837 | | |
905 | | - | |
906 | | - | |
907 | | - | |
908 | | - | |
909 | | - | |
910 | | - | |
911 | | - | |
| 838 | + | |
912 | 839 | | |
913 | 840 | | |
914 | 841 | | |
| |||
948 | 875 | | |
949 | 876 | | |
950 | 877 | | |
951 | | - | |
952 | | - | |
953 | | - | |
954 | | - | |
955 | | - | |
956 | | - | |
957 | | - | |
| 878 | + | |
958 | 879 | | |
959 | 880 | | |
960 | 881 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | 8 | | |
10 | | - | |
11 | | - | |
| 9 | + | |
12 | 10 | | |
13 | 11 | | |
14 | 12 | | |
| |||
47 | 45 | | |
48 | 46 | | |
49 | 47 | | |
50 | | - | |
51 | 48 | | |
52 | 49 | | |
53 | 50 | | |
54 | 51 | | |
55 | | - | |
56 | | - | |
57 | 52 | | |
58 | 53 | | |
59 | 54 | | |
| |||
102 | 97 | | |
103 | 98 | | |
104 | 99 | | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
113 | 106 | | |
114 | | - | |
115 | | - | |
116 | | - | |
| 107 | + | |
| 108 | + | |
117 | 109 | | |
118 | 110 | | |
119 | 111 | | |
| |||
0 commit comments