Commit 3a51914
authored
feat: auto-select fiat payment method for
## **Description**
Modifies the Money Hub "Deposit Funds" flow to use `initiateDeposit`
with auto-fiat-selection instead of the Ramps `goToBuy` flow. When the
user taps "Deposit Funds" in the Add Money sheet, the confirmation
screen now auto-selects the first available fiat payment method
(bank/card) rather than showing the crypto token selector.
**Key implementation details:**
- Extended `useAutomaticTransactionPayToken` to handle fiat
auto-selection atomically: when `autoSelectFiatPayment` is true, the
hook waits for Ramps payment methods to load, then calls
`updateFiatPayment` without calling `setPayToken` (since
`updatePaymentToken` resets `fiatPayment` to `{}` in the controller).
- All three effects in `useAutomaticTransactionPayToken` are guarded
with `hasFiatPaymentSelected` to prevent any instance of the hook from
calling `setPayToken` when a fiat payment method is active — this
protects against the second instance in `usePayWithPreferredToken` (used
by the pay-with bottom sheet) from wiping the fiat selection.
- The "Deposit Funds" option is gated on the `confirmations_pay_fiat`
remote feature flag including `moneyAccountDeposit` in
`enabledTransactionTypes`.
## **Changelog**
CHANGELOG entry: null
## **Related issues**
Fixes:
## **Manual testing steps**
```gherkin
Feature: Auto-select fiat payment for money account deposits
Scenario: user deposits funds via fiat payment
Given the user is on the Money Hub with moneyAccountDeposit enabled in confirmations_pay_fiat feature flag
When user taps "Add funds" then "Deposit funds"
Then the confirmation screen shows with fiat payment method pre-selected (no crypto token flicker)
And the PayAccountSelector and percentage buttons are hidden initially
Scenario: user switches from fiat to crypto payment
Given the confirmation screen shows with fiat payment method pre-selected
When user taps the "Pay with" row and selects a crypto token
Then the PayAccountSelector appears
And percentage buttons appear
And the selected crypto token is shown in the Pay with row
Scenario: deposit funds hidden when feature flag is off
Given moneyAccountDeposit is NOT in the confirmations_pay_fiat enabledTransactionTypes
When user opens the Add Money sheet
Then the "Deposit funds" option is not shown
```
## **Screenshots/Recordings**
### **Before**
https://github.com/user-attachments/assets/31d85902-70b1-46d4-b987-1aaefb8d7ee8
### **After**
https://github.com/user-attachments/assets/09fd4583-3a21-4c2b-a819-464d5ae52458
## **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.
#### 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**
- [ ] 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**
> Changes payment routing and Transaction Pay fiat/token selection for
money account deposits; mitigated by feature flags and tests, but
affects funds-in UX and controller state.
>
> **Overview**
> Money Hub **Deposit funds** now routes through `initiateDeposit` with
**`autoSelectFiatPayment`** instead of the Ramps buy flow, and the sheet
only shows that option when **`confirmations_pay_fiat`** includes
`moneyAccountDeposit`.
>
> On the money-account deposit confirmation screen,
**`autoSelectFiatPayment`** is threaded from navigation params into
**`useAutomaticTransactionPayToken`**, which picks the first eligible
Ramps payment method (respecting max delay) via **`updateFiatPayment`**
and skips **`setPayToken`** so fiat selection is not cleared.
**`CustomAmountInfo`** can hide the account selector and percentage
shortcuts until the user switches to crypto, and hook effects bail out
when a fiat method is already selected.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
1737fd5. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->MoneyAccount "Deposit Funds" action (MetaMask#30713)1 parent b65bcbd commit 3a51914
10 files changed
Lines changed: 212 additions & 64 deletions
File tree
- app/components
- UI/Money
- components/MoneyAddMoneySheet
- hooks
- Views/confirmations
- components
- confirm
- info
- custom-amount-info
- money-account-deposit-info
- hooks/pay
Lines changed: 29 additions & 25 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
6 | | - | |
7 | | - | |
8 | 7 | | |
9 | 8 | | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | 13 | | |
15 | | - | |
16 | 14 | | |
17 | 15 | | |
18 | 16 | | |
19 | 17 | | |
20 | | - | |
21 | | - | |
22 | 18 | | |
23 | 19 | | |
24 | 20 | | |
| |||
32 | 28 | | |
33 | 29 | | |
34 | 30 | | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | 31 | | |
44 | 32 | | |
45 | 33 | | |
| |||
48 | 36 | | |
49 | 37 | | |
50 | 38 | | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
51 | 46 | | |
52 | 47 | | |
53 | 48 | | |
| |||
80 | 75 | | |
81 | 76 | | |
82 | 77 | | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | 78 | | |
92 | 79 | | |
93 | 80 | | |
| |||
98 | 85 | | |
99 | 86 | | |
100 | 87 | | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
101 | 92 | | |
102 | 93 | | |
103 | 94 | | |
| |||
226 | 217 | | |
227 | 218 | | |
228 | 219 | | |
229 | | - | |
| 220 | + | |
230 | 221 | | |
231 | 222 | | |
232 | 223 | | |
233 | 224 | | |
234 | 225 | | |
235 | 226 | | |
236 | 227 | | |
237 | | - | |
238 | | - | |
| 228 | + | |
| 229 | + | |
239 | 230 | | |
240 | 231 | | |
241 | 232 | | |
| |||
250 | 241 | | |
251 | 242 | | |
252 | 243 | | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
253 | 257 | | |
254 | 258 | | |
255 | 259 | | |
| |||
Lines changed: 25 additions & 22 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 | | |
| |||
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
21 | | - | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
27 | 26 | | |
28 | 27 | | |
29 | | - | |
30 | 28 | | |
| 29 | + | |
31 | 30 | | |
32 | 31 | | |
33 | 32 | | |
| |||
54 | 53 | | |
55 | 54 | | |
56 | 55 | | |
57 | | - | |
58 | | - | |
59 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
60 | 62 | | |
61 | 63 | | |
62 | 64 | | |
| |||
72 | 74 | | |
73 | 75 | | |
74 | 76 | | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | 77 | | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | 78 | | |
83 | | - | |
| 79 | + | |
84 | 80 | | |
85 | | - | |
| 81 | + | |
86 | 82 | | |
87 | 83 | | |
88 | 84 | | |
| |||
129 | 125 | | |
130 | 126 | | |
131 | 127 | | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
140 | 143 | | |
141 | 144 | | |
142 | 145 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
201 | 201 | | |
202 | 202 | | |
203 | 203 | | |
| 204 | + | |
204 | 205 | | |
205 | 206 | | |
206 | 207 | | |
| |||
214 | 215 | | |
215 | 216 | | |
216 | 217 | | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
217 | 233 | | |
218 | 234 | | |
219 | 235 | | |
| |||
241 | 257 | | |
242 | 258 | | |
243 | 259 | | |
| 260 | + | |
244 | 261 | | |
245 | 262 | | |
246 | 263 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
| |||
108 | 109 | | |
109 | 110 | | |
110 | 111 | | |
| 112 | + | |
111 | 113 | | |
112 | 114 | | |
113 | 115 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| 61 | + | |
61 | 62 | | |
62 | 63 | | |
63 | 64 | | |
| |||
Lines changed: 24 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
| 75 | + | |
75 | 76 | | |
76 | 77 | | |
77 | 78 | | |
78 | 79 | | |
| 80 | + | |
79 | 81 | | |
80 | 82 | | |
81 | 83 | | |
| |||
104 | 106 | | |
105 | 107 | | |
106 | 108 | | |
| 109 | + | |
107 | 110 | | |
108 | 111 | | |
109 | 112 | | |
110 | 113 | | |
111 | 114 | | |
112 | 115 | | |
| 116 | + | |
113 | 117 | | |
114 | 118 | | |
115 | 119 | | |
| |||
121 | 125 | | |
122 | 126 | | |
123 | 127 | | |
| 128 | + | |
124 | 129 | | |
125 | 130 | | |
126 | 131 | | |
| |||
133 | 138 | | |
134 | 139 | | |
135 | 140 | | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
136 | 147 | | |
137 | 148 | | |
138 | 149 | | |
| |||
239 | 250 | | |
240 | 251 | | |
241 | 252 | | |
242 | | - | |
243 | | - | |
244 | | - | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
245 | 258 | | |
246 | 259 | | |
247 | 260 | | |
248 | 261 | | |
249 | 262 | | |
250 | | - | |
251 | | - | |
252 | | - | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
253 | 266 | | |
254 | 267 | | |
255 | 268 | | |
| |||
276 | 289 | | |
277 | 290 | | |
278 | 291 | | |
279 | | - | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
280 | 296 | | |
281 | 297 | | |
282 | 298 | | |
| |||
0 commit comments