Commit 714d6b6
authored
feat(card): Card <> Money Account linkage bottom sheet (#30189)
<!--
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**
This branch delivers Money Account ↔ MetaMask Card linkage improvements:
a confirmation bottom sheet before on-chain delegation, a canonical
“already delegated” signal for the Money feature, post-link refresh of
card home data, concurrent-linkage protection, a developer-only unlink
control, and a small Money deposit-address fix that landed alongside the
merge.
**Branch history (first-parent vs `main`):**
1. `feat(card): add card linkage bottomsheet and selectors` — core
sheet, hook split, delegated selector/helper, controller refresh, tests.
2. `merge with main` — brings current `main` into the branch (reviewers
may see a large merge diff in GitHub; the **feature surface** is the
scoped paths listed under “What changed” below).
3. `feat(card): undo money account enabled feature flag hardcoded` —
restores normal `isMoneyAccountEnabled` behaviour (remote + local flag).
4. `feat(card): remove comments and solve lint issues` — e.g. `no-void`
fix on the link sheet confirm handler; APY interpolation on the sheet;
shared `mm_usd.png` illustration instead of a dedicated asset.
5. `feat(card): add developer section to remove delegation and prevent
duplicates` — Developer Options “Unlink Money Account from Card”;
`CardLinkageInProgressError` + `linkMoneyAccountCard` singleflight +
`isLinkageInProgress()`; hook guard and tests.
### Why
- **UX**: Users should confirm “Spend and earn” before any SIWE /
`approve` / Baanx post-approval runs; sheet dismisses first, then
existing pending / success / error toasts apply.
- **State**: Money views need one place to know the MA is already a card
funding source; `selectIsMoneyAccountDelegatedForCard` + `canLink`
coupling avoids re-link and stranded error toasts.
- **Freshness**: After a successful link, `fetchCardHomeData()` runs so
the new Monad USDC row appears without waiting for another refresh.
- **Safety**: A second “Link card” while the first flow is in flight
must not double-submit; controller singleflight + hook sync check +
silent second tap.
- **Dev tooling**: QA/dev need a way to revoke delegation (`approve(0)`
path via `linkMoneyAccountCard` with `delegationAmountHuman: '0'`).
### What changed (scoped paths vs `main`)
| Area | Files / behaviour |
| --------------------------- |
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| **Link Card sheet** |
[`MoneyLinkCardSheet`](app/components/UI/Money/components/MoneyLinkCardSheet/MoneyLinkCardSheet.tsx)
+ styles, testIds, tests, barrel export;
[`Routes`](app/constants/navigation/Routes.ts) `LINK_CARD_SHEET`;
[`Money` modal stack](app/components/UI/Money/routes/index.tsx) +
[`index.test.tsx`](app/components/UI/Money/routes/index.test.tsx).
Illustration: [`mm_usd.png`](app/images/mm_usd.png) (same as condensed
info cards). Description uses `{{apy}}` via
[`useMoneyAccountBalance`](app/components/UI/Money/hooks/useMoneyAccountBalance.tsx).
CTA uses `.catch(() => undefined)` instead of `void` (ESLint `no-void`).
|
| **Hook** |
[`useMoneyAccountCardLinkage`](app/components/UI/Card/hooks/useMoneyAccountCardLinkage.tsx):
`openLinkCardSheet` / `confirmLinkInBackground`, `canLink` includes
`!isAlreadyDelegated`, sync `isLinkageInProgress()` guard, silent
`CardLinkageInProgressError` handling;
[`useMoneyAccountCardLinkage.test.tsx`](app/components/UI/Card/hooks/useMoneyAccountCardLinkage.test.tsx).
|
| **Money home** |
[`MoneyHomeView`](app/components/UI/Money/Views/MoneyHomeView/MoneyHomeView.tsx)
uses `canLink` + `openLinkCardSheet`; tests updated. |
| **Delegated indicator** |
[`moneyAccountCardToken.ts`](app/core/Engine/controllers/card-controller/utils/moneyAccountCardToken.ts)
+ tests: `isMoneyAccountDelegatedForCard`, CAIP chain constant;
[`cardController.ts`](app/selectors/cardController.ts)
`selectIsMoneyAccountDelegatedForCard` + tests. |
| **Controller** |
[`CardController`](app/core/Engine/controllers/card-controller/CardController.ts):
post-`approveFunding` `fetchCardHomeData()` (errors swallowed + logged);
`linkMoneyAccountCard` singleflight (`#linkMoneyAccountCardUnsafe`),
`isLinkageInProgress()`;
[`CardLinkageInProgressError`](app/core/Engine/controllers/card-controller/provider-types.ts);
extensive
[`CardController.test.ts`](app/core/Engine/controllers/card-controller/CardController.test.ts)
coverage. |
| **Locales** | [`en.json`](locales/languages/en.json):
`money.metamask_card.link_card_sheet_*` (description with `{{apy}}`);
`app_settings.developer_options.card.unlink_money_account_*`. |
| **Developer Options** |
[`CardDeveloperOptionsSection`](app/components/UI/Card/components/CardDeveloperOptionsSection/CardDeveloperOptionsSection.tsx):
unlink row (disabled when not delegated + hint), calls
`linkMoneyAccountCard` with `'0'`;
[`CardDeveloperOptionsSection.test.tsx`](app/components/UI/Card/components/CardDeveloperOptionsSection/CardDeveloperOptionsSection.test.tsx).
|
| **Feature flag** |
[`feature-flags.ts`](app/lib/Money/feature-flags.ts): restore
`validatedVersionGatedFeatureFlag` for Money Account enablement (reverts
debug hardcode). |
| **Money transactions util** |
[`moneyAccountTransactions.ts`](app/components/UI/Money/utils/moneyAccountTransactions.ts):
`getMoneyAccountDepositAssetAddress` uses `MUSD_TOKEN_ADDRESS_BY_CHAIN`
instead of a hardcoded USDC address (came in with branch merge / related
Money work). |
### Out of scope (intentional)
- Replacing Money home onboarding / MetaMask Card copy when already
delegated (selector is ready; UI follow-up optional).
- B3 SpendingLimit MA-mode wiring (separate branch / ticket).
## **Changelog**
CHANGELOG entry: Added a "Spend and earn" confirmation step before
linking your MetaMask Card to your Money Account; prevented duplicate
in-flight linkage submissions; added a developer option to unlink the
Money Account from the card (revoke USDC allowance).
## **Related issues**
Fixes:
## **Manual testing steps**
```gherkin
Feature: Money Account ↔ MetaMask Card linkage
Background:
Given the Money Account feature flag is enabled for my version
And my wallet has a Money Account
And I am authenticated with the MetaMask Card backend
And delegation settings expose the Monad USDC card token
Scenario: confirm linkage from the sheet
Given my Money Account is NOT yet delegated for card usage
And I am on Money home
When I tap the link CTA
Then the "Spend and earn" bottom sheet appears with APY matching Money home
When I tap "Link card" on the sheet
Then the sheet dismisses immediately
And a pending "Linking card" toast appears
When the approval flow completes
Then a success toast appears
And I cannot trigger a second concurrent linkage from a re-opened sheet without duplicate pending toasts (second submit is a silent no-op while the first run is in flight)
Scenario: dismiss sheet without linking
Given the link sheet is open
When I close the sheet without confirming
Then no transaction runs and no pending toast appears
Scenario: already delegated user
Given my Money Account is already delegated for card
When I tap the link CTA on Money home
Then I am taken to Card home without the sheet (no error toast)
Scenario: developer unlink (dev build only)
Given Developer Options are enabled (MM_ENABLE_SETTINGS_PAGE_DEV_OPTIONS)
And my Money Account is delegated for card
When I tap "Unlink Money Account from Card"
Then approve(0) / revoke path runs (no confirmation dialog in dev row)
And the unlink control becomes disabled when no active linkage remains
```
## **Screenshots/Recordings**
### **Before**
<!-- Money home link CTA starts linkage without confirmation sheet;
duplicate submits possible while in flight; no dev unlink row. -->
### **After**
<!-- "Spend and earn" sheet → Link card → dismiss → toasts; optional:
Developer Options Card section with unlink row. -->
## **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.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Touches the card linking flow and
`CardController.linkMoneyAccountCard`, including new concurrency guards
and post-link refresh; mistakes could cause failed/duplicated linkage
attempts or confusing UX, though changes are bounded and well-tested.
>
> **Overview**
> Introduces a new Money modal `MoneyLinkCardSheet` and route
(`Routes.MONEY.MODALS.LINK_CARD_SHEET`) so tapping “Link card” on Money
home opens a confirmation sheet before executing the on-chain
delegation.
>
> Refactors `useMoneyAccountCardLinkage` into `openLinkCardSheet`
(navigation-only) and `confirmLinkInBackground` (runs linkage + toasts),
and makes `canLink` fail closed when
`selectIsMoneyAccountDelegatedForCard` reports the primary Money Account
is already delegated.
>
> Adds a canonical delegated signal via `isMoneyAccountDelegatedForCard`
+ `selectIsMoneyAccountDelegatedForCard`, updates
`CardController.linkMoneyAccountCard` to (1) prevent concurrent
submissions with a new
`CardLinkageInProgressError`/`isLinkageInProgress()` and (2) refresh
card home data post-link (errors swallowed + logged), and adds a
Developer Options “Unlink Money Account from Card” action that submits
the revoke (`delegationAmountHuman: '0'`).
>
> Updates locales and extends/adjusts tests across the Money home view,
linkage hook, controller, selector, and developer options.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
7970343. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent a55aeb3 commit 714d6b6
21 files changed
Lines changed: 1411 additions & 55 deletions
File tree
- app
- components/UI
- Card
- components/CardDeveloperOptionsSection
- hooks
- Money
- Views/MoneyHomeView
- components/MoneyLinkCardSheet
- routes
- core/Engine/controllers/card-controller
- utils
- selectors
- locales/languages
app/components/UI/Card/components/CardDeveloperOptionsSection/CardDeveloperOptionsSection.test.tsx
Lines changed: 222 additions & 22 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
6 | 10 | | |
7 | 11 | | |
8 | 12 | | |
| |||
14 | 18 | | |
15 | 19 | | |
16 | 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 | + | |
17 | 75 | | |
18 | 76 | | |
19 | 77 | | |
| 78 | + | |
| 79 | + | |
20 | 80 | | |
21 | 81 | | |
22 | | - | |
23 | | - | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
24 | 85 | | |
25 | | - | |
26 | | - | |
| 86 | + | |
| 87 | + | |
27 | 88 | | |
28 | | - | |
29 | | - | |
| 89 | + | |
| 90 | + | |
30 | 91 | | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
37 | 104 | | |
38 | | - | |
39 | | - | |
| 105 | + | |
| 106 | + | |
40 | 107 | | |
41 | | - | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
42 | 114 | | |
43 | 115 | | |
44 | | - | |
45 | | - | |
| 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 | + | |
46 | 239 | | |
47 | | - | |
48 | | - | |
| 240 | + | |
49 | 241 | | |
50 | | - | |
51 | | - | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
52 | 252 | | |
53 | 253 | | |
Lines changed: 60 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
16 | 20 | | |
17 | 21 | | |
18 | 22 | | |
19 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
20 | 28 | | |
21 | 29 | | |
22 | 30 | | |
23 | 31 | | |
24 | 32 | | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
25 | 50 | | |
26 | 51 | | |
27 | 52 | | |
| |||
49 | 74 | | |
50 | 75 | | |
51 | 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 | + | |
52 | 111 | | |
53 | 112 | | |
54 | 113 | | |
| |||
0 commit comments