Repository navigation
Commit 803491c
authored
fix(rewards): guard pending referral acceptance (#47668)
## **Description**
Closing a referral invite while Accept is pending can submit
registration after the sheet unmounts or record dismissal before a
successful acceptance. Repeated Accept calls can also start duplicate
registrations.
Keep one Accept attempt active through validation, registration, and the
read-back. Disable editing and decline while it runs, ignore dismissal,
and prevent late work from submitting after validation or updating the
UI and analytics after unmount.
Validation: 51 tests passed across five related suites; changed-file
lint and circular dependency checks passed. The full project typecheck
reports errors in unchanged MCP, Discover, and perps files; none were
reported for the four changed files. Manual testing is pending.
## **Changelog**
CHANGELOG entry: Fixed referral invitations allowing dismissal or
duplicate submission while acceptance was pending.
## **Related issues**
Related: #47622, #47665. This fix is independent of referral deep-link
routing.
## **Manual testing steps**
1. Use a development build containing this fix and the referral entry
flow from #47665. Enable Basic Functionality and Money rewards, then
open an invite with an eligible profile and a valid test code.
2. Throttle validation and registration requests. Press Accept, then try
editing the code, accepting again, declining, and closing the sheet.
Verify the sheet stays open, editing/Accept/Decline are disabled, and
only one registration is submitted.
3. Let registration finish. Verify the activation screen opens and the
offer records acceptance without an intervening dismissal. Repeat with
an API refusal and verify retry and dismissal become available
afterward.
4. Lock the wallet while validation or registration is pending. Let the
request settle and unlock. Verify validation does not start registration
after the invite unmounts and late callbacks do not reopen the
activation screen or emit offer interactions from the old sheet.
## **Screenshots/Recordings**
Not captured locally.
<!--
### **Before**
### **After**
-->
## **Pre-merge author checklist**
- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/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-extension/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]
> **Medium Risk**
> Touches referral registration and MetaMetrics interaction timing;
behavior is constrained by new guards and tests but still affects
rewards onboarding UX.
>
> **Overview**
> Fixes a race where users could dismiss the money referral invite or
tap **Accept** again while validation, registration, or referral-me
read-back was still running—leading to duplicate registrations,
dismissal recorded before success, or analytics/UI updates after the
sheet unmounted.
>
> `useAcceptMoneyReferralCode` now treats **`isAccepting` as true for
the whole flow** (not just registration), blocks overlapping `accept`
calls via `acceptingRef`, and **bails out of register, read-back,
`onAccepted`, and state updates** when the hook unmounts mid-flight.
`AcceptInviteSheet` **disables close, decline, code input, and dismiss
handlers** while accepting and **skips acceptance tracking** if the
component unmounted before the promise settles.
>
> Hook and sheet tests add coverage for pending validation/registration,
post-unmount completion, and duplicate Accept.
**`useTokenInsightsData.test.ts`** only adjusts Redux selector
mocking/assertion ordering (no product change).
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
ce0a9b9. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 95528ad commit 803491c
5 files changed
Lines changed: 261 additions & 35 deletions
File tree
- ui
- components/app/rewards/money-referral
- hooks
- rewards
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
68 | 69 | | |
69 | 70 | | |
70 | 71 | | |
71 | | - | |
| 72 | + | |
72 | 73 | | |
73 | 74 | | |
74 | 75 | | |
| |||
407 | 408 | | |
408 | 409 | | |
409 | 410 | | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
410 | 476 | | |
411 | 477 | | |
412 | 478 | | |
| |||
420 | 486 | | |
421 | 487 | | |
422 | 488 | | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
423 | 492 | | |
424 | 493 | | |
425 | 494 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
128 | 136 | | |
129 | 137 | | |
130 | 138 | | |
| |||
274 | 282 | | |
275 | 283 | | |
276 | 284 | | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
277 | 288 | | |
278 | 289 | | |
279 | | - | |
| 290 | + | |
280 | 291 | | |
281 | 292 | | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
282 | 296 | | |
283 | 297 | | |
284 | | - | |
| 298 | + | |
285 | 299 | | |
286 | 300 | | |
287 | 301 | | |
288 | 302 | | |
289 | 303 | | |
290 | 304 | | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
291 | 308 | | |
292 | 309 | | |
293 | 310 | | |
| |||
321 | 338 | | |
322 | 339 | | |
323 | 340 | | |
324 | | - | |
| 341 | + | |
325 | 342 | | |
326 | 343 | | |
327 | 344 | | |
| |||
347 | 364 | | |
348 | 365 | | |
349 | 366 | | |
| 367 | + | |
350 | 368 | | |
351 | 369 | | |
352 | 370 | | |
| |||
390 | 408 | | |
391 | 409 | | |
392 | 410 | | |
| 411 | + | |
393 | 412 | | |
394 | 413 | | |
395 | 414 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
| 6 | + | |
6 | 7 | | |
| 8 | + | |
7 | 9 | | |
8 | 10 | | |
9 | 11 | | |
| |||
94 | 96 | | |
95 | 97 | | |
96 | 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 | + | |
97 | 214 | | |
98 | 215 | | |
99 | 216 | | |
| |||
0 commit comments