Skip to content

Commit

Permalink
fix: shadowed state variable
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptodev-2s committed May 23, 2024
1 parent 719f9fd commit e28003f
Showing 1 changed file with 43 additions and 22 deletions.
65 changes: 43 additions & 22 deletions packages/assets-controllers/src/NftDetectionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,29 +408,11 @@ export class NftDetectionController extends StaticIntervalPollingController<
this.#disabled = disabled;

this.#getNftState = getNftState;
onPreferencesStateChange(({ selectedAddress, useNftDetection }) => {
const { selectedAddress: currentSelectedAddress } = this.state;
if (
selectedAddress !== currentSelectedAddress ||
!useNftDetection !== this.#disabled
) {
this.update((state) => {
state.selectedAddress = selectedAddress;
});
this.#disabled = !useNftDetection;
if (useNftDetection) {
this.start();
} else {
this.stop();
}
}
});

onNetworkStateChange(({ providerConfig }) => {
this.update((state) => {
state.chainId = providerConfig.chainId;
});
});
onPreferencesStateChange(this.#onPreferencesStateChange.bind(this));

onNetworkStateChange(this.#onNetworkStateChange.bind(this));

this.#addNft = addNft;
this.setIntervalLength(this.#interval);
}
Expand Down Expand Up @@ -494,6 +476,45 @@ export class NftDetectionController extends StaticIntervalPollingController<
return networkClient.configuration.chainId === ChainId.mainnet;
};

/**
* Handles the state change of the preference controller.
* @param preferencesState - The new state of the preference controller.
* @param preferencesState.selectedAddress - The current selected address of the preference controller.
* @param preferencesState.useNftDetection - Boolean indicating user preference on NFT detection.
*/
#onPreferencesStateChange({
selectedAddress,
useNftDetection,
}: PreferencesState) {
const { selectedAddress: currentSelectedAddress } = this.state;
if (
selectedAddress !== currentSelectedAddress ||
!useNftDetection !== this.#disabled
) {
this.update((state) => {
state.selectedAddress = selectedAddress;
});
this.#disabled = !useNftDetection;
if (useNftDetection) {
this.start();
} else {
this.stop();
}
}
}

/**
* Handles the event when the network changes.
*
* @param networkState - The updated network state.
* @param networkState.providerConfig - RPC URL and network name provider settings of the currently connected network
*/
#onNetworkStateChange({ providerConfig }: NetworkState) {
this.update((state) => {
state.chainId = providerConfig.chainId;
});
}

#getOwnerNftApi({ address, next }: { address: string; next?: string }) {
return `${NFT_API_BASE_URL}/users/${address}/tokens?chainIds=1&limit=50&includeTopBid=true&continuation=${
next ?? ''
Expand Down

0 comments on commit e28003f

Please sign in to comment.