Commit 0b3c740
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
File tree
36 files changed
+7847
-3008
lines changed- app/components/UI/Card
- Views
- CardHome
- __snapshots__
- SpendingLimit
- components
- AssetSelectionBottomSheet
- CardWarningBox
- SpendingLimitProgressBar
- hooks
- sdk
- util
- locales/languages
36 files changed
+7847
-3008
lines changedLines changed: 310 additions & 146 deletions
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Lines changed: 126 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
320 | 320 | | |
321 | 321 | | |
322 | 322 | | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
323 | 335 | | |
324 | 336 | | |
325 | 337 | | |
| |||
328 | 340 | | |
329 | 341 | | |
330 | 342 | | |
| 343 | + | |
331 | 344 | | |
332 | 345 | | |
333 | 346 | | |
| |||
413 | 426 | | |
414 | 427 | | |
415 | 428 | | |
| 429 | + | |
416 | 430 | | |
417 | 431 | | |
418 | 432 | | |
| |||
712 | 726 | | |
713 | 727 | | |
714 | 728 | | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
715 | 778 | | |
716 | 779 | | |
717 | 780 | | |
| |||
1439 | 1502 | | |
1440 | 1503 | | |
1441 | 1504 | | |
| 1505 | + | |
| 1506 | + | |
| 1507 | + | |
| 1508 | + | |
| 1509 | + | |
| 1510 | + | |
| 1511 | + | |
| 1512 | + | |
| 1513 | + | |
| 1514 | + | |
| 1515 | + | |
| 1516 | + | |
1442 | 1517 | | |
1443 | 1518 | | |
1444 | 1519 | | |
| |||
1447 | 1522 | | |
1448 | 1523 | | |
1449 | 1524 | | |
| 1525 | + | |
1450 | 1526 | | |
1451 | 1527 | | |
1452 | 1528 | | |
| |||
1532 | 1608 | | |
1533 | 1609 | | |
1534 | 1610 | | |
| 1611 | + | |
1535 | 1612 | | |
1536 | 1613 | | |
1537 | 1614 | | |
| |||
1831 | 1908 | | |
1832 | 1909 | | |
1833 | 1910 | | |
| 1911 | + | |
| 1912 | + | |
| 1913 | + | |
| 1914 | + | |
| 1915 | + | |
| 1916 | + | |
| 1917 | + | |
| 1918 | + | |
| 1919 | + | |
| 1920 | + | |
| 1921 | + | |
| 1922 | + | |
| 1923 | + | |
| 1924 | + | |
| 1925 | + | |
| 1926 | + | |
| 1927 | + | |
| 1928 | + | |
| 1929 | + | |
| 1930 | + | |
| 1931 | + | |
| 1932 | + | |
| 1933 | + | |
| 1934 | + | |
| 1935 | + | |
| 1936 | + | |
| 1937 | + | |
| 1938 | + | |
| 1939 | + | |
| 1940 | + | |
| 1941 | + | |
| 1942 | + | |
| 1943 | + | |
| 1944 | + | |
| 1945 | + | |
| 1946 | + | |
| 1947 | + | |
| 1948 | + | |
| 1949 | + | |
| 1950 | + | |
| 1951 | + | |
| 1952 | + | |
| 1953 | + | |
| 1954 | + | |
| 1955 | + | |
| 1956 | + | |
| 1957 | + | |
| 1958 | + | |
| 1959 | + | |
1834 | 1960 | | |
1835 | 1961 | | |
1836 | 1962 | | |
| |||
0 commit comments