Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Prevent State Changes for ignoreTokens on Non-Current Network #5014

Merged
merged 9 commits into from
Dec 17, 2024
4 changes: 2 additions & 2 deletions packages/assets-controllers/src/TokensController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ describe('TokensController', () => {
decimals: 6,
});
controller.ignoreTokens(['0x03'], InfuraNetworkType.goerli);
expect(controller.state.ignoredTokens).toStrictEqual(['0x03']);
expect(controller.state.ignoredTokens).toStrictEqual([]);

// Validate the overall ignored tokens state
expect(controller.state.allIgnoredTokens).toStrictEqual({
Expand Down Expand Up @@ -879,7 +879,7 @@ describe('TokensController', () => {
// Ignore the token on Sepolia
controller.ignoreTokens(['0x01'], InfuraNetworkType.sepolia);
expect(controller.state.tokens).toHaveLength(0);
expect(controller.state.ignoredTokens).toStrictEqual(['0x01']);
expect(controller.state.ignoredTokens).toStrictEqual([]);

// Attempt to ignore a token that was added on Goerli
await controller.addToken({
Expand Down
8 changes: 5 additions & 3 deletions packages/assets-controllers/src/TokensController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ export class TokensController extends BaseController<
tokenAddressesToIgnore: string[],
networkClientId?: NetworkClientId,
) {
let interactingChainId;
let interactingChainId = this.#chainId;
if (networkClientId) {
interactingChainId = this.messagingSystem.call(
'NetworkController:getNetworkClientById',
Expand Down Expand Up @@ -624,12 +624,14 @@ export class TokensController extends BaseController<
});

this.update((state) => {
state.ignoredTokens = newIgnoredTokens;
state.tokens = newTokens;
state.detectedTokens = newDetectedTokens;
state.allIgnoredTokens = newAllIgnoredTokens;
state.allDetectedTokens = newAllDetectedTokens;
state.allTokens = newAllTokens;
if (interactingChainId === this.#chainId) {
state.tokens = newTokens;
state.ignoredTokens = newIgnoredTokens;
}
});
}

Expand Down
Loading