Skip to content

Commit

Permalink
Minor refactors to event listeners for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
MajorLift committed Feb 6, 2024
1 parent beacf9b commit 4b303b4
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/assets-controllers/src/TokenDetectionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,14 @@ export class TokenDetectionController extends StaticIntervalPollingController<

this.messagingSystem.subscribe(
'AccountsController:selectedAccountChange',
async (account) => {
async ({ address: newSelectedAddress }) => {
const isSelectedAddressChanged =
this.#selectedAddress !== newSelectedAddress;
if (
this.#selectedAddress !== account.address &&
isSelectedAddressChanged &&
this.#isDetectionEnabledFromPreferences
) {
this.#selectedAddress = account.address;
this.#selectedAddress = newSelectedAddress;
await this.#restartTokenDetection({
selectedAddress: this.#selectedAddress,
});
Expand All @@ -297,12 +299,12 @@ export class TokenDetectionController extends StaticIntervalPollingController<
this.#networkClientId = selectedNetworkClientId;
const newChainId = this.#getCorrectChainId(selectedNetworkClientId);
const isChainIdChanged = this.#chainId !== newChainId;
this.#chainId = newChainId;

this.#isDetectionEnabledForNetwork =
isTokenDetectionSupportedForNetwork(newChainId);

if (this.#isDetectionEnabledForNetwork && isChainIdChanged) {
if (isChainIdChanged && this.#isDetectionEnabledForNetwork) {
this.#chainId = newChainId;
await this.#restartTokenDetection({
chainId: this.#chainId,
});
Expand Down

0 comments on commit 4b303b4

Please sign in to comment.