Skip to content

Commit 7f0226e

Browse files
chore: use sids from ois endpoint (#20628)
## **Description** Use new sids prop from ois reward data service call. This allows us to enrich the reward controller cache more efficiently and avoid things like: - Out of sync cache with reality, having to do an explicit performauth to get the subscription id. ## **Changelog** CHANGELOG entry: null <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Leverages `sids` from `getOptInStatus` to cache per-account subscription IDs and use them for candidate selection, updating DTOs, controller logic, and tests. > > - **RewardsController**: > - Add `sids` support to `OptInStatusDto`; when feature disabled, return `{ ois: [false], sids: [null] }`-shaped responses. > - Enhance `getOptInStatus` to merge cached/fresh results, cache `hasOptedIn` and `subscriptionId` from `sids`, and return `{ ois, sids }`. > - Update `getCandidateSubscriptionId` to return the first available subscription from `sids` before attempting silent auth. > - Persist cached subscription IDs in account state; use cached values when present. > - **Types**: > - Extend `OptInStatusDto` with `sids: (string | null)[]`. > - **Tests**: > - Update controller, data-service, and hook tests to include/validate `sids` handling. > - Add cases for caching behavior, mixed cached/fresh results, and using `sids` for candidate subscription resolution. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 63a891c. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Alexandre Chappaz <[email protected]>
1 parent 563c13b commit 7f0226e

File tree

5 files changed

+497
-35
lines changed

5 files changed

+497
-35
lines changed

app/components/UI/Rewards/hooks/useRewardOptinSummary.test.ts

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ describe('useRewardOptinSummary', () => {
207207
// Arrange - Account1 and Account3 opted in, Account2 not opted in
208208
const mockResponse: OptInStatusDto = {
209209
ois: [true, false, true], // Account1: true, Account2: false, Account3: true
210+
sids: ['sub_123', null, 'sub_456'], // Account1: sub_123, Account2: null, Account3: sub_456
210211
};
211212

212213
mockEngineCall.mockImplementation((method: string, ..._args) => {
@@ -287,6 +288,7 @@ describe('useRewardOptinSummary', () => {
287288
// Arrange
288289
const mockResponse: OptInStatusDto = {
289290
ois: [false, false, false],
291+
sids: [null, null, null],
290292
};
291293

292294
mockEngineCall.mockImplementation((method: string, ..._args) => {
@@ -323,6 +325,7 @@ describe('useRewardOptinSummary', () => {
323325
// Arrange
324326
const mockResponse: OptInStatusDto = {
325327
ois: [true, true, true],
328+
sids: ['sub_123', 'sub_456', 'sub_789'],
326329
};
327330

328331
mockEngineCall.mockImplementation((method: string, ..._args) => {
@@ -370,6 +373,7 @@ describe('useRewardOptinSummary', () => {
370373

371374
const mockResponse: OptInStatusDto = {
372375
ois: [true, false, true],
376+
sids: ['sub_123', null, 'sub_456'],
373377
};
374378

375379
mockEngineCall.mockImplementation((method: string, ..._args) => {
@@ -504,6 +508,7 @@ describe('useRewardOptinSummary', () => {
504508
// Arrange
505509
const mockResponse: OptInStatusDto = {
506510
ois: [true, false, true],
511+
sids: ['sub_123', null, 'sub_456'],
507512
};
508513
mockEngineCall.mockResolvedValueOnce(mockResponse);
509514

@@ -542,6 +547,7 @@ describe('useRewardOptinSummary', () => {
542547

543548
const mockResponse: OptInStatusDto = {
544549
ois: [true, false, true],
550+
sids: ['sub_123', null, 'sub_456'],
545551
};
546552

547553
mockEngineCall.mockImplementation((method: string, ..._args) => {
@@ -577,7 +583,8 @@ describe('useRewardOptinSummary', () => {
577583
it('should only fetch opt-in status for supported accounts', async () => {
578584
// Arrange - Only account1 and account3 are supported
579585
const mockResponse: OptInStatusDto = {
580-
ois: [true, false], // Only 2 accounts supported: account1 (true), account3 (false)
586+
ois: [true, false],
587+
sids: ['sub_123', null], // Only 2 accounts supported: account1 (true), account3 (false)
581588
};
582589

583590
mockEngineCall.mockImplementation((method: string, ...args) => {
@@ -636,7 +643,8 @@ describe('useRewardOptinSummary', () => {
636643
it('should handle when selected account is unsupported but others are supported', async () => {
637644
// Arrange - Account1 (selected) is unsupported, but account2 and account3 are supported
638645
const mockResponse: OptInStatusDto = {
639-
ois: [true, false], // account2 (true), account3 (false)
646+
ois: [true, false],
647+
sids: ['sub_123', null], // account2 (true), account3 (false)
640648
};
641649

642650
mockEngineCall.mockImplementation((method: string, ...args) => {
@@ -735,6 +743,7 @@ describe('useRewardOptinSummary', () => {
735743

736744
const mockResponse: OptInStatusDto = {
737745
ois: [true],
746+
sids: ['sub_123'],
738747
};
739748
mockEngineCall
740749
.mockResolvedValueOnce(mockResponse)
@@ -792,6 +801,7 @@ describe('useRewardOptinSummary', () => {
792801
// Arrange - accounts already exist
793802
const mockResponse: OptInStatusDto = {
794803
ois: [true, false, true],
804+
sids: ['sub_123', null, 'sub_456'],
795805
};
796806
mockEngineCall.mockResolvedValueOnce(mockResponse);
797807

@@ -833,6 +843,7 @@ describe('useRewardOptinSummary', () => {
833843
// Arrange
834844
const mockResponse: OptInStatusDto = {
835845
ois: [true, false, true],
846+
sids: ['sub_123', null, 'sub_456'],
836847
};
837848
mockEngineCall.mockResolvedValueOnce(mockResponse);
838849

@@ -865,7 +876,8 @@ describe('useRewardOptinSummary', () => {
865876
.mockReturnValueOnce(null); // selectRewardsActiveAccountSubscriptionId (null)
866877

867878
const mockResponse: OptInStatusDto = {
868-
ois: [true, false, true], // Account1 and Account3 opted in
879+
ois: [true, false, true],
880+
sids: ['sub_123', null, 'sub_456'], // Account1 and Account3 opted in
869881
};
870882

871883
mockEngineCall.mockImplementation((method: string, ..._args) => {
@@ -917,7 +929,8 @@ describe('useRewardOptinSummary', () => {
917929
.mockReturnValueOnce('active-subscription-id'); // selectRewardsActiveAccountSubscriptionId
918930

919931
const mockResponse: OptInStatusDto = {
920-
ois: [true, false, true], // Account1 and Account3 opted in
932+
ois: [true, false, true],
933+
sids: ['sub_123', null, 'sub_456'], // Account1 and Account3 opted in
921934
};
922935

923936
mockEngineCall.mockImplementation((method: string, ..._args) => {
@@ -970,7 +983,8 @@ describe('useRewardOptinSummary', () => {
970983
.mockReturnValueOnce(subscriptionId); // selectRewardsActiveAccountSubscriptionId
971984

972985
const mockResponse: OptInStatusDto = {
973-
ois: [true, false, true], // Account1 and Account3 opted in
986+
ois: [true, false, true],
987+
sids: ['sub_123', null, 'sub_456'], // Account1 and Account3 opted in
974988
};
975989

976990
mockEngineCall.mockImplementation((method: string, ..._args) => {
@@ -1028,7 +1042,8 @@ describe('useRewardOptinSummary', () => {
10281042
});
10291043

10301044
const mockResponse: OptInStatusDto = {
1031-
ois: [true, false, true], // Account1 and Account3 opted in
1045+
ois: [true, false, true],
1046+
sids: ['sub_123', null, 'sub_456'], // Account1 and Account3 opted in
10321047
};
10331048

10341049
mockEngineCall.mockImplementation((method: string, ...args) => {
@@ -1097,7 +1112,8 @@ describe('useRewardOptinSummary', () => {
10971112
});
10981113

10991114
const mockResponse: OptInStatusDto = {
1100-
ois: [true, false, true], // Account1 and Account3 opted in
1115+
ois: [true, false, true],
1116+
sids: ['sub_123', null, 'sub_456'], // Account1 and Account3 opted in
11011117
};
11021118

11031119
mockEngineCall.mockImplementation((method: string, ..._args) => {
@@ -1146,7 +1162,8 @@ describe('useRewardOptinSummary', () => {
11461162
});
11471163

11481164
const mockResponse: OptInStatusDto = {
1149-
ois: [true, false, true], // Account1 and Account3 opted in
1165+
ois: [true, false, true],
1166+
sids: ['sub_123', null, 'sub_456'], // Account1 and Account3 opted in
11501167
};
11511168

11521169
// Mock convertInternalAccountToCaipAccountId to return null for Account3
@@ -1221,7 +1238,8 @@ describe('useRewardOptinSummary', () => {
12211238
});
12221239

12231240
const mockResponse: OptInStatusDto = {
1224-
ois: [true, false, true], // Account1 and Account3 opted in
1241+
ois: [true, false, true],
1242+
sids: ['sub_123', null, 'sub_456'], // Account1 and Account3 opted in
12251243
};
12261244

12271245
mockEngineCall.mockImplementation((method: string, ...args) => {

0 commit comments

Comments
 (0)