Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/subscription-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +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`. ([#10994](https://github.com/MetaMask/core/pull/10994))
- **BREAKING:** Remove `builderCode` from `PerpsBenefitUsage` and from benefits-response validation. The Perps benefits payload no longer includes it, and requiring the field rejected otherwise valid responses. ([#10995](https://github.com/MetaMask/core/pull/10995))

## [14.0.2]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,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: {
Expand All @@ -830,12 +830,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);
},
Expand Down
14 changes: 7 additions & 7 deletions packages/subscription-controller/src/SubscriptionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<SubscriptionBenefitsResponse> {
this.#assertIsActiveMoneyAccountPlusSubscriber();
Expand All @@ -464,10 +468,6 @@ export class SubscriptionController extends StaticIntervalPollingController()<
: undefined;
});

if (!benefits.eligible) {
throw new Error(SubscriptionControllerErrorMessage.UserNotSubscribed);
}

return benefits;
}

Expand Down
Loading