Skip to content

Commit 0b3c740

Browse files
authored
fix(card): delegation issues (#22058)
<!-- 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** <!-- 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? --> This PR addresses several issues affecting the Card experience, ensuring proper asset display, navigation flow, and data consistency across components. Fixes - Fixed an issue where assets were not loading correctly after opening the Card Home screen. - Corrected balance handling on the Change Asset Bottom Sheet — it now displays `availableBalance` for enabled tokens and the user’s total balance for disabled ones. - Restored asset icons on all asset-related bottom sheets. - Fixed incorrect titles on the Spending Limit screen: - Selecting a token that isn’t enabled now correctly shows “Change token and network.” - Pressing “Manage spending limit” on Card Home now correctly shows “Enable token.” - Resolved concurrency issues caused by promise caching in the `useLoadCardData` hook. ## **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: Fixed issue where assets failed to load after opening the Card Home screen. CHANGELOG entry: Fixed balance display on the Change Asset Bottom Sheet to correctly show availableBalance for enabled tokens and user balance for disabled tokens. CHANGELOG entry: Restored missing asset icons on asset bottom sheets. CHANGELOG entry: Fixed incorrect Spending Limit title when selecting a token that’s not enabled (now shows “Change token and network”). CHANGELOG entry: Fixed incorrect Spending Limit title when pressing “Manage spending limit” on Card Home (now shows “Enable token”). CHANGELOG entry: Resolved concurrency and caching issues in useLoadCardData hook. ## **Related issues** Fixes: ## **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** - [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] > Replaces balance logic with aggregated hook, adds pull-to-refresh and spending limit progress/warning on Card Home, fixes navigation/metrics/caching, strengthens delegation/external wallet flows, and adds extensive tests. > > - **Card Home UI**: > - Add pull-to-refresh and toast on enable-card failure. > - Show Spending Limit progress bar and close-to-limit warning; hide controls when enabling assets/card. > - Use `balanceFormatted` fallback when fiat unavailable; update metrics gating and properties. > - **Asset Selection / Spending Limit**: > - Use `useAssetBalances` with per-token keying; show correct balances (available vs wallet), restore icons, exclude Solana where needed. > - Adjust manage flow routing/params and block navigation during delegation; improved input validation and button states. > - **Hooks & Data Flow**: > - Replace `useAssetBalance`/`useAssetsList` with `useAssetBalances` (map-based, multi-token). > - Revise `useLoadCardData` with explicit (re)fetch controls, cache-clearing on auth errors, and concurrency fixes. > - New hooks/util: delegation handling (user-cancel aware), external wallet details with timeout, delegation settings caching, chain/name mapping, safe chainId formatting. > - **SDK**: > - Simplify provider init; add allowance querying robustness (skip non-EVM, timeout) and remove unused mapping. > - **State & i18n**: > - Add global cache clear on logout; new error string for enable-card. > - **Tests**: > - Add/expand tests for AssetSelectionBottomSheet, SpendingLimit, CardHome, delegation, balances, external wallet details, delegation settings, priority token loading, and utilities; update snapshots. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 2f10229. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 3bf2cf9 commit 0b3c740

36 files changed

+7847
-3008
lines changed

app/components/UI/Card/Views/CardHome/CardHome.test.tsx

Lines changed: 310 additions & 146 deletions
Large diffs are not rendered by default.

app/components/UI/Card/Views/CardHome/CardHome.tsx

Lines changed: 176 additions & 45 deletions
Large diffs are not rendered by default.

app/components/UI/Card/Views/CardHome/__snapshots__/CardHome.test.tsx.snap

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,18 @@ exports[`CardHome Component renders correctly and matches snapshot 1`] = `
320320
"paddingBottom": 32,
321321
}
322322
}
323+
refreshControl={
324+
<RefreshControlMock
325+
colors={
326+
[
327+
"#4459ff",
328+
]
329+
}
330+
onRefresh={[Function]}
331+
refreshing={false}
332+
tintColor="#121314"
333+
/>
334+
}
323335
showsVerticalScrollIndicator={false}
324336
style={
325337
{
@@ -328,6 +340,7 @@ exports[`CardHome Component renders correctly and matches snapshot 1`] = `
328340
}
329341
}
330342
>
343+
<RCTRefreshControl />
331344
<View>
332345
<View
333346
style={
@@ -413,6 +426,7 @@ exports[`CardHome Component renders correctly and matches snapshot 1`] = `
413426
}
414427
>
415428
<RNSVGSvgView
429+
address="0x78...x789"
416430
align="xMidYMid"
417431
bbHeight="100%"
418432
bbWidth="100%"
@@ -712,6 +726,55 @@ exports[`CardHome Component renders correctly and matches snapshot 1`] = `
712726
}
713727
/>
714728
</RNSVGGroup>
729+
<RNSVGText
730+
content={null}
731+
dx={[]}
732+
dy={[]}
733+
fill={
734+
{
735+
"payload": 4294967295,
736+
"type": 0,
737+
}
738+
}
739+
font={
740+
{
741+
"fontSize": "40px",
742+
"fontWeight": 800,
743+
}
744+
}
745+
propList={
746+
[
747+
"fill",
748+
]
749+
}
750+
rotate={[]}
751+
x={
752+
[
753+
40,
754+
]
755+
}
756+
y={
757+
[
758+
500,
759+
]
760+
}
761+
>
762+
<RNSVGTSpan
763+
content="0x78...x789"
764+
dx={[]}
765+
dy={[]}
766+
fill={
767+
{
768+
"payload": 4278190080,
769+
"type": 0,
770+
}
771+
}
772+
font={{}}
773+
rotate={[]}
774+
x={[]}
775+
y={[]}
776+
/>
777+
</RNSVGText>
715778
<RNSVGDefs>
716779
<RNSVGClipPath
717780
fill={
@@ -1439,6 +1502,18 @@ exports[`CardHome Component renders correctly with privacy mode enabled 1`] = `
14391502
"paddingBottom": 32,
14401503
}
14411504
}
1505+
refreshControl={
1506+
<RefreshControlMock
1507+
colors={
1508+
[
1509+
"#4459ff",
1510+
]
1511+
}
1512+
onRefresh={[Function]}
1513+
refreshing={false}
1514+
tintColor="#121314"
1515+
/>
1516+
}
14421517
showsVerticalScrollIndicator={false}
14431518
style={
14441519
{
@@ -1447,6 +1522,7 @@ exports[`CardHome Component renders correctly with privacy mode enabled 1`] = `
14471522
}
14481523
}
14491524
>
1525+
<RCTRefreshControl />
14501526
<View>
14511527
<View
14521528
style={
@@ -1532,6 +1608,7 @@ exports[`CardHome Component renders correctly with privacy mode enabled 1`] = `
15321608
}
15331609
>
15341610
<RNSVGSvgView
1611+
address="0x78...x789"
15351612
align="xMidYMid"
15361613
bbHeight="100%"
15371614
bbWidth="100%"
@@ -1831,6 +1908,55 @@ exports[`CardHome Component renders correctly with privacy mode enabled 1`] = `
18311908
}
18321909
/>
18331910
</RNSVGGroup>
1911+
<RNSVGText
1912+
content={null}
1913+
dx={[]}
1914+
dy={[]}
1915+
fill={
1916+
{
1917+
"payload": 4294967295,
1918+
"type": 0,
1919+
}
1920+
}
1921+
font={
1922+
{
1923+
"fontSize": "40px",
1924+
"fontWeight": 800,
1925+
}
1926+
}
1927+
propList={
1928+
[
1929+
"fill",
1930+
]
1931+
}
1932+
rotate={[]}
1933+
x={
1934+
[
1935+
40,
1936+
]
1937+
}
1938+
y={
1939+
[
1940+
500,
1941+
]
1942+
}
1943+
>
1944+
<RNSVGTSpan
1945+
content="0x78...x789"
1946+
dx={[]}
1947+
dy={[]}
1948+
fill={
1949+
{
1950+
"payload": 4278190080,
1951+
"type": 0,
1952+
}
1953+
}
1954+
font={{}}
1955+
rotate={[]}
1956+
x={[]}
1957+
y={[]}
1958+
/>
1959+
</RNSVGText>
18341960
<RNSVGDefs>
18351961
<RNSVGClipPath
18361962
fill={

0 commit comments

Comments
 (0)