Skip to content

Commit

Permalink
Subscribe to AccountsController:selectedAccountChange event
Browse files Browse the repository at this point in the history
  • Loading branch information
MajorLift committed Jan 24, 2024
1 parent 3b987d1 commit feb1ff9
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/assets-controllers/src/TokenDetectionController.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { AccountsControllerSelectedAccountChangeEvent } from '@metamask/accounts-controller';
import type {
RestrictedControllerMessenger,
ControllerGetStateAction,
Expand Down Expand Up @@ -51,6 +52,7 @@ export type TokenDetectionControllerEvents =
TokenDetectionControllerStateChangeEvent;

export type AllowedEvents =
| AccountsControllerSelectedAccountChangeEvent
| NetworkControllerStateChangeEvent
| NetworkControllerNetworkDidChangeEvent
| TokenListStateChange;
Expand Down Expand Up @@ -195,6 +197,18 @@ export class TokenDetectionController extends StaticIntervalPollingController<
}
},
);

this.messagingSystem.subscribe(
'AccountsController:selectedAccountChange',
async (account) => {
if (
this.#selectedAddress !== account.address &&
this.#isDetectionEnabledFromPreferences
) {
this.#selectedAddress = account.address;
await this.#restartTokenDetection({
selectedAddress: this.#selectedAddress,
});
}
},
);
Expand Down

0 comments on commit feb1ff9

Please sign in to comment.