Commit 0828e98
authored
fix(card): cp-7.58.3 physical address consent issue + undefined balances (#22676)
<!--
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 hardens several Card flows:
- Mailing-address consent now recreates or reuses onboarding consent
defensively, mirroring the logic in the physical-address step.
- useWrapWithCache, CardHome, and their test suites now treat cache
errors and expired-card tokens consistently; the home screen shows a
dedicated spinner while auth cleanup runs and only processes each auth
error once.
- Onboarding/Complete now calls
navigation.dispatch(StackActions.replace(...)) (with updated tests) so
we don’t stack duplicate routes after successful onboarding.
- Card login path surfaces the new ACCOUNT_DISABLED error type with the
correct localized messaging.
- These fixes resolve missing-consent crashes, inconsistent
priority-token balances, brittle token-expiration UX, and the lingering
navigation issue after onboarding.
## **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: Improved MetaMask Card onboarding and home flows
(defensive consent creation, consistent balance caching, robust
expired-token handling, and navigation fixes).
## **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]
> Defensively manage consent across onboarding, improve auth-error
cleanup and navigation, refine balance fiat/caching logic, and add
ACCOUNT_DISABLED handling with new consent lookup API.
>
> - **Onboarding**:
> - **Mailing/Physical Address**: Add defensive consent flow
(reuse/create via `getOnboardingConsentSetByOnboardingId`, link user,
clear `consentSetId`); maintain validations and success paths.
Navigation uses replace where appropriate.
> - **Complete screen**: Switch to
`navigation.dispatch(StackActions.replace(...))` and reset onboarding
state before redirect.
> - **Card Home**:
> - Add robust auth-error handling (single-run cleanup, token removal,
Redux reset/cache clear, `StackActions.replace` to welcome, loading
spinner during cleanup) and initial authenticated data load.
> - Preserve/compute balances and spending limit UI as before; minor UX
tweaks.
> - **Hooks**:
> - `useAssetBalances`: Rework fiat formatting and fallbacks (handle
`tokenRateUndefined`/loading strings, raw fiat parsing, proportional
fiat, currency detection), keep Solana/EVM paths; expose consistent map.
> - `useWrapWithCache`: Return real `Error`, avoid auto-retries on
error, prevent refetch while loading, skip caching null/undefined; same
API.
> - `useCardDetails`: Surface `error` object (not enum), keep polling,
warnings.
> - `useGetCardExternalWalletDetails`: Guard auto-fetch on error;
unchanged API.
> - `useGetDelegationSettings`/`useRegistrationSettings`: Align to
`Error` semantics.
> - **SDK/Types**:
> - `CardSDK.login`: detect and surface `ACCOUNT_DISABLED` error; OTP
flows unchanged.
> - Add `getConsentSetByOnboardingId` endpoint support; new
`ConsentSet`/`GetOnboardingConsentResponse` types.
> - **Tests**: Extensive updates/new cases across components and hooks
to cover consent recovery, navigation replace, auth cleanup order,
cache/error behavior, and fiat formatting.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
9e3b88d. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent e700d86 commit 0828e98
File tree
26 files changed
+2818
-308
lines changed- app/components/UI/Card
- Views/CardHome
- components/Onboarding
- hooks
- sdk
26 files changed
+2818
-308
lines changedLarge diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
25 | | - | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
58 | 59 | | |
59 | 60 | | |
60 | 61 | | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | 62 | | |
| 63 | + | |
66 | 64 | | |
67 | 65 | | |
68 | 66 | | |
| |||
97 | 95 | | |
98 | 96 | | |
99 | 97 | | |
| 98 | + | |
100 | 99 | | |
101 | 100 | | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
102 | 105 | | |
103 | 106 | | |
104 | 107 | | |
| |||
190 | 193 | | |
191 | 194 | | |
192 | 195 | | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | 196 | | |
197 | 197 | | |
198 | 198 | | |
| |||
497 | 497 | | |
498 | 498 | | |
499 | 499 | | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
500 | 507 | | |
501 | 508 | | |
502 | 509 | | |
503 | | - | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
504 | 517 | | |
505 | 518 | | |
506 | 519 | | |
507 | | - | |
508 | | - | |
509 | | - | |
510 | | - | |
511 | | - | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
512 | 530 | | |
513 | | - | |
| 531 | + | |
514 | 532 | | |
515 | | - | |
516 | | - | |
517 | | - | |
518 | | - | |
519 | 533 | | |
520 | | - | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
521 | 539 | | |
522 | 540 | | |
523 | | - | |
524 | | - | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
525 | 552 | | |
526 | 553 | | |
527 | 554 | | |
528 | 555 | | |
529 | | - | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
530 | 569 | | |
531 | 570 | | |
532 | 571 | | |
| |||
565 | 604 | | |
566 | 605 | | |
567 | 606 | | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
568 | 617 | | |
569 | 618 | | |
570 | 619 | | |
| |||
Lines changed: 61 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
8 | 15 | | |
9 | 16 | | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
10 | 23 | | |
11 | 24 | | |
12 | 25 | | |
| |||
147 | 160 | | |
148 | 161 | | |
149 | 162 | | |
150 | | - | |
151 | 163 | | |
152 | 164 | | |
153 | 165 | | |
154 | 166 | | |
155 | 167 | | |
156 | 168 | | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
157 | 172 | | |
158 | 173 | | |
159 | | - | |
| 174 | + | |
160 | 175 | | |
161 | 176 | | |
162 | 177 | | |
| |||
228 | 243 | | |
229 | 244 | | |
230 | 245 | | |
231 | | - | |
| 246 | + | |
232 | 247 | | |
233 | 248 | | |
234 | 249 | | |
235 | 250 | | |
236 | 251 | | |
237 | 252 | | |
238 | | - | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
239 | 257 | | |
240 | 258 | | |
241 | 259 | | |
242 | | - | |
| 260 | + | |
243 | 261 | | |
244 | 262 | | |
245 | 263 | | |
246 | 264 | | |
247 | 265 | | |
248 | 266 | | |
249 | | - | |
| 267 | + | |
250 | 268 | | |
251 | 269 | | |
252 | 270 | | |
253 | 271 | | |
254 | 272 | | |
255 | | - | |
256 | | - | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
257 | 296 | | |
258 | 297 | | |
259 | 298 | | |
| |||
265 | 304 | | |
266 | 305 | | |
267 | 306 | | |
268 | | - | |
| 307 | + | |
269 | 308 | | |
270 | 309 | | |
271 | 310 | | |
272 | 311 | | |
273 | 312 | | |
274 | 313 | | |
275 | | - | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
276 | 318 | | |
277 | 319 | | |
278 | 320 | | |
| |||
403 | 445 | | |
404 | 446 | | |
405 | 447 | | |
406 | | - | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
407 | 452 | | |
408 | 453 | | |
409 | 454 | | |
| |||
418 | 463 | | |
419 | 464 | | |
420 | 465 | | |
421 | | - | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
422 | 470 | | |
423 | 471 | | |
424 | 472 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
| 48 | + | |
48 | 49 | | |
49 | | - | |
| 50 | + | |
| 51 | + | |
50 | 52 | | |
51 | | - | |
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
| |||
0 commit comments