From 5f3a143af902cb350470448e2e84a97492f61d96 Mon Sep 17 00:00:00 2001 From: Tuna Date: Thu, 22 Oct 2026 16:36:15 +0700 Subject: [PATCH 1/3] fix: benefit eligible return not throw --- .../src/services/RewardsIntegrationService.ts | 13 +++++++------ packages/subscription-controller/CHANGELOG.md | 4 ++++ .../SubscriptionController-method-action-types.ts | 10 +++++++--- .../src/SubscriptionController.test.ts | 9 ++++----- .../src/SubscriptionController.ts | 14 +++++++------- 5 files changed, 29 insertions(+), 21 deletions(-) diff --git a/packages/perps-controller/src/services/RewardsIntegrationService.ts b/packages/perps-controller/src/services/RewardsIntegrationService.ts index 5c5f9695480..5d6a83f2958 100644 --- a/packages/perps-controller/src/services/RewardsIntegrationService.ts +++ b/packages/perps-controller/src/services/RewardsIntegrationService.ts @@ -988,12 +988,13 @@ function isValidTradingFeeGrant( * Whether a benefits rejection definitively means "this profile is not * entitled", as opposed to "the read failed". * - * `SubscriptionController.getBenefits` throws `UserNotSubscribed` when the - * subscription is inactive or the response reports ineligibility, and clears - * its own benefits state on that path. Treating it as a transport failure would - * keep serving a cached waiver for the rest of the staleness window — up to ten - * minutes of free trading after entitlement ended — so it is converted to a - * real `null` answer instead. + * `SubscriptionController.getBenefits` throws `UserNotSubscribed` when there + * is no active subscription, and clears its own benefits state on that path. + * An ineligible response is returned with `eligible: false` and does not reach + * this check. Treating the inactive-subscription rejection as a transport + * failure would keep serving a cached waiver for the rest of the staleness + * window — up to ten minutes of free trading after entitlement ended — so it + * is converted to a real `null` answer instead. * * Matched on the message because the controller throws a plain `Error`; any * other failure stays a failure and preserves the cached snapshot. diff --git a/packages/subscription-controller/CHANGELOG.md b/packages/subscription-controller/CHANGELOG.md index ef8c65f2981..66e878d81d7 100644 --- a/packages/subscription-controller/CHANGELOG.md +++ b/packages/subscription-controller/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- **BREAKING:** `getBenefits` returns an ineligible benefits response instead of throwing `UserNotSubscribed`. + ## [14.0.2] ### Changed diff --git a/packages/subscription-controller/src/SubscriptionController-method-action-types.ts b/packages/subscription-controller/src/SubscriptionController-method-action-types.ts index 65a941235b3..d340e9f81ba 100644 --- a/packages/subscription-controller/src/SubscriptionController-method-action-types.ts +++ b/packages/subscription-controller/src/SubscriptionController-method-action-types.ts @@ -23,9 +23,13 @@ export type SubscriptionControllerGetSubscriptionsAction = { /** * Gets and stores the user's subscription benefits. * - * @returns The benefits response. - * @throws If the user is not an active Money Account Plus subscriber or is - * not eligible for benefits. + * An ineligible response is a normal result. Persisted benefits are cleared + * and the response is returned so callers can branch on `eligible`. That + * includes a provisional subscription whose benefits are not ready yet, + * which is distinct from having no active Money Account Plus subscription. + * + * @returns The benefits response, including when `eligible` is false. + * @throws If the user is not an active Money Account Plus subscriber. */ export type SubscriptionControllerGetBenefitsAction = { type: `SubscriptionController:getBenefits`; diff --git a/packages/subscription-controller/src/SubscriptionController.test.ts b/packages/subscription-controller/src/SubscriptionController.test.ts index d16b5bd636f..22e182ff4f2 100644 --- a/packages/subscription-controller/src/SubscriptionController.test.ts +++ b/packages/subscription-controller/src/SubscriptionController.test.ts @@ -819,7 +819,7 @@ describe('SubscriptionController', () => { ); }); - it('should clear benefits state before throwing UserNotSubscribed for an ineligible response', async () => { + it('should clear benefits state and return an ineligible response', async () => { await withController( { state: { @@ -832,12 +832,11 @@ describe('SubscriptionController', () => { MOCK_INELIGIBLE_BENEFITS_RESPONSE, ); - await expect( - rootMessenger.call('SubscriptionController:getBenefits'), - ).rejects.toThrow( - SubscriptionControllerErrorMessage.UserNotSubscribed, + const result = await rootMessenger.call( + 'SubscriptionController:getBenefits', ); + expect(result).toStrictEqual(MOCK_INELIGIBLE_BENEFITS_RESPONSE); expect(controller.state.benefits).toBeUndefined(); expect(mockService.getBenefits).toHaveBeenCalledTimes(1); }, diff --git a/packages/subscription-controller/src/SubscriptionController.ts b/packages/subscription-controller/src/SubscriptionController.ts index cbce479b240..55d9fde9bf7 100644 --- a/packages/subscription-controller/src/SubscriptionController.ts +++ b/packages/subscription-controller/src/SubscriptionController.ts @@ -439,9 +439,13 @@ export class SubscriptionController extends StaticIntervalPollingController()< /** * Gets and stores the user's subscription benefits. * - * @returns The benefits response. - * @throws If the user is not an active Money Account Plus subscriber or is - * not eligible for benefits. + * An ineligible response is a normal result. Persisted benefits are cleared + * and the response is returned so callers can branch on `eligible`. That + * includes a provisional subscription whose benefits are not ready yet, + * which is distinct from having no active Money Account Plus subscription. + * + * @returns The benefits response, including when `eligible` is false. + * @throws If the user is not an active Money Account Plus subscriber. */ async getBenefits(): Promise { this.#assertIsActiveMoneyAccountPlusSubscriber(); @@ -464,10 +468,6 @@ export class SubscriptionController extends StaticIntervalPollingController()< : undefined; }); - if (!benefits.eligible) { - throw new Error(SubscriptionControllerErrorMessage.UserNotSubscribed); - } - return benefits; } From e4f7f73184e639a3d4dbc9d1fc2b8b22f16eeb00 Mon Sep 17 00:00:00 2001 From: Tuna Date: Thu, 22 Oct 2026 16:38:29 +0700 Subject: [PATCH 2/3] chore: update changelog --- packages/subscription-controller/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/subscription-controller/CHANGELOG.md b/packages/subscription-controller/CHANGELOG.md index 66e878d81d7..7a2a2b2f775 100644 --- a/packages/subscription-controller/CHANGELOG.md +++ b/packages/subscription-controller/CHANGELOG.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed -- **BREAKING:** `getBenefits` returns an ineligible benefits response instead of throwing `UserNotSubscribed`. +- **BREAKING:** `getBenefits` returns an ineligible benefits response instead of throwing `UserNotSubscribed`. ([#10994](https://github.com/MetaMask/core/pull/10994)) ## [14.0.2] From 6488ae025de17b8cfd5e9eb0840e9219b93ba002 Mon Sep 17 00:00:00 2001 From: Tuna Date: Thu, 22 Oct 2026 16:45:21 +0700 Subject: [PATCH 3/3] chore: revert perps controller comment --- .../src/services/RewardsIntegrationService.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/perps-controller/src/services/RewardsIntegrationService.ts b/packages/perps-controller/src/services/RewardsIntegrationService.ts index 5d6a83f2958..5c5f9695480 100644 --- a/packages/perps-controller/src/services/RewardsIntegrationService.ts +++ b/packages/perps-controller/src/services/RewardsIntegrationService.ts @@ -988,13 +988,12 @@ function isValidTradingFeeGrant( * Whether a benefits rejection definitively means "this profile is not * entitled", as opposed to "the read failed". * - * `SubscriptionController.getBenefits` throws `UserNotSubscribed` when there - * is no active subscription, and clears its own benefits state on that path. - * An ineligible response is returned with `eligible: false` and does not reach - * this check. Treating the inactive-subscription rejection as a transport - * failure would keep serving a cached waiver for the rest of the staleness - * window — up to ten minutes of free trading after entitlement ended — so it - * is converted to a real `null` answer instead. + * `SubscriptionController.getBenefits` throws `UserNotSubscribed` when the + * subscription is inactive or the response reports ineligibility, and clears + * its own benefits state on that path. Treating it as a transport failure would + * keep serving a cached waiver for the rest of the staleness window — up to ten + * minutes of free trading after entitlement ended — so it is converted to a + * real `null` answer instead. * * Matched on the message because the controller throws a plain `Error`; any * other failure stays a failure and preserves the cached snapshot.