Skip to content

Commit 0c25595

Browse files
authored
feat: user customer id and trialed product state (#6628)
## Explanation <!-- Thanks for your contribution! Take a moment to answer these questions so that reviewers have the information they need to properly understand your changes: * What is the current state of things and why does it need to change? * What is the solution your changes offer and how does it work? * Are there any changes whose purpose might not obvious to those unfamiliar with the domain? * If your primary goal was to update one package but you found you had to update another one along the way, why did you do so? * If you had to upgrade a dependency, why did you do so? --> Add user customer id and trialed product in subscription controller state ## References <!-- Are there any issues that this pull request is tied to? Are there other links that reviewers should consult to understand these changes better? Are there client or consumer pull requests to adopt any breaking changes? For example: * Fixes #12345 * Related to #67890 --> ## Checklist - [x] I've updated the test suite for new or updated code as appropriate - [x] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [x] I've communicated my changes to consumers by [updating changelogs for packages I've changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs), highlighting breaking changes as necessary - [x] I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes
1 parent 8042cdd commit 0c25595

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

packages/subscription-controller/src/SubscriptionController.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,11 @@ describe('SubscriptionController', () => {
950950
controller.metadata,
951951
'anonymous',
952952
),
953-
).toMatchInlineSnapshot(`Object {}`);
953+
).toMatchInlineSnapshot(`
954+
Object {
955+
"trialedProducts": Array [],
956+
}
957+
`);
954958
});
955959
});
956960

@@ -965,6 +969,7 @@ describe('SubscriptionController', () => {
965969
).toMatchInlineSnapshot(`
966970
Object {
967971
"subscriptions": Array [],
972+
"trialedProducts": Array [],
968973
}
969974
`);
970975
});
@@ -981,6 +986,7 @@ describe('SubscriptionController', () => {
981986
).toMatchInlineSnapshot(`
982987
Object {
983988
"subscriptions": Array [],
989+
"trialedProducts": Array [],
984990
}
985991
`);
986992
});
@@ -997,6 +1003,7 @@ describe('SubscriptionController', () => {
9971003
).toMatchInlineSnapshot(`
9981004
Object {
9991005
"subscriptions": Array [],
1006+
"trialedProducts": Array [],
10001007
}
10011008
`);
10021009
});

packages/subscription-controller/src/SubscriptionController.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import {
3030
} from './types';
3131

3232
export type SubscriptionControllerState = {
33+
customerId?: string;
34+
trialedProducts: ProductType[];
3335
subscriptions: Subscription[];
3436
pricing?: PricingResponse;
3537
};
@@ -127,6 +129,7 @@ export type SubscriptionControllerOptions = {
127129
export function getDefaultSubscriptionControllerState(): SubscriptionControllerState {
128130
return {
129131
subscriptions: [],
132+
trialedProducts: [],
130133
};
131134
}
132135

@@ -145,6 +148,18 @@ const subscriptionControllerMetadata: StateMetadata<SubscriptionControllerState>
145148
anonymous: false,
146149
usedInUi: true,
147150
},
151+
customerId: {
152+
includeInStateLogs: true,
153+
persist: true,
154+
anonymous: false,
155+
usedInUi: true,
156+
},
157+
trialedProducts: {
158+
includeInStateLogs: true,
159+
persist: true,
160+
anonymous: true,
161+
usedInUi: true,
162+
},
148163
pricing: {
149164
includeInStateLogs: true,
150165
persist: true,
@@ -242,11 +257,13 @@ export class SubscriptionController extends BaseController<
242257
}
243258

244259
async getSubscriptions() {
245-
const { subscriptions } =
260+
const { subscriptions, customerId, trialedProducts } =
246261
await this.#subscriptionService.getSubscriptions();
247262

248263
this.update((state) => {
249264
state.subscriptions = subscriptions;
265+
state.customerId = customerId;
266+
state.trialedProducts = trialedProducts;
250267
});
251268

252269
return subscriptions;

0 commit comments

Comments
 (0)