Commit 721934e
authored
feat(card): add Money Account card linkage hook and inline background linking from Money home (#30057)
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until this PR meets the canonical
Definition of Ready For Review in `docs/readme/ready-for-review.md`.
In short: the template must be materially complete (not just section
titles
present), all status checks must be currently passing, and the only
expected
follow-up commits must be reviewer-driven.
-->
## **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 is the **B2 hook + inline-trigger** branch of the Money Account ↔
Card linkage stack, stacked on top of [#30000 (B1
foundation)](#30000). B1
delivered the `CardController.linkMoneyAccountCard` orchestration; B2
adds the thin UI layer that drives it from the Money home screen.
### Why
After B1, the wallet has a fully-orchestrated, race-safe Money Account →
Card linkage flow in the controller, but it is only invoked from one
wallet path (`useCardDelegation` for the Spending Limit screen). The
Money home "Link card" CTA still navigated the user out to `CARD.HOME`,
which forced an extra screen + tap even when the user already had
everything needed to link in-place (cardholder + authenticated card
session + a primary Money Account on a supported chain).
This PR introduces a dedicated UI hook so any screen can:
- ask the question "is this user ready to link a Card to their Money
Account right now?" (`canLink`), and
- trigger that linkage as a background operation that owns its own toast
UX (`linkInBackground`).
This unblocks B3 (`SpendingLimit` fixed-MA option + `linkInteractive`)
without requiring `SpendingLimit` to know anything about toast plumbing
or selector composition.
### What
| Layer | Change |
| --- | --- |
| **`useMoneyAccountCardLinkage` hook** (new) | UI-only hook wrapping
`Engine.context.CardController.linkMoneyAccountCard`. Exposes
`linkInBackground()`, `status`, `isLinking`, `error`, `reset`, plus the
derived prerequisites (`hasMoneyAccountRequirements`,
`isCardAuthenticated`, `primaryMoneyAccount`, `moneyAccountCardToken`,
`canLink`). Composes the five Money/Card selectors and the
`resolveMoneyAccountCardToken` + `hasMoneyAccountCardRequirements` utils
delivered in B1. **No on-chain logic** — all transaction work stays in
the controller. |
| **Predict-style toasts** | Hook owns three toasts: pending (bold title
+ body + `<Spinner color={PrimaryDefault}>` `startAccessory`,
`hasNoTimeout: true`), success (bold title + non-bold description,
`Confirmation` icon, `success.default` color), error (`Danger` icon,
`error.muted` background, `error.default` color). `UserCancelledError`
is silent — no error toast on user-rejected signatures. |
| **`MoneyHomeView.handleLinkCardPress`** | Now async. When
`isCardholder && isCardAuthenticated && hasMoneyAccountRequirements`, it
calls `linkInBackground()` and returns early — no navigation. Otherwise
the existing `navigation.navigate(Routes.CARD.ROOT, { screen:
Routes.CARD.HOME })` behaviour is preserved. The 4-branch routing helper
(welcome / authentication / fully-ready) is intentionally deferred to
B3. |
| **Locale strings** | Adds `money.metamask_card.link_pending_title`,
`link_pending_description`, `link_success_title`,
`link_success_description`, `link_error`. |
### Out of scope (lands in B3+)
- `linkInteractive({ amount })` on the hook + `useSpendingLimit.submit`
MA dispatch.
- `getNextRouteAfterCardReady` route helper + WELCOME / AUTHENTICATION
navigation branches in `handleLinkCardPress`.
- Removing the 3s `setTimeout` in the wallet submit flow.
- Surfacing `isLinking` on `MoneyMetaMaskCard mode="link"` for disable /
loading affordance.
### Test coverage
- New `useMoneyAccountCardLinkage.test.tsx` — 12 tests covering the
derived-state matrix, happy-path transitions (`idle → pending →
success`), pending toast (Spinner `startAccessory`, `hasNoTimeout:
true`, bold title + non-bold description), success toast, generic error
reject, `UserCancelledError` silent path, fail-closed (`!canLink`), and
`reset`.
- `MoneyHomeView.test.tsx` — adds 4 assertions: regression (no MA
readiness → still navigates to `CARD.HOME`) and fully-ready
inline-linking, for both `MoneyOnboardingCard` CTA and
`MoneyMetaMaskCard` link-button press paths.
- Full `app/components/UI/Card` + `app/components/UI/Money` jest scope:
**2983 tests / 156 suites passing.**
## **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: null
## **Related issues**
Refs: [#30000](#30000)
(B1 foundation)
No issue: internal hook + inline trigger for the Money Account ↔ Card
linkage stack (B2 of a multi-branch stack).
## **Manual testing steps**
```gherkin
Feature: Inline Money Account → Card linkage from Money home
Background:
Given the user is a cardholder
And the user has an authenticated Card session
And the user has a primary Money Account on a supported chain
And the Money Account feature flag is enabled
And the user is on the Money home screen with the "Link card" CTA visible
Scenario: Successful inline linking from Money home
When the user taps "Link card" (either onboarding-card CTA or MetaMaskCard link button)
Then the screen does NOT navigate to Card home
And a pending toast appears with title "Linking card", description "Approving spending limit…", and a spinner icon
And the pending toast persists until the on-chain approval is confirmed
When the approval transaction is confirmed
Then the pending toast is replaced by a success toast with title "Card linked successfully" and description "You can now spend while you earn"
Scenario: User rejects the signature
When the user taps "Link card"
And the user rejects the SIWE signature prompt
Then no error toast is shown
And the user stays on Money home
Scenario: Transaction failure
When the user taps "Link card"
And the on-chain approval fails or times out
Then an error toast appears with title "Couldn't link card"
Scenario: Falls back to navigation when prerequisites are not met
Given the user is a cardholder
But the user is NOT authenticated for Card OR has no Money Account on a supported chain
When the user taps "Link card"
Then the app navigates to Card home (existing behaviour preserved)
```
## **Screenshots/Recordings**
<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->
### **Before**
N/A — no inline linking on Money home; "Link card" always navigated to
`CARD.HOME`.
### **After**
https://github.com/user-attachments/assets/07691435-05a5-4b5d-b80a-f199ccb47c1b
<!-- Pending and error toasts follow the Predict toast style; pending
uses an animated Spinner startAccessory. -->
## **Pre-merge author checklist**
<!--
Every checklist item must be consciously assessed before marking this PR
as
"Ready for review". A checked box means you deliberately considered that
responsibility, not that you literally performed every action listed.
Unchecked boxes are ambiguous: they are not an implicit "N/A" and they
are not
a silent "skip". See `docs/readme/ready-for-review.md` for the full
checklist
semantics.
-->
- [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.
#### Performance checks (if applicable)
- [ ] I've tested on Android
- Ideally on a mid-range device; emulator is acceptable
- [ ] I've tested with a power user scenario
- Use these [power-user
SRPs](https://consensyssoftware.atlassian.net/wiki/spaces/TL1/pages/edit-v2/401401446401?draftShareId=9d77e1e1-4bdc-4be1-9ebb-ccd916988d93)
to import wallets with many accounts and tokens
- [ ] I've instrumented key operations with Sentry traces for production
performance metrics
- See [`trace()`](/app/util/trace.ts) for usage and
[`addToken`](/app/components/Views/AddAsset/components/AddCustomToken/AddCustomToken.tsx#L274)
for an example
For performance guidelines and tooling, see the [Performance
Guide](https://consensyssoftware.atlassian.net/wiki/spaces/TL1/pages/400085549067/Performance+Guide+for+Engineers).
## **Pre-merge reviewer checklist**
<!--
Reviewer checklist items follow the same semantics as the author
checklist: an
unchecked box is ambiguous, a checked box means the reviewer consciously
assessed that responsibility. See `docs/readme/ready-for-review.md`.
-->
- [ ] 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.
<!-- Generated with the help of the pr-description AI skill -->
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Medium risk because it changes Money home CTA behavior to trigger
background card-linking (on-chain flow) and introduces new toast-driven
orchestration around `CardController.linkMoneyAccountCard`, which could
affect user navigation and error handling.
>
> **Overview**
> Adds a new UI hook, `useMoneyAccountCardLinkage`, that derives whether
a user can link a Money Account to a MetaMask Card and, when triggered,
runs `CardController.linkMoneyAccountCard` in the background while
managing pending/success/error toast UX (including a silent user-cancel
path).
>
> Updates `MoneyHomeView` so the “Link card” actions *inline-link* (no
navigation) when `isCardholder && canLink`, otherwise preserving the
existing navigation to `CARD.HOME`. Adds/updates Jest coverage for the
hook and Money home linking behavior, and introduces new locale strings
for the new toasts.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
91d05cd. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 7876524 commit 721934e
5 files changed
Lines changed: 669 additions & 5 deletions
File tree
- app/components/UI
- Card/hooks
- Money/Views/MoneyHomeView
- locales/languages
Lines changed: 336 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
0 commit comments