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
5 changes: 5 additions & 0 deletions packages/subscription-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Trigger `triggerAccessTokenRefresh` everytime subscription state change instead of only when polling ([#7149](https://github.com/MetaMask/core/pull/7149))
- Remove `triggerAccessTokenRefresh` after `startShieldSubscriptionWithCard` ([#7149](https://github.com/MetaMask/core/pull/7149))

## [4.2.1]

### Added
Expand Down
14 changes: 4 additions & 10 deletions packages/subscription-controller/src/SubscriptionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,6 @@ export class SubscriptionController extends StaticIntervalPollingController()<
> {
readonly #subscriptionService: ISubscriptionService;

#shouldCallRefreshAuthToken: boolean = false;

/**
* Creates a new SubscriptionController instance.
*
Expand Down Expand Up @@ -391,7 +389,8 @@ export class SubscriptionController extends StaticIntervalPollingController()<
state.trialedProducts = newTrialedProducts;
state.lastSubscription = newLastSubscription;
});
this.#shouldCallRefreshAuthToken = true;
// trigger access token refresh to ensure the user has the latest access token if subscription state change
this.triggerAccessTokenRefresh();
}

return newSubscriptions;
Expand Down Expand Up @@ -466,8 +465,7 @@ export class SubscriptionController extends StaticIntervalPollingController()<

const response =
await this.#subscriptionService.startSubscriptionWithCard(request);

this.triggerAccessTokenRefresh();
// note: no need to trigger access token refresh after startSubscriptionWithCard request because this only return stripe checkout session url, subscription not created yet

return response;
}
Expand All @@ -476,7 +474,7 @@ export class SubscriptionController extends StaticIntervalPollingController()<
this.#assertIsUserNotSubscribed({ products: request.products });
const response =
await this.#subscriptionService.startSubscriptionWithCrypto(request);
this.triggerAccessTokenRefresh();

return response;
}

Expand Down Expand Up @@ -730,10 +728,6 @@ export class SubscriptionController extends StaticIntervalPollingController()<

async _executePoll(): Promise<void> {
await this.getSubscriptions();
if (this.#shouldCallRefreshAuthToken) {
this.triggerAccessTokenRefresh();
this.#shouldCallRefreshAuthToken = false;
}
}

/**
Expand Down
Loading