Commit d54ea81
authored
feat: debounce points estimation & alt fox icon if points is 0 (#37575)
## **Description**
Previous PR related to rewards point estimation for swaps/bridge was not
debouncing the estimation API call, which due to react dependency for
active quote, resulted in sometimes doing X API calls instead of 1 for
the last active quote.
This PR fixes that by adding debouncing logic to `useRewards`. It also
changes the fox icon color to alternative variant if points retrieved is
0. (just like in mobile)
## **Changelog**
CHANGELOG entry: null
## **Related issues**
Fixes: https://consensyssoftware.atlassian.net/browse/RWDS-613
## **Manual testing steps**
1. Have an account that is opted into rewards
2. Go to swaps page and open network tab
3. There should only be 1 call made to the estimation endpoint for
rewards
## **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**
- [x] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [x] 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]
> Debounces rewards points estimation in useRewards, adds alt icon when
points = 0, improves auth/opt-in flow and handles SeasonNotFound errors,
with comprehensive tests.
>
> - **Hooks (useRewards)**:
> - Add 750ms debounced `estimateRewardsPoints` flow using
`lodash.debounce` to prevent duplicate calls.
> - Refine opt-in checks, loading/error states, and USD fee price
calculation; guard early-return conditions.
> - Extensive tests for debounce behavior, error handling, loading, and
selector stubs; use fake timers.
> - **Controller (RewardsController)**:
> - Prefetch bulk `getOptInStatus` during auth trigger; iterate silent
auth by sorted accounts.
> - Tighten `shouldSkipSilentAuth` to require both `subscriptionId` and
a session token.
> - On `SeasonNotFoundError`, clear `rewardsSeasons` only; preserve
accounts/subscriptions.
> - Tests for silent auth without token and season-not-found cache
clearing.
> - **Data Service (RewardsDataService)**:
> - Introduce `SeasonNotFoundError`; map 404 "Season not found"
responses in `getSeasonStatus`.
> - Tests for season-not-found and message-based detection.
> - **UI**:
> - `MultichainBridgeQuoteCard`: pass `useAlternativeIconColor` to
`RewardsBadge` when estimated points is 0.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
7915f79. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent d788715 commit d54ea81
File tree
7 files changed
+653
-143
lines changed- app/scripts/controllers/rewards
- ui
- hooks/bridge
- pages/bridge/quotes
7 files changed
+653
-143
lines changedLines changed: 163 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| 56 | + | |
56 | 57 | | |
57 | 58 | | |
58 | 59 | | |
| |||
2154 | 2155 | | |
2155 | 2156 | | |
2156 | 2157 | | |
| 2158 | + | |
| 2159 | + | |
| 2160 | + | |
2157 | 2161 | | |
2158 | 2162 | | |
2159 | 2163 | | |
| |||
2170 | 2174 | | |
2171 | 2175 | | |
2172 | 2176 | | |
| 2177 | + | |
| 2178 | + | |
| 2179 | + | |
| 2180 | + | |
| 2181 | + | |
| 2182 | + | |
| 2183 | + | |
| 2184 | + | |
| 2185 | + | |
| 2186 | + | |
| 2187 | + | |
| 2188 | + | |
| 2189 | + | |
| 2190 | + | |
| 2191 | + | |
| 2192 | + | |
| 2193 | + | |
| 2194 | + | |
| 2195 | + | |
| 2196 | + | |
| 2197 | + | |
| 2198 | + | |
| 2199 | + | |
| 2200 | + | |
| 2201 | + | |
| 2202 | + | |
| 2203 | + | |
| 2204 | + | |
| 2205 | + | |
| 2206 | + | |
| 2207 | + | |
| 2208 | + | |
| 2209 | + | |
| 2210 | + | |
| 2211 | + | |
| 2212 | + | |
| 2213 | + | |
| 2214 | + | |
| 2215 | + | |
| 2216 | + | |
| 2217 | + | |
| 2218 | + | |
| 2219 | + | |
| 2220 | + | |
| 2221 | + | |
| 2222 | + | |
| 2223 | + | |
| 2224 | + | |
| 2225 | + | |
| 2226 | + | |
| 2227 | + | |
2173 | 2228 | | |
2174 | 2229 | | |
2175 | 2230 | | |
| |||
2405 | 2460 | | |
2406 | 2461 | | |
2407 | 2462 | | |
| 2463 | + | |
| 2464 | + | |
| 2465 | + | |
| 2466 | + | |
| 2467 | + | |
| 2468 | + | |
| 2469 | + | |
| 2470 | + | |
| 2471 | + | |
| 2472 | + | |
| 2473 | + | |
| 2474 | + | |
| 2475 | + | |
| 2476 | + | |
| 2477 | + | |
| 2478 | + | |
| 2479 | + | |
| 2480 | + | |
| 2481 | + | |
| 2482 | + | |
| 2483 | + | |
| 2484 | + | |
| 2485 | + | |
| 2486 | + | |
| 2487 | + | |
| 2488 | + | |
| 2489 | + | |
| 2490 | + | |
| 2491 | + | |
| 2492 | + | |
| 2493 | + | |
| 2494 | + | |
| 2495 | + | |
| 2496 | + | |
| 2497 | + | |
| 2498 | + | |
| 2499 | + | |
| 2500 | + | |
| 2501 | + | |
| 2502 | + | |
| 2503 | + | |
| 2504 | + | |
| 2505 | + | |
| 2506 | + | |
| 2507 | + | |
| 2508 | + | |
| 2509 | + | |
| 2510 | + | |
| 2511 | + | |
| 2512 | + | |
| 2513 | + | |
| 2514 | + | |
| 2515 | + | |
| 2516 | + | |
| 2517 | + | |
| 2518 | + | |
| 2519 | + | |
| 2520 | + | |
| 2521 | + | |
| 2522 | + | |
| 2523 | + | |
| 2524 | + | |
| 2525 | + | |
| 2526 | + | |
| 2527 | + | |
| 2528 | + | |
| 2529 | + | |
| 2530 | + | |
| 2531 | + | |
| 2532 | + | |
| 2533 | + | |
| 2534 | + | |
| 2535 | + | |
| 2536 | + | |
| 2537 | + | |
| 2538 | + | |
| 2539 | + | |
| 2540 | + | |
| 2541 | + | |
| 2542 | + | |
| 2543 | + | |
| 2544 | + | |
| 2545 | + | |
| 2546 | + | |
| 2547 | + | |
| 2548 | + | |
| 2549 | + | |
| 2550 | + | |
| 2551 | + | |
| 2552 | + | |
| 2553 | + | |
| 2554 | + | |
| 2555 | + | |
| 2556 | + | |
| 2557 | + | |
| 2558 | + | |
| 2559 | + | |
| 2560 | + | |
2408 | 2561 | | |
2409 | 2562 | | |
2410 | 2563 | | |
| |||
2955 | 3108 | | |
2956 | 3109 | | |
2957 | 3110 | | |
2958 | | - | |
2959 | | - | |
| 3111 | + | |
| 3112 | + | |
2960 | 3113 | | |
2961 | 3114 | | |
2962 | 3115 | | |
| |||
2976 | 3129 | | |
2977 | 3130 | | |
2978 | 3131 | | |
| 3132 | + | |
| 3133 | + | |
| 3134 | + | |
| 3135 | + | |
| 3136 | + | |
| 3137 | + | |
2979 | 3138 | | |
2980 | 3139 | | |
2981 | 3140 | | |
| |||
2984 | 3143 | | |
2985 | 3144 | | |
2986 | 3145 | | |
2987 | | - | |
2988 | | - | |
| 3146 | + | |
| 3147 | + | |
2989 | 3148 | | |
2990 | 3149 | | |
2991 | 3150 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
| |||
545 | 546 | | |
546 | 547 | | |
547 | 548 | | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
548 | 558 | | |
549 | 559 | | |
550 | 560 | | |
| |||
609 | 619 | | |
610 | 620 | | |
611 | 621 | | |
612 | | - | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
613 | 628 | | |
614 | 629 | | |
615 | 630 | | |
| |||
1319 | 1334 | | |
1320 | 1335 | | |
1321 | 1336 | | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
1322 | 1342 | | |
1323 | 1343 | | |
1324 | 1344 | | |
| |||
Lines changed: 41 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
861 | 862 | | |
862 | 863 | | |
863 | 864 | | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
864 | 905 | | |
865 | 906 | | |
866 | 907 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
49 | 59 | | |
50 | 60 | | |
51 | 61 | | |
| |||
397 | 407 | | |
398 | 408 | | |
399 | 409 | | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
400 | 416 | | |
401 | 417 | | |
402 | 418 | | |
| |||
0 commit comments