Skip to content

Commit 4b303b4

Browse files
committed
Minor refactors to event listeners for consistency
1 parent beacf9b commit 4b303b4

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

packages/assets-controllers/src/TokenDetectionController.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,14 @@ export class TokenDetectionController extends StaticIntervalPollingController<
278278

279279
this.messagingSystem.subscribe(
280280
'AccountsController:selectedAccountChange',
281-
async (account) => {
281+
async ({ address: newSelectedAddress }) => {
282+
const isSelectedAddressChanged =
283+
this.#selectedAddress !== newSelectedAddress;
282284
if (
283-
this.#selectedAddress !== account.address &&
285+
isSelectedAddressChanged &&
284286
this.#isDetectionEnabledFromPreferences
285287
) {
286-
this.#selectedAddress = account.address;
288+
this.#selectedAddress = newSelectedAddress;
287289
await this.#restartTokenDetection({
288290
selectedAddress: this.#selectedAddress,
289291
});
@@ -297,12 +299,12 @@ export class TokenDetectionController extends StaticIntervalPollingController<
297299
this.#networkClientId = selectedNetworkClientId;
298300
const newChainId = this.#getCorrectChainId(selectedNetworkClientId);
299301
const isChainIdChanged = this.#chainId !== newChainId;
300-
this.#chainId = newChainId;
301302

302303
this.#isDetectionEnabledForNetwork =
303304
isTokenDetectionSupportedForNetwork(newChainId);
304305

305-
if (this.#isDetectionEnabledForNetwork && isChainIdChanged) {
306+
if (isChainIdChanged && this.#isDetectionEnabledForNetwork) {
307+
this.#chainId = newChainId;
306308
await this.#restartTokenDetection({
307309
chainId: this.#chainId,
308310
});

0 commit comments

Comments
 (0)