@metamask-previews/subscription-controller 7.0.0-preview-c2ef75d18 → 7.0.0-preview-6b4bcdab3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/CHANGELOG.md +1 -33
  2. package/dist/SubscriptionController-method-action-types.cjs.map +1 -1
  3. package/dist/SubscriptionController-method-action-types.d.cts +18 -55
  4. package/dist/SubscriptionController-method-action-types.d.cts.map +1 -1
  5. package/dist/SubscriptionController-method-action-types.d.mts +18 -55
  6. package/dist/SubscriptionController-method-action-types.d.mts.map +1 -1
  7. package/dist/SubscriptionController-method-action-types.mjs.map +1 -1
  8. package/dist/SubscriptionController.cjs +45 -165
  9. package/dist/SubscriptionController.cjs.map +1 -1
  10. package/dist/SubscriptionController.d.cts +17 -53
  11. package/dist/SubscriptionController.d.cts.map +1 -1
  12. package/dist/SubscriptionController.d.mts +17 -53
  13. package/dist/SubscriptionController.d.mts.map +1 -1
  14. package/dist/SubscriptionController.mjs +46 -166
  15. package/dist/SubscriptionController.mjs.map +1 -1
  16. package/dist/SubscriptionService-method-action-types.cjs.map +1 -1
  17. package/dist/SubscriptionService-method-action-types.d.cts +1 -5
  18. package/dist/SubscriptionService-method-action-types.d.cts.map +1 -1
  19. package/dist/SubscriptionService-method-action-types.d.mts +1 -5
  20. package/dist/SubscriptionService-method-action-types.d.mts.map +1 -1
  21. package/dist/SubscriptionService-method-action-types.mjs.map +1 -1
  22. package/dist/SubscriptionService-structs.cjs +12 -35
  23. package/dist/SubscriptionService-structs.cjs.map +1 -1
  24. package/dist/SubscriptionService-structs.d.cts +237 -185
  25. package/dist/SubscriptionService-structs.d.cts.map +1 -1
  26. package/dist/SubscriptionService-structs.d.mts +237 -185
  27. package/dist/SubscriptionService-structs.d.mts.map +1 -1
  28. package/dist/SubscriptionService-structs.mjs +14 -37
  29. package/dist/SubscriptionService-structs.mjs.map +1 -1
  30. package/dist/SubscriptionService.cjs +2 -24
  31. package/dist/SubscriptionService.cjs.map +1 -1
  32. package/dist/SubscriptionService.d.cts +1 -5
  33. package/dist/SubscriptionService.d.cts.map +1 -1
  34. package/dist/SubscriptionService.d.mts +1 -5
  35. package/dist/SubscriptionService.d.mts.map +1 -1
  36. package/dist/SubscriptionService.mjs +2 -24
  37. package/dist/SubscriptionService.mjs.map +1 -1
  38. package/dist/constants.cjs +0 -2
  39. package/dist/constants.cjs.map +1 -1
  40. package/dist/constants.d.cts +0 -2
  41. package/dist/constants.d.cts.map +1 -1
  42. package/dist/constants.d.mts +0 -2
  43. package/dist/constants.d.mts.map +1 -1
  44. package/dist/constants.mjs +0 -2
  45. package/dist/constants.mjs.map +1 -1
  46. package/dist/index.cjs +1 -2
  47. package/dist/index.cjs.map +1 -1
  48. package/dist/index.d.cts +3 -3
  49. package/dist/index.d.cts.map +1 -1
  50. package/dist/index.d.mts +3 -3
  51. package/dist/index.d.mts.map +1 -1
  52. package/dist/index.mjs +1 -1
  53. package/dist/index.mjs.map +1 -1
  54. package/dist/types.cjs +1 -27
  55. package/dist/types.cjs.map +1 -1
  56. package/dist/types.d.cts +10 -171
  57. package/dist/types.d.cts.map +1 -1
  58. package/dist/types.d.mts +10 -171
  59. package/dist/types.d.mts.map +1 -1
  60. package/dist/types.mjs +0 -26
  61. package/dist/types.mjs.map +1 -1
  62. package/package.json +1 -1
@@ -1,11 +1,12 @@
1
1
  import type { ControllerStateChangeEvent, ControllerGetStateAction } from "@metamask/base-controller";
2
2
  import type { Messenger } from "@metamask/messenger";
3
3
  import type { AuthenticationController } from "@metamask/profile-sync-controller";
4
+ import type { TransactionMeta } from "@metamask/transaction-controller";
4
5
  import type { CaipAccountId } from "@metamask/utils";
5
6
  import { controllerName } from "./constants.cjs";
6
7
  import type { SubscriptionControllerMethodActions } from "./SubscriptionController-method-action-types.cjs";
7
8
  import type { SubscriptionServiceAssignUserToCohortAction, SubscriptionServiceCancelSubscriptionAction, SubscriptionServiceGetBillingPortalUrlAction, SubscriptionServiceGetPricingAction, SubscriptionServiceGetSubscriptionsAction, SubscriptionServiceGetSubscriptionsEligibilitiesAction, SubscriptionServiceLinkRewardsAction, SubscriptionServiceStartSubscriptionWithCardAction, SubscriptionServiceStartSubscriptionWithCryptoAction, SubscriptionServiceSubmitSponsorshipIntentsAction, SubscriptionServiceSubmitUserEventAction, SubscriptionServiceUnCancelSubscriptionAction, SubscriptionServiceUpdatePaymentMethodCardAction, SubscriptionServiceUpdatePaymentMethodCryptoAction } from "./SubscriptionService-method-action-types.cjs";
8
- import type { AssignCohortRequest, BillingPortalResponse, GetCryptoApproveTransactionRequest, GetCryptoApproveTransactionResponse, GetSubscriptionsEligibilitiesRequest, ProductPrice, SubscriptionEligibility, StartCryptoSubscriptionRequest, SubmitSubscriptionCryptoApprovalRequest, SubmitUserEventRequest, TokenPaymentInfo, UpdatePaymentMethodCardResponse, UpdatePaymentMethodOpts, CachedLastSelectedPaymentMethod, CacheLastSelectedPaymentMethodRequest, SubmitSponsorshipIntentsMethodParams, LinkRewardsRequest, StartCryptoSubscriptionResponse, StartSubscriptionResponse, CancelSubscriptionRequest } from "./types.cjs";
9
+ import type { AssignCohortRequest, BillingPortalResponse, GetCryptoApproveTransactionRequest, GetCryptoApproveTransactionResponse, GetSubscriptionsEligibilitiesRequest, ProductPrice, SubscriptionEligibility, StartCryptoSubscriptionRequest, SubmitUserEventRequest, TokenPaymentInfo, UpdatePaymentMethodCardResponse, UpdatePaymentMethodOpts, CachedLastSelectedPaymentMethod, SubmitSponsorshipIntentsMethodParams, LinkRewardsRequest, StartCryptoSubscriptionResponse, StartSubscriptionResponse, CancelSubscriptionRequest } from "./types.cjs";
9
10
  import type { PricingResponse, ProductType, StartSubscriptionRequest, Subscription } from "./types.cjs";
10
11
  export type SubscriptionControllerState = {
11
12
  customerId?: string;
@@ -21,7 +22,7 @@ export type SubscriptionControllerState = {
21
22
  * This is used to display the last selected payment method in the UI.
22
23
  * This state is also meant to be used internally to track the last selected payment method for the user. (e.g. for crypto subscriptions)
23
24
  */
24
- lastSelectedPaymentMethod?: Partial<Record<ProductType, CachedLastSelectedPaymentMethod>>;
25
+ lastSelectedPaymentMethod?: Record<ProductType, CachedLastSelectedPaymentMethod>;
25
26
  };
26
27
  export type SubscriptionControllerGetStateAction = ControllerGetStateAction<typeof controllerName, SubscriptionControllerState>;
27
28
  export type SubscriptionControllerActions = SubscriptionControllerGetStateAction | SubscriptionControllerMethodActions;
@@ -103,53 +104,17 @@ export declare class SubscriptionController extends SubscriptionController_base<
103
104
  unCancelSubscription(request: {
104
105
  subscriptionId: string;
105
106
  }): Promise<void>;
106
- /**
107
- * Starts a card-paid subscription checkout session for the requested products
108
- * (e.g. Shield or Money Account Plus).
109
- *
110
- * `isTrialRequested` on the request is ignored and overwritten from pricing
111
- * (`trialPeriodDays > 0`) and `trialedProducts`.
112
- *
113
- * @param request - The start subscription request.
114
- * @returns The checkout session response.
115
- */
116
- startSubscriptionWithCard(request: StartSubscriptionRequest): Promise<StartSubscriptionResponse>;
117
- /**
118
- * Starts a crypto-paid subscription for the requested products
119
- * (e.g. Shield or Money Account Plus). Unlike card checkout, this
120
- * creates the subscription immediately, so local state is refreshed
121
- * afterwards.
122
- *
123
- * `isTrialRequested` on the request is ignored and overwritten from pricing
124
- * (`trialPeriodDays > 0`) and `trialedProducts`.
125
- *
126
- * @param request - The start crypto subscription request.
127
- * @returns The start crypto subscription response.
128
- * @throws If `products` is empty.
129
- */
107
+ startShieldSubscriptionWithCard(request: StartSubscriptionRequest): Promise<StartSubscriptionResponse>;
130
108
  startSubscriptionWithCrypto(request: StartCryptoSubscriptionRequest): Promise<StartCryptoSubscriptionResponse>;
131
109
  /**
132
- * Submits a Shield ERC-20 crypto approval transaction to start or update a
133
- * crypto subscription.
134
- *
135
- * This handler is Shield / `TransactionType.shieldSubscriptionApprove` only.
136
- * Delegation-based products (e.g. Money Account) must call
137
- * `startSubscriptionWithCrypto` instead.
110
+ * Handles shield subscription crypto approval transactions.
138
111
  *
139
- * @param request - The crypto approval request.
140
- * @param request.productType - The subscription product. Typed as
141
- * `typeof PRODUCT_TYPES.SHIELD` only at the moment (future might support more
142
- * product).
143
- * @param request.txMeta - The transaction metadata. Must have type
144
- * `TransactionType.shieldSubscriptionApprove`.
145
- * @param request.isSponsored - Whether the transaction is sponsored.
146
- * @param request.rewardAccountId - The account ID of the reward subscription
147
- * to link.
148
- * @throws If `productType` is not Shield or `txMeta.type` is not
149
- * `shieldSubscriptionApprove`.
112
+ * @param txMeta - The transaction metadata.
113
+ * @param isSponsored - Whether the transaction is sponsored.
114
+ * @param rewardAccountId - The account ID of the reward subscription to link to the shield subscription.
150
115
  * @returns void
151
116
  */
152
- submitSubscriptionCryptoApproval(request: SubmitSubscriptionCryptoApprovalRequest): Promise<void>;
117
+ submitShieldSubscriptionCryptoApproval(txMeta: TransactionMeta, isSponsored?: boolean, rewardAccountId?: CaipAccountId): Promise<void>;
153
118
  /**
154
119
  * Get transaction params to create crypto approve transaction for subscription payment
155
120
  *
@@ -171,14 +136,14 @@ export declare class SubscriptionController extends SubscriptionController_base<
171
136
  /**
172
137
  * Cache the last selected payment method for a specific product.
173
138
  *
174
- * @param request - The request object.
175
- * @param request.product - The product to cache the payment method for.
176
- * @param request.paymentMethod - The payment method to cache.
177
- * @param request.paymentMethod.type - The type of the payment method.
178
- * @param request.paymentMethod.paymentTokenAddress - The payment token address.
179
- * @param request.paymentMethod.plan - The plan of the payment method.
139
+ * @param product - The product to cache the payment method for.
140
+ * @param paymentMethod - The payment method to cache.
141
+ * @param paymentMethod.type - The type of the payment method.
142
+ * @param paymentMethod.paymentTokenAddress - The payment token address.
143
+ * @param paymentMethod.plan - The plan of the payment method.
144
+ * @param paymentMethod.product - The product of the payment method.
180
145
  */
181
- cacheLastSelectedPaymentMethod(request: CacheLastSelectedPaymentMethodRequest): void;
146
+ cacheLastSelectedPaymentMethod(product: ProductType, paymentMethod: CachedLastSelectedPaymentMethod): void;
182
147
  /**
183
148
  * Clear the last selected payment method for a specific product.
184
149
  *
@@ -198,8 +163,7 @@ export declare class SubscriptionController extends SubscriptionController_base<
198
163
  * recurringInterval: RecurringInterval.Month,
199
164
  * billingCycles: 1,
200
165
  * }
201
- * @returns resolves to true if the sponsorship is supported and intents were submitted successfully, false if the chain does not support sponsorship or the user has already trialed
202
- * @throws If the crypto payment method or chain is missing from pricing
166
+ * @returns resolves to true if the sponsorship is supported and intents were submitted successfully, false otherwise
203
167
  */
204
168
  submitSponsorshipIntents(request: SubmitSponsorshipIntentsMethodParams): Promise<boolean>;
205
169
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"SubscriptionController.d.cts","sourceRoot":"","sources":["../src/SubscriptionController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,0BAA0B,EAC1B,wBAAwB,EACzB,kCAAkC;AACnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD,OAAO,KAAK,EAAE,wBAAwB,EAAE,0CAA0C;AAElF,OAAO,KAAK,EAAE,aAAa,EAAO,wBAAwB;AAG1D,OAAO,EAEL,cAAc,EAGf,wBAAuB;AACxB,OAAO,KAAK,EAAE,mCAAmC,EAAE,yDAAwD;AAC3G,OAAO,KAAK,EACV,2CAA2C,EAC3C,2CAA2C,EAC3C,4CAA4C,EAC5C,mCAAmC,EACnC,yCAAyC,EACzC,sDAAsD,EACtD,oCAAoC,EACpC,kDAAkD,EAClD,oDAAoD,EACpD,iDAAiD,EACjD,wCAAwC,EACxC,6CAA6C,EAC7C,gDAAgD,EAChD,kDAAkD,EACnD,sDAAqD;AAOtD,OAAO,KAAK,EACV,mBAAmB,EACnB,qBAAqB,EAErB,kCAAkC,EAClC,mCAAmC,EACnC,oCAAoC,EACpC,YAAY,EACZ,uBAAuB,EACvB,8BAA8B,EAC9B,uCAAuC,EACvC,sBAAsB,EACtB,gBAAgB,EAChB,+BAA+B,EAC/B,uBAAuB,EACvB,+BAA+B,EAC/B,qCAAqC,EACrC,oCAAoC,EAGpC,kBAAkB,EAClB,+BAA+B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,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAIrE;;;;;OAKG;IACG,kBAAkB,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAOrE;;;;;;;;OAQG;IACG,WAAW,CACf,OAAO,EAAE,kBAAkB,GAAG;QAAE,cAAc,EAAE,MAAM,CAAA;KAAE,GACvD,OAAO,CAAC,IAAI,CAAC;IAgBV,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAmCnC;;;;;;OAMG;IACH,qBAAqB,CACnB,KAAK,EAAE,YAAY,EACnB,gBAAgB,EAAE,gBAAgB,GACjC,MAAM;IAkBT;;;;;;OAMG;IACH,4BAA4B,CAC1B,KAAK,EAAE,YAAY,EACnB,gBAAgB,EAAE,gBAAgB,GACjC,MAAM;IAmBT;;OAEG;IACH,UAAU,IAAI,IAAI;IAOlB;;OAEG;IACH,yBAAyB,IAAI,IAAI;CAyMlC"}
@@ -1,11 +1,12 @@
1
1
  import type { ControllerStateChangeEvent, ControllerGetStateAction } from "@metamask/base-controller";
2
2
  import type { Messenger } from "@metamask/messenger";
3
3
  import type { AuthenticationController } from "@metamask/profile-sync-controller";
4
+ import type { TransactionMeta } from "@metamask/transaction-controller";
4
5
  import type { CaipAccountId } from "@metamask/utils";
5
6
  import { controllerName } from "./constants.mjs";
6
7
  import type { SubscriptionControllerMethodActions } from "./SubscriptionController-method-action-types.mjs";
7
8
  import type { SubscriptionServiceAssignUserToCohortAction, SubscriptionServiceCancelSubscriptionAction, SubscriptionServiceGetBillingPortalUrlAction, SubscriptionServiceGetPricingAction, SubscriptionServiceGetSubscriptionsAction, SubscriptionServiceGetSubscriptionsEligibilitiesAction, SubscriptionServiceLinkRewardsAction, SubscriptionServiceStartSubscriptionWithCardAction, SubscriptionServiceStartSubscriptionWithCryptoAction, SubscriptionServiceSubmitSponsorshipIntentsAction, SubscriptionServiceSubmitUserEventAction, SubscriptionServiceUnCancelSubscriptionAction, SubscriptionServiceUpdatePaymentMethodCardAction, SubscriptionServiceUpdatePaymentMethodCryptoAction } from "./SubscriptionService-method-action-types.mjs";
8
- import type { AssignCohortRequest, BillingPortalResponse, GetCryptoApproveTransactionRequest, GetCryptoApproveTransactionResponse, GetSubscriptionsEligibilitiesRequest, ProductPrice, SubscriptionEligibility, StartCryptoSubscriptionRequest, SubmitSubscriptionCryptoApprovalRequest, SubmitUserEventRequest, TokenPaymentInfo, UpdatePaymentMethodCardResponse, UpdatePaymentMethodOpts, CachedLastSelectedPaymentMethod, CacheLastSelectedPaymentMethodRequest, SubmitSponsorshipIntentsMethodParams, LinkRewardsRequest, StartCryptoSubscriptionResponse, StartSubscriptionResponse, CancelSubscriptionRequest } from "./types.mjs";
9
+ import type { AssignCohortRequest, BillingPortalResponse, GetCryptoApproveTransactionRequest, GetCryptoApproveTransactionResponse, GetSubscriptionsEligibilitiesRequest, ProductPrice, SubscriptionEligibility, StartCryptoSubscriptionRequest, SubmitUserEventRequest, TokenPaymentInfo, UpdatePaymentMethodCardResponse, UpdatePaymentMethodOpts, CachedLastSelectedPaymentMethod, SubmitSponsorshipIntentsMethodParams, LinkRewardsRequest, StartCryptoSubscriptionResponse, StartSubscriptionResponse, CancelSubscriptionRequest } from "./types.mjs";
9
10
  import type { PricingResponse, ProductType, StartSubscriptionRequest, Subscription } from "./types.mjs";
10
11
  export type SubscriptionControllerState = {
11
12
  customerId?: string;
@@ -21,7 +22,7 @@ export type SubscriptionControllerState = {
21
22
  * This is used to display the last selected payment method in the UI.
22
23
  * This state is also meant to be used internally to track the last selected payment method for the user. (e.g. for crypto subscriptions)
23
24
  */
24
- lastSelectedPaymentMethod?: Partial<Record<ProductType, CachedLastSelectedPaymentMethod>>;
25
+ lastSelectedPaymentMethod?: Record<ProductType, CachedLastSelectedPaymentMethod>;
25
26
  };
26
27
  export type SubscriptionControllerGetStateAction = ControllerGetStateAction<typeof controllerName, SubscriptionControllerState>;
27
28
  export type SubscriptionControllerActions = SubscriptionControllerGetStateAction | SubscriptionControllerMethodActions;
@@ -103,53 +104,17 @@ export declare class SubscriptionController extends SubscriptionController_base<
103
104
  unCancelSubscription(request: {
104
105
  subscriptionId: string;
105
106
  }): Promise<void>;
106
- /**
107
- * Starts a card-paid subscription checkout session for the requested products
108
- * (e.g. Shield or Money Account Plus).
109
- *
110
- * `isTrialRequested` on the request is ignored and overwritten from pricing
111
- * (`trialPeriodDays > 0`) and `trialedProducts`.
112
- *
113
- * @param request - The start subscription request.
114
- * @returns The checkout session response.
115
- */
116
- startSubscriptionWithCard(request: StartSubscriptionRequest): Promise<StartSubscriptionResponse>;
117
- /**
118
- * Starts a crypto-paid subscription for the requested products
119
- * (e.g. Shield or Money Account Plus). Unlike card checkout, this
120
- * creates the subscription immediately, so local state is refreshed
121
- * afterwards.
122
- *
123
- * `isTrialRequested` on the request is ignored and overwritten from pricing
124
- * (`trialPeriodDays > 0`) and `trialedProducts`.
125
- *
126
- * @param request - The start crypto subscription request.
127
- * @returns The start crypto subscription response.
128
- * @throws If `products` is empty.
129
- */
107
+ startShieldSubscriptionWithCard(request: StartSubscriptionRequest): Promise<StartSubscriptionResponse>;
130
108
  startSubscriptionWithCrypto(request: StartCryptoSubscriptionRequest): Promise<StartCryptoSubscriptionResponse>;
131
109
  /**
132
- * Submits a Shield ERC-20 crypto approval transaction to start or update a
133
- * crypto subscription.
134
- *
135
- * This handler is Shield / `TransactionType.shieldSubscriptionApprove` only.
136
- * Delegation-based products (e.g. Money Account) must call
137
- * `startSubscriptionWithCrypto` instead.
110
+ * Handles shield subscription crypto approval transactions.
138
111
  *
139
- * @param request - The crypto approval request.
140
- * @param request.productType - The subscription product. Typed as
141
- * `typeof PRODUCT_TYPES.SHIELD` only at the moment (future might support more
142
- * product).
143
- * @param request.txMeta - The transaction metadata. Must have type
144
- * `TransactionType.shieldSubscriptionApprove`.
145
- * @param request.isSponsored - Whether the transaction is sponsored.
146
- * @param request.rewardAccountId - The account ID of the reward subscription
147
- * to link.
148
- * @throws If `productType` is not Shield or `txMeta.type` is not
149
- * `shieldSubscriptionApprove`.
112
+ * @param txMeta - The transaction metadata.
113
+ * @param isSponsored - Whether the transaction is sponsored.
114
+ * @param rewardAccountId - The account ID of the reward subscription to link to the shield subscription.
150
115
  * @returns void
151
116
  */
152
- submitSubscriptionCryptoApproval(request: SubmitSubscriptionCryptoApprovalRequest): Promise<void>;
117
+ submitShieldSubscriptionCryptoApproval(txMeta: TransactionMeta, isSponsored?: boolean, rewardAccountId?: CaipAccountId): Promise<void>;
153
118
  /**
154
119
  * Get transaction params to create crypto approve transaction for subscription payment
155
120
  *
@@ -171,14 +136,14 @@ export declare class SubscriptionController extends SubscriptionController_base<
171
136
  /**
172
137
  * Cache the last selected payment method for a specific product.
173
138
  *
174
- * @param request - The request object.
175
- * @param request.product - The product to cache the payment method for.
176
- * @param request.paymentMethod - The payment method to cache.
177
- * @param request.paymentMethod.type - The type of the payment method.
178
- * @param request.paymentMethod.paymentTokenAddress - The payment token address.
179
- * @param request.paymentMethod.plan - The plan of the payment method.
139
+ * @param product - The product to cache the payment method for.
140
+ * @param paymentMethod - The payment method to cache.
141
+ * @param paymentMethod.type - The type of the payment method.
142
+ * @param paymentMethod.paymentTokenAddress - The payment token address.
143
+ * @param paymentMethod.plan - The plan of the payment method.
144
+ * @param paymentMethod.product - The product of the payment method.
180
145
  */
181
- cacheLastSelectedPaymentMethod(request: CacheLastSelectedPaymentMethodRequest): void;
146
+ cacheLastSelectedPaymentMethod(product: ProductType, paymentMethod: CachedLastSelectedPaymentMethod): void;
182
147
  /**
183
148
  * Clear the last selected payment method for a specific product.
184
149
  *
@@ -198,8 +163,7 @@ export declare class SubscriptionController extends SubscriptionController_base<
198
163
  * recurringInterval: RecurringInterval.Month,
199
164
  * billingCycles: 1,
200
165
  * }
201
- * @returns resolves to true if the sponsorship is supported and intents were submitted successfully, false if the chain does not support sponsorship or the user has already trialed
202
- * @throws If the crypto payment method or chain is missing from pricing
166
+ * @returns resolves to true if the sponsorship is supported and intents were submitted successfully, false otherwise
203
167
  */
204
168
  submitSponsorshipIntents(request: SubmitSponsorshipIntentsMethodParams): Promise<boolean>;
205
169
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"SubscriptionController.d.mts","sourceRoot":"","sources":["../src/SubscriptionController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,0BAA0B,EAC1B,wBAAwB,EACzB,kCAAkC;AACnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD,OAAO,KAAK,EAAE,wBAAwB,EAAE,0CAA0C;AAElF,OAAO,KAAK,EAAE,aAAa,EAAO,wBAAwB;AAG1D,OAAO,EAEL,cAAc,EAGf,wBAAuB;AACxB,OAAO,KAAK,EAAE,mCAAmC,EAAE,yDAAwD;AAC3G,OAAO,KAAK,EACV,2CAA2C,EAC3C,2CAA2C,EAC3C,4CAA4C,EAC5C,mCAAmC,EACnC,yCAAyC,EACzC,sDAAsD,EACtD,oCAAoC,EACpC,kDAAkD,EAClD,oDAAoD,EACpD,iDAAiD,EACjD,wCAAwC,EACxC,6CAA6C,EAC7C,gDAAgD,EAChD,kDAAkD,EACnD,sDAAqD;AAOtD,OAAO,KAAK,EACV,mBAAmB,EACnB,qBAAqB,EAErB,kCAAkC,EAClC,mCAAmC,EACnC,oCAAoC,EACpC,YAAY,EACZ,uBAAuB,EACvB,8BAA8B,EAC9B,uCAAuC,EACvC,sBAAsB,EACtB,gBAAgB,EAChB,+BAA+B,EAC/B,uBAAuB,EACvB,+BAA+B,EAC/B,qCAAqC,EACrC,oCAAoC,EAGpC,kBAAkB,EAClB,+BAA+B,EAC/B,yBAAyB,EACzB,yBAAyB,EAE1B,oBAAmB;AACpB,OAAO,KAAK,EACV,eAAe,EACf,WAAW,EACX,wBAAwB,EACxB,YAAY,EACb,oBAAmB;AAEpB,MAAM,MAAM,2BAA2B,GAAG;IACxC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,WAAW,EAAE,CAAC;IAC/B,aAAa,EAAE,YAA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AC;IAgBV,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAmCnC;;;;;;OAMG;IACH,qBAAqB,CACnB,KAAK,EAAE,YAAY,EACnB,gBAAgB,EAAE,gBAAgB,GACjC,MAAM;IAkBT;;;;;;OAMG;IACH,4BAA4B,CAC1B,KAAK,EAAE,YAAY,EACnB,gBAAgB,EAAE,gBAAgB,GACjC,MAAM;IAmBT;;OAEG;IACH,UAAU,IAAI,IAAI;IAOlB;;OAEG;IACH,yBAAyB,IAAI,IAAI;CAyMlC"}
@@ -3,12 +3,12 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
3
3
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
4
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
5
  };
6
- var _SubscriptionController_instances, _SubscriptionController_getSubscriptionPriceAmount, _SubscriptionController_getSubscriptionBalanceAmount, _SubscriptionController_getProductPriceByProductAndPlan, _SubscriptionController_assertValidSubscriptionStateForCryptoApproval, _SubscriptionController_assertIsUserNotSubscribed, _SubscriptionController_assertIsUserSubscribed, _SubscriptionController_assertIsPaymentMethodCrypto, _SubscriptionController_getIsEligibleForTrialedSponsorship, _SubscriptionController_getIsTrialRequested, _SubscriptionController_findCryptoPaymentMethod, _SubscriptionController_resolveCryptoPaymentMethodDefaults, _SubscriptionController_getChainSupportsSponsorship, _SubscriptionController_areTrialedProductsEqual, _SubscriptionController_areSubscriptionsEqual, _SubscriptionController_isSubscriptionEqual, _SubscriptionController_stringifySubscription;
6
+ var _SubscriptionController_instances, _SubscriptionController_getSubscriptionPriceAmount, _SubscriptionController_getSubscriptionBalanceAmount, _SubscriptionController_getProductPriceByProductAndPlan, _SubscriptionController_assertValidSubscriptionStateForCryptoApproval, _SubscriptionController_assertIsUserNotSubscribed, _SubscriptionController_assertIsUserSubscribed, _SubscriptionController_assertIsPaymentMethodCrypto, _SubscriptionController_getIsEligibleForTrialedSponsorship, _SubscriptionController_getChainSupportsSponsorship, _SubscriptionController_areTrialedProductsEqual, _SubscriptionController_areSubscriptionsEqual, _SubscriptionController_isSubscriptionEqual, _SubscriptionController_stringifySubscription;
7
7
  import { StaticIntervalPollingController } from "@metamask/polling-controller";
8
8
  import { TransactionType } from "@metamask/transaction-controller";
9
9
  import { BigNumber } from "bignumber.js";
10
10
  import { ACTIVE_SUBSCRIPTION_STATUSES, controllerName, DEFAULT_POLLING_INTERVAL, SubscriptionControllerErrorMessage } from "./constants.mjs";
11
- import { CRYPTO_AUTH_METHODS, PAYMENT_TYPES, PRODUCT_TYPES, SUBSCRIPTION_STATUSES } from "./types.mjs";
11
+ import { PAYMENT_TYPES, PRODUCT_TYPES, SUBSCRIPTION_STATUSES } from "./types.mjs";
12
12
  /**
13
13
  * Get the default state for the Subscription Controller.
14
14
  *
@@ -78,10 +78,10 @@ const MESSENGER_EXPOSED_METHODS = [
78
78
  'getSubscriptionsEligibilities',
79
79
  'cancelSubscription',
80
80
  'unCancelSubscription',
81
- 'startSubscriptionWithCard',
81
+ 'startShieldSubscriptionWithCard',
82
82
  'startSubscriptionWithCrypto',
83
83
  'stopAllPolling',
84
- 'submitSubscriptionCryptoApproval',
84
+ 'submitShieldSubscriptionCryptoApproval',
85
85
  'getCryptoApproveTransactionParams',
86
86
  'updatePaymentMethod',
87
87
  'getBillingPortalUrl',
@@ -206,107 +206,51 @@ export class SubscriptionController extends StaticIntervalPollingController() {
206
206
  });
207
207
  this.triggerAccessTokenRefresh();
208
208
  }
209
- /**
210
- * Starts a card-paid subscription checkout session for the requested products
211
- * (e.g. Shield or Money Account Plus).
212
- *
213
- * `isTrialRequested` on the request is ignored and overwritten from pricing
214
- * (`trialPeriodDays > 0`) and `trialedProducts`.
215
- *
216
- * @param request - The start subscription request.
217
- * @returns The checkout session response.
218
- */
219
- async startSubscriptionWithCard(request) {
220
- // get the latest subscriptions state before computing trial eligibility
221
- await this.getSubscriptions();
209
+ async startShieldSubscriptionWithCard(request) {
222
210
  __classPrivateFieldGet(this, _SubscriptionController_instances, "m", _SubscriptionController_assertIsUserNotSubscribed).call(this, { products: request.products });
223
- const response = await this.messenger.call('SubscriptionService:startSubscriptionWithCard', {
224
- ...request,
225
- isTrialRequested: __classPrivateFieldGet(this, _SubscriptionController_instances, "m", _SubscriptionController_getIsTrialRequested).call(this, request.products, request.recurringInterval),
226
- });
211
+ const response = await this.messenger.call('SubscriptionService:startSubscriptionWithCard', request);
227
212
  // note: no need to trigger access token refresh after startSubscriptionWithCard request because this only return stripe checkout session url, subscription not created yet
228
213
  return response;
229
214
  }
230
- /**
231
- * Starts a crypto-paid subscription for the requested products
232
- * (e.g. Shield or Money Account Plus). Unlike card checkout, this
233
- * creates the subscription immediately, so local state is refreshed
234
- * afterwards.
235
- *
236
- * `isTrialRequested` on the request is ignored and overwritten from pricing
237
- * (`trialPeriodDays > 0`) and `trialedProducts`.
238
- *
239
- * @param request - The start crypto subscription request.
240
- * @returns The start crypto subscription response.
241
- * @throws If `products` is empty.
242
- */
243
215
  async startSubscriptionWithCrypto(request) {
244
- if (request.products.length === 0) {
245
- throw new Error(SubscriptionControllerErrorMessage.SubscriptionProductsEmpty);
246
- }
247
- // get the latest subscriptions state before computing trial eligibility
248
- await this.getSubscriptions();
249
216
  __classPrivateFieldGet(this, _SubscriptionController_instances, "m", _SubscriptionController_assertIsUserNotSubscribed).call(this, { products: request.products });
250
- const response = await this.messenger.call('SubscriptionService:startSubscriptionWithCrypto', {
251
- ...request,
252
- isTrialRequested: __classPrivateFieldGet(this, _SubscriptionController_instances, "m", _SubscriptionController_getIsTrialRequested).call(this, request.products, request.recurringInterval),
253
- });
254
- // Crypto start creates the subscription immediately (unlike card checkout).
255
- await this.getSubscriptions();
217
+ const response = await this.messenger.call('SubscriptionService:startSubscriptionWithCrypto', request);
256
218
  return response;
257
219
  }
258
220
  /**
259
- * Submits a Shield ERC-20 crypto approval transaction to start or update a
260
- * crypto subscription.
261
- *
262
- * This handler is Shield / `TransactionType.shieldSubscriptionApprove` only.
263
- * Delegation-based products (e.g. Money Account) must call
264
- * `startSubscriptionWithCrypto` instead.
221
+ * Handles shield subscription crypto approval transactions.
265
222
  *
266
- * @param request - The crypto approval request.
267
- * @param request.productType - The subscription product. Typed as
268
- * `typeof PRODUCT_TYPES.SHIELD` only at the moment (future might support more
269
- * product).
270
- * @param request.txMeta - The transaction metadata. Must have type
271
- * `TransactionType.shieldSubscriptionApprove`.
272
- * @param request.isSponsored - Whether the transaction is sponsored.
273
- * @param request.rewardAccountId - The account ID of the reward subscription
274
- * to link.
275
- * @throws If `productType` is not Shield or `txMeta.type` is not
276
- * `shieldSubscriptionApprove`.
223
+ * @param txMeta - The transaction metadata.
224
+ * @param isSponsored - Whether the transaction is sponsored.
225
+ * @param rewardAccountId - The account ID of the reward subscription to link to the shield subscription.
277
226
  * @returns void
278
227
  */
279
- async submitSubscriptionCryptoApproval(request) {
280
- const { productType, txMeta, isSponsored, rewardAccountId } = request;
281
- if (
282
- // Widen for the runtime guard: JS / unsound callers may still pass a
283
- // non-Shield product.
284
- productType !== PRODUCT_TYPES.SHIELD ||
285
- txMeta.type !== TransactionType.shieldSubscriptionApprove) {
286
- throw new Error(SubscriptionControllerErrorMessage.CryptoApprovalRequiresShieldApprove);
228
+ async submitShieldSubscriptionCryptoApproval(txMeta, isSponsored, rewardAccountId) {
229
+ if (txMeta.type !== TransactionType.shieldSubscriptionApprove) {
230
+ return;
287
231
  }
288
232
  const { chainId, rawTx } = txMeta;
289
233
  if (!chainId || !rawTx) {
290
234
  throw new Error('Chain ID or raw transaction not found');
291
235
  }
292
- const { pricing, lastSelectedPaymentMethod } = this.state;
236
+ const { pricing, trialedProducts, lastSelectedPaymentMethod } = this.state;
293
237
  if (!pricing) {
294
238
  throw new Error('Subscription pricing not found');
295
239
  }
296
240
  if (!lastSelectedPaymentMethod) {
297
241
  throw new Error('Last selected payment method not found');
298
242
  }
299
- const lastSelectedPaymentMethodForProduct = lastSelectedPaymentMethod[productType];
300
- __classPrivateFieldGet(this, _SubscriptionController_instances, "m", _SubscriptionController_assertIsPaymentMethodCrypto).call(this, lastSelectedPaymentMethodForProduct);
301
- const productPrice = __classPrivateFieldGet(this, _SubscriptionController_instances, "m", _SubscriptionController_getProductPriceByProductAndPlan).call(this, productType, lastSelectedPaymentMethodForProduct.plan);
302
- // get the latest subscriptions state before computing trial eligibility
243
+ const lastSelectedPaymentMethodShield = lastSelectedPaymentMethod[PRODUCT_TYPES.SHIELD];
244
+ __classPrivateFieldGet(this, _SubscriptionController_instances, "m", _SubscriptionController_assertIsPaymentMethodCrypto).call(this, lastSelectedPaymentMethodShield);
245
+ const productPrice = __classPrivateFieldGet(this, _SubscriptionController_instances, "m", _SubscriptionController_getProductPriceByProductAndPlan).call(this, PRODUCT_TYPES.SHIELD, lastSelectedPaymentMethodShield.plan);
246
+ const isTrialed = trialedProducts?.includes(PRODUCT_TYPES.SHIELD);
247
+ // get the latest subscriptions state to check if the user has an active shield subscription
303
248
  await this.getSubscriptions();
304
- const isTrialRequested = __classPrivateFieldGet(this, _SubscriptionController_instances, "m", _SubscriptionController_getIsTrialRequested).call(this, [productType], lastSelectedPaymentMethodForProduct.plan);
305
- const currentSubscription = this.getSubscriptionByProduct(productType);
249
+ const currentSubscription = this.state.subscriptions.find((subscription) => subscription.products.some((product) => product.name === PRODUCT_TYPES.SHIELD));
306
250
  __classPrivateFieldGet(this, _SubscriptionController_instances, "m", _SubscriptionController_assertValidSubscriptionStateForCryptoApproval).call(this, {
307
- productType,
251
+ productType: PRODUCT_TYPES.SHIELD,
308
252
  });
309
- // if subscription exists, this transaction is for changing payment method
253
+ // if shield subscription exists, this transaction is for changing payment method
310
254
  const isChangePaymentMethod = Boolean(currentSubscription);
311
255
  if (isChangePaymentMethod) {
312
256
  await this.updatePaymentMethod({
@@ -314,7 +258,7 @@ export class SubscriptionController extends StaticIntervalPollingController() {
314
258
  subscriptionId: currentSubscription.id,
315
259
  chainId,
316
260
  payerAddress: txMeta.txParams.from,
317
- tokenSymbol: lastSelectedPaymentMethodForProduct.paymentTokenSymbol,
261
+ tokenSymbol: lastSelectedPaymentMethodShield.paymentTokenSymbol,
318
262
  rawTransaction: rawTx,
319
263
  recurringInterval: productPrice.interval,
320
264
  billingCycles: productPrice.minBillingCycles,
@@ -322,17 +266,16 @@ export class SubscriptionController extends StaticIntervalPollingController() {
322
266
  }
323
267
  else {
324
268
  const params = {
325
- products: [productType],
326
- isTrialRequested,
269
+ products: [PRODUCT_TYPES.SHIELD],
270
+ isTrialRequested: !isTrialed,
327
271
  recurringInterval: productPrice.interval,
328
272
  billingCycles: productPrice.minBillingCycles,
329
273
  chainId,
330
274
  payerAddress: txMeta.txParams.from,
331
- tokenSymbol: lastSelectedPaymentMethodForProduct.paymentTokenSymbol,
275
+ tokenSymbol: lastSelectedPaymentMethodShield.paymentTokenSymbol,
332
276
  rawTransaction: rawTx,
333
- cryptoAuthMethod: CRYPTO_AUTH_METHODS.ERC20_APPROVAL,
334
277
  isSponsored,
335
- useTestClock: lastSelectedPaymentMethodForProduct.useTestClock,
278
+ useTestClock: lastSelectedPaymentMethodShield.useTestClock,
336
279
  rewardAccountId,
337
280
  };
338
281
  await this.startSubscriptionWithCrypto(params);
@@ -363,7 +306,7 @@ export class SubscriptionController extends StaticIntervalPollingController() {
363
306
  if (!price) {
364
307
  throw new Error('Price not found');
365
308
  }
366
- const chainsPaymentInfo = __classPrivateFieldGet(this, _SubscriptionController_instances, "m", _SubscriptionController_findCryptoPaymentMethod).call(this, request.productType, CRYPTO_AUTH_METHODS.ERC20_APPROVAL);
309
+ const chainsPaymentInfo = pricing.paymentMethods.find((paymentMethod) => paymentMethod.type === PAYMENT_TYPES.byCrypto);
367
310
  if (!chainsPaymentInfo) {
368
311
  throw new Error('Chains payment info not found');
369
312
  }
@@ -407,15 +350,14 @@ export class SubscriptionController extends StaticIntervalPollingController() {
407
350
  /**
408
351
  * Cache the last selected payment method for a specific product.
409
352
  *
410
- * @param request - The request object.
411
- * @param request.product - The product to cache the payment method for.
412
- * @param request.paymentMethod - The payment method to cache.
413
- * @param request.paymentMethod.type - The type of the payment method.
414
- * @param request.paymentMethod.paymentTokenAddress - The payment token address.
415
- * @param request.paymentMethod.plan - The plan of the payment method.
353
+ * @param product - The product to cache the payment method for.
354
+ * @param paymentMethod - The payment method to cache.
355
+ * @param paymentMethod.type - The type of the payment method.
356
+ * @param paymentMethod.paymentTokenAddress - The payment token address.
357
+ * @param paymentMethod.plan - The plan of the payment method.
358
+ * @param paymentMethod.product - The product of the payment method.
416
359
  */
417
- cacheLastSelectedPaymentMethod(request) {
418
- const { product, paymentMethod } = request;
360
+ cacheLastSelectedPaymentMethod(product, paymentMethod) {
419
361
  if (paymentMethod.type === PAYMENT_TYPES.byCrypto &&
420
362
  (!paymentMethod.paymentTokenAddress || !paymentMethod.paymentTokenSymbol)) {
421
363
  throw new Error(SubscriptionControllerErrorMessage.PaymentTokenAddressAndSymbolRequiredForCrypto);
@@ -454,8 +396,7 @@ export class SubscriptionController extends StaticIntervalPollingController() {
454
396
  * recurringInterval: RecurringInterval.Month,
455
397
  * billingCycles: 1,
456
398
  * }
457
- * @returns resolves to true if the sponsorship is supported and intents were submitted successfully, false if the chain does not support sponsorship or the user has already trialed
458
- * @throws If the crypto payment method or chain is missing from pricing
399
+ * @returns resolves to true if the sponsorship is supported and intents were submitted successfully, false otherwise
459
400
  */
460
401
  async submitSponsorshipIntents(request) {
461
402
  if (request.products.length === 0) {
@@ -464,9 +405,7 @@ export class SubscriptionController extends StaticIntervalPollingController() {
464
405
  __classPrivateFieldGet(this, _SubscriptionController_instances, "m", _SubscriptionController_assertIsUserNotSubscribed).call(this, { products: request.products });
465
406
  const selectedPaymentMethod = this.state.lastSelectedPaymentMethod?.[request.products[0]];
466
407
  __classPrivateFieldGet(this, _SubscriptionController_instances, "m", _SubscriptionController_assertIsPaymentMethodCrypto).call(this, selectedPaymentMethod);
467
- const cryptoAuthMethod = selectedPaymentMethod.cryptoAuthMethod ??
468
- CRYPTO_AUTH_METHODS.ERC20_APPROVAL;
469
- const isEligibleForTrialedSponsorship = __classPrivateFieldGet(this, _SubscriptionController_instances, "m", _SubscriptionController_getIsEligibleForTrialedSponsorship).call(this, request.chainId, request.products, cryptoAuthMethod);
408
+ const isEligibleForTrialedSponsorship = __classPrivateFieldGet(this, _SubscriptionController_instances, "m", _SubscriptionController_getIsEligibleForTrialedSponsorship).call(this, request.chainId, request.products);
470
409
  if (!isEligibleForTrialedSponsorship) {
471
410
  return false;
472
411
  }
@@ -532,7 +471,7 @@ export class SubscriptionController extends StaticIntervalPollingController() {
532
471
  * @returns The token approve amount
533
472
  */
534
473
  getTokenApproveAmount(price, tokenPaymentInfo) {
535
- const conversionRate = tokenPaymentInfo.conversionRate?.[price.currency];
474
+ const conversionRate = tokenPaymentInfo.conversionRate[price.currency];
536
475
  if (!conversionRate) {
537
476
  throw new Error('Conversion rate not found');
538
477
  }
@@ -552,7 +491,7 @@ export class SubscriptionController extends StaticIntervalPollingController() {
552
491
  * @returns The token balance amount
553
492
  */
554
493
  getTokenMinimumBalanceAmount(price, tokenPaymentInfo) {
555
- const conversionRate = tokenPaymentInfo.conversionRate?.[price.currency];
494
+ const conversionRate = tokenPaymentInfo.conversionRate[price.currency];
556
495
  if (!conversionRate) {
557
496
  throw new Error('Conversion rate not found');
558
497
  }
@@ -634,74 +573,15 @@ _SubscriptionController_instances = new WeakSet(), _SubscriptionController_getSu
634
573
  !value.paymentTokenSymbol) {
635
574
  throw new Error(SubscriptionControllerErrorMessage.PaymentMethodNotCrypto);
636
575
  }
637
- }, _SubscriptionController_getIsEligibleForTrialedSponsorship = function _SubscriptionController_getIsEligibleForTrialedSponsorship(chainId, products, cryptoAuthMethod) {
638
- const isSponsorshipSupported = __classPrivateFieldGet(this, _SubscriptionController_instances, "m", _SubscriptionController_getChainSupportsSponsorship).call(this, chainId, products[0], cryptoAuthMethod);
576
+ }, _SubscriptionController_getIsEligibleForTrialedSponsorship = function _SubscriptionController_getIsEligibleForTrialedSponsorship(chainId, products) {
577
+ const isSponsorshipSupported = __classPrivateFieldGet(this, _SubscriptionController_instances, "m", _SubscriptionController_getChainSupportsSponsorship).call(this, chainId);
639
578
  // verify if the user has trialed the provided products before
640
579
  const hasTrialedBefore = this.state.trialedProducts.some((product) => products.includes(product));
641
580
  return isSponsorshipSupported && !hasTrialedBefore;
642
- }, _SubscriptionController_getIsTrialRequested = function _SubscriptionController_getIsTrialRequested(products, plan) {
643
- return products.every((productType) => {
644
- if (this.state.trialedProducts.includes(productType)) {
645
- return false;
646
- }
647
- const productPrice = __classPrivateFieldGet(this, _SubscriptionController_instances, "m", _SubscriptionController_getProductPriceByProductAndPlan).call(this, productType, plan);
648
- return productPrice.trialPeriodDays > 0;
649
- });
650
- }, _SubscriptionController_findCryptoPaymentMethod = function _SubscriptionController_findCryptoPaymentMethod(productType, cryptoAuthMethod) {
651
- const matches = [];
652
- for (const paymentMethod of this.state.pricing?.paymentMethods ?? []) {
653
- if (paymentMethod.type !== PAYMENT_TYPES.byCrypto) {
654
- continue;
655
- }
656
- const resolved = __classPrivateFieldGet(this, _SubscriptionController_instances, "m", _SubscriptionController_resolveCryptoPaymentMethodDefaults).call(this, paymentMethod);
657
- if (!resolved) {
658
- continue;
659
- }
660
- if (resolved.cryptoAuthMethod === cryptoAuthMethod &&
661
- resolved.products.includes(productType)) {
662
- matches.push({
663
- method: paymentMethod,
664
- explicit: resolved.explicit,
665
- });
666
- }
667
- }
668
- if (matches.length === 0) {
669
- return undefined;
670
- }
671
- const explicitMatches = matches.filter((match) => match.explicit);
672
- const candidates = explicitMatches.length > 0 ? explicitMatches : matches;
673
- if (candidates.length > 1) {
674
- throw new Error('Multiple matching crypto payment methods found');
675
- }
676
- return candidates[0].method;
677
- }, _SubscriptionController_resolveCryptoPaymentMethodDefaults = function _SubscriptionController_resolveCryptoPaymentMethodDefaults(paymentMethod) {
678
- const productsPresent = paymentMethod.products !== undefined;
679
- const authPresent = paymentMethod.cryptoAuthMethod !== undefined;
680
- if (!productsPresent && !authPresent) {
681
- return {
682
- products: [PRODUCT_TYPES.SHIELD],
683
- cryptoAuthMethod: CRYPTO_AUTH_METHODS.ERC20_APPROVAL,
684
- explicit: false,
685
- };
686
- }
687
- if (!paymentMethod.products?.length || !paymentMethod.cryptoAuthMethod) {
688
- return undefined;
689
- }
690
- return {
691
- products: paymentMethod.products,
692
- cryptoAuthMethod: paymentMethod.cryptoAuthMethod,
693
- explicit: true,
694
- };
695
- }, _SubscriptionController_getChainSupportsSponsorship = function _SubscriptionController_getChainSupportsSponsorship(chainId, productType, cryptoAuthMethod) {
696
- const cryptoPaymentInfo = __classPrivateFieldGet(this, _SubscriptionController_instances, "m", _SubscriptionController_findCryptoPaymentMethod).call(this, productType, cryptoAuthMethod);
697
- if (!cryptoPaymentInfo) {
698
- throw new Error('Chains payment info not found');
699
- }
700
- const chainPaymentInfo = cryptoPaymentInfo.chains?.find((chain) => chain.chainId === chainId);
701
- if (!chainPaymentInfo) {
702
- throw new Error('Invalid chain id');
703
- }
704
- return Boolean(chainPaymentInfo.isSponsorshipSupported);
581
+ }, _SubscriptionController_getChainSupportsSponsorship = function _SubscriptionController_getChainSupportsSponsorship(chainId) {
582
+ const cryptoPaymentInfo = this.state.pricing?.paymentMethods.find((paymentMethod) => paymentMethod.type === PAYMENT_TYPES.byCrypto);
583
+ const isSponsorshipSupported = cryptoPaymentInfo?.chains?.find((chain) => chain.chainId === chainId)?.isSponsorshipSupported;
584
+ return Boolean(isSponsorshipSupported);
705
585
  }, _SubscriptionController_areTrialedProductsEqual = function _SubscriptionController_areTrialedProductsEqual(oldTrialedProducts, newTrialedProducts) {
706
586
  return (oldTrialedProducts.length === newTrialedProducts?.length &&
707
587
  oldTrialedProducts.every((product) => newTrialedProducts?.includes(product)));