Commit 0f3d948
authored
fix: handle polling subscriptions after subscription with card cp-13.13.0 (#38610)
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->
## **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?
-->
Previously after subscription with card we navigate to shield settings
screen with wait for active subscriptions params but in background we
only fetch subscription once so if stripe event handle in backend is
slower than client fetch, it would timeout in shield settings screen.
This PR add subscriptions polling after subscription with card stripe
checkout succeeded to ensure we fetch for latest subscription created.
[](https://codespaces.new/MetaMask/metamask-extension/pull/38610?quickstart=1)
## **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: fix shield subscription subscribe with card race
condition
## **Related issues**
Fixes: #38615
## **Manual testing steps**
1. Go to shield plan
2. Subscribe with card
3. After succeed should navigate to shield settings screen and wait for
subscription creation
## **Screenshots/Recordings**
<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->
### **Before**
<!-- [screenshots/recordings] -->
### **After**
<!-- [screenshots/recordings] -->
## **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]
> Adds polling after card checkout to wait for active/paused Shield
subscription with configurable interval/timeout, and centralizes Shield
error constants; updates tests and UI usage.
>
> - **Subscription Service**
(`app/scripts/services/subscription/subscription-service.ts`):
> - Add polling (`#pollForSubscription`) using
`getIsShieldSubscriptionActive/Paused`, with defaults
`SUBSCRIPTION_POLL_INTERVAL` and `SUBSCRIPTION_POLL_TIMEOUT`; throws
`SHIELD_ERROR.subscriptionPollingTimedOut`.
> - `startSubscriptionWithCard` now polls until subscription exists;
accepts optional `subscriptionPollInterval`/`subscriptionPollTimeout`;
on "already exists" error, refreshes `getSubscriptions`.
> - Use `SHIELD_ERROR.tabActionFailed` when checkout tab closes without
success; open settings with `waitForSubscriptionCreation=true`.
> - Minor: import time constants (`SECOND`) and Shield helpers.
> - **Shared** (`shared/modules/shield/constants.ts`):
> - Introduce `SHIELD_ERROR` with `tabActionFailed` and
`subscriptionPollingTimedOut`.
> - **UI Hook** (`ui/hooks/subscription/useSubscription.ts`):
> - Switch to `SHIELD_ERROR.tabActionFailed` for non-API tab failure
handling.
> - **Tests**
(`app/scripts/services/subscription/subscription-service.test.ts`):
> - Add mocks and cases for polling behavior (paused, multi-attempts,
timeout) and environment setup; assert results/errors accordingly.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
3dfb3b6. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 0680b94 commit 0f3d948
File tree
4 files changed
+144
-9
lines changed- app/scripts/services/subscription
- ui/hooks/subscription
4 files changed
+144
-9
lines changedLines changed: 84 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
12 | 15 | | |
13 | 16 | | |
14 | 17 | | |
| |||
17 | 20 | | |
18 | 21 | | |
19 | 22 | | |
| 23 | + | |
| 24 | + | |
20 | 25 | | |
21 | 26 | | |
22 | 27 | | |
| |||
50 | 55 | | |
51 | 56 | | |
52 | 57 | | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
53 | 76 | | |
54 | 77 | | |
55 | 78 | | |
| |||
194 | 217 | | |
195 | 218 | | |
196 | 219 | | |
| 220 | + | |
197 | 221 | | |
198 | 222 | | |
199 | 223 | | |
200 | 224 | | |
201 | 225 | | |
| 226 | + | |
| 227 | + | |
202 | 228 | | |
203 | 229 | | |
204 | 230 | | |
| |||
345 | 371 | | |
346 | 372 | | |
347 | 373 | | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
348 | 432 | | |
349 | 433 | | |
350 | 434 | | |
| |||
Lines changed: 54 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
39 | 46 | | |
40 | 47 | | |
41 | 48 | | |
| |||
44 | 51 | | |
45 | 52 | | |
46 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
47 | 57 | | |
48 | 58 | | |
49 | 59 | | |
| |||
137 | 147 | | |
138 | 148 | | |
139 | 149 | | |
| 150 | + | |
| 151 | + | |
140 | 152 | | |
141 | 153 | | |
142 | 154 | | |
| |||
169 | 181 | | |
170 | 182 | | |
171 | 183 | | |
172 | | - | |
173 | | - | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
174 | 188 | | |
175 | 189 | | |
176 | 190 | | |
| |||
187 | 201 | | |
188 | 202 | | |
189 | 203 | | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
190 | 209 | | |
191 | 210 | | |
192 | 211 | | |
| |||
365 | 384 | | |
366 | 385 | | |
367 | 386 | | |
368 | | - | |
| 387 | + | |
369 | 388 | | |
370 | 389 | | |
371 | 390 | | |
372 | 391 | | |
373 | 392 | | |
374 | 393 | | |
375 | 394 | | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
376 | 427 | | |
377 | 428 | | |
378 | 429 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
| 69 | + | |
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| |||
596 | 596 | | |
597 | 597 | | |
598 | 598 | | |
599 | | - | |
600 | | - | |
601 | | - | |
| 599 | + | |
602 | 600 | | |
603 | 601 | | |
604 | 602 | | |
| |||
0 commit comments