Commit 9b8734a
authored
fix: getcandidatesubscriptionid silent auth if no subscription in state (#22124)
## **Description**
Very soon there will be multiple places to opt into rewards, which
requires a small change in the `getCandidateSubscriptionId` controller
function. In that function, we detect a subscription id in via `/ois`
and we don't have a subscription object in our store state, we should do
a silent auth for the account tied to the subscription. This will
(re)populate the store state appropriately.
## **Changelog**
CHANGELOG entry: null
## **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.
## **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]
> Perform silent auth during candidate subscription discovery when state
lacks the subscription, try all accounts and set a sensible
activeAccount fallback, reduce opt‑in cache staleness to 1h, and make
invalidation async with token reset; update tests accordingly.
>
> - **RewardsController**:
> - **Candidate Subscription**: `getCandidateSubscriptionId` now returns
`sids[i]` only if a valid token exists AND the subscription is in state;
otherwise performs `performSilentAuth` for that account.
> - **Auth Flow**: `handleAuthenticationTrigger` iterates all accounts,
captures the first success, and sets `activeAccount` to the first
success or the first account; calls `performSilentAuth(account, false,
true)`.
> - **Cache/Thresholds**: Shorten not‑opted‑in opt‑in status stale
threshold to 1 hour (`NOT_OPTED_IN_OIS_STALE_CACHE_THRESHOLD_MS`).
> - **Invalidation**: `invalidateAccountsAndSubscriptions` is now
`async`, also clears `lastFreshOptInStatusCheck`, and awaits
`resetAllSubscriptionTokens`; consumers updated to `await` it (e.g., 403
path in `getSeasonStatus`).
> - **Safety/Refactors**: Null-safety tweaks (e.g., `ois?.[0]`) and
clearer CAIP coercion logic in perps discount; small readability fixes.
> - **Tests**:
> - Add/expand coverage for multi-account silent auth behavior, active
account fallback, 1h threshold logic, async invalidation with token
reset, and new `getCandidateSubscriptionId` behavior (silent auth when
`sids` not in state).
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
45a6464. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent a1730dc commit 9b8734a
File tree
3 files changed
+290
-68
lines changed- app
- components/UI/Rewards/components/Tabs/LevelsTab
- core/Engine/controllers/rewards-controller
3 files changed
+290
-68
lines changedLines changed: 0 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | 37 | | |
42 | 38 | | |
43 | 39 | | |
| |||
110 | 106 | | |
111 | 107 | | |
112 | 108 | | |
113 | | - | |
114 | | - | |
115 | 109 | | |
116 | 110 | | |
117 | 111 | | |
| |||
129 | 123 | | |
130 | 124 | | |
131 | 125 | | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | 126 | | |
137 | 127 | | |
138 | 128 | | |
| |||
242 | 232 | | |
243 | 233 | | |
244 | 234 | | |
245 | | - | |
246 | 235 | | |
247 | 236 | | |
248 | 237 | | |
249 | 238 | | |
250 | 239 | | |
251 | 240 | | |
252 | 241 | | |
253 | | - | |
254 | 242 | | |
255 | 243 | | |
256 | 244 | | |
| |||
0 commit comments