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 non-current network tokens from being hidden incorrectly #28674

Merged
merged 2 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,27 @@ index a13403446a2376d4d905a9ef733941798da89c88..3c8229f9ea40f4c1ee760a22884e1066
/**
* The list of currencies that can be supplied as the `vsCurrency` parameter to
* the `/spot-prices` endpoint, in lowercase form.
diff --git a/dist/TokensController.cjs b/dist/TokensController.cjs
index 343b343b8300136756d96acac77aab8140efc95a..69d8e2ea84d6303a3af02bd95458ef3060c76f2b 100644
--- a/dist/TokensController.cjs
+++ b/dist/TokensController.cjs
@@ -270,13 +270,16 @@ class TokensController extends base_controller_1.BaseController {
* @param networkClientId - Optional network client ID used to determine interacting chain ID.
*/
ignoreTokens(tokenAddressesToIgnore, networkClientId) {
- const { ignoredTokens, detectedTokens, tokens } = this.state;
- const ignoredTokensMap = {};
- let newIgnoredTokens = [...ignoredTokens];
let interactingChainId;
if (networkClientId) {
interactingChainId = this.messagingSystem.call('NetworkController:getNetworkClientById', networkClientId).configuration.chainId;
}
+ const { allTokens, allDetectedTokens, allIgnoredTokens } = this.state;
+ const ignoredTokensMap = {};
+ const ignoredTokens = allIgnoredTokens[interactingChainId ?? __classPrivateFieldGet(this, _TokensController_chainId, "f")]?.[__classPrivateFieldGet(this, _TokensController_instances, "m", _TokensController_getSelectedAddress).call(this)] || [];
+ let newIgnoredTokens = [...ignoredTokens];
+ const tokens = allTokens[interactingChainId ?? __classPrivateFieldGet(this, _TokensController_chainId, "f")]?.[__classPrivateFieldGet(this, _TokensController_instances, "m", _TokensController_getSelectedAddress).call(this)] || [];
+ const detectedTokens = allDetectedTokens[interactingChainId ?? __classPrivateFieldGet(this, _TokensController_chainId, "f")]?.[__classPrivateFieldGet(this, _TokensController_instances, "m", _TokensController_getSelectedAddress).call(this)] || [];
const checksummedTokenAddresses = tokenAddressesToIgnore.map((address) => {
const checksumAddress = (0, controller_utils_1.toChecksumHexAddress)(address);
ignoredTokensMap[address.toLowerCase()] = true;
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import thunk from 'redux-thunk';
import * as actions from '../../../../store/actions';
import { renderWithProvider } from '../../../../../test/lib/render-helpers';
import mockState from '../../../../../test/data/mock-state.json';
import { mockNetworkState } from '../../../../../test/stub/networks';
import HideTokenConfirmationModal from '.';

const mockHistoryPush = jest.fn();
Expand All @@ -25,6 +26,13 @@ describe('Hide Token Confirmation Modal', () => {
image: '',
};

const tokenState2 = {
address: '0xTokenAddress2',
symbol: 'TKN2',
image: '',
chainId: '0x89',
};

const tokenModalState = {
...mockState,
appState: {
Expand Down Expand Up @@ -82,4 +90,47 @@ describe('Hide Token Confirmation Modal', () => {
networkClientId: 'goerli',
});
});

it('should hide token from another chain', () => {
const tokenModalStateWithDifferentChain = {
...mockState,
metamask: {
...mockState.metamask,
selectedNetworkClientId: 'bsc',
...mockNetworkState({ chainId: '0x89', id: 'bsc' }),
},
appState: {
...mockState.appState,
modal: {
modalState: {
props: {
history: {
push: mockHistoryPush,
},
token: tokenState2,
},
},
},
},
};

const mockStoreDifferentChain = configureMockStore([thunk])(
tokenModalStateWithDifferentChain,
);

const { queryByTestId } = renderWithProvider(
<HideTokenConfirmationModal />,
mockStoreDifferentChain,
);

const hideButton = queryByTestId('hide-token-confirmation__hide');

fireEvent.click(hideButton);

expect(mockHideModal).toHaveBeenCalled();
expect(actions.ignoreTokens).toHaveBeenCalledWith({
tokensToIgnore: tokenState2.address,
networkClientId: 'bsc',
});
});
});
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4975,7 +4975,7 @@ __metadata:

"@metamask/assets-controllers@patch:@metamask/assets-controllers@npm%3A45.1.0#~/.yarn/patches/@metamask-assets-controllers-npm-45.1.0-d914c453f0.patch":
version: 45.1.0
resolution: "@metamask/assets-controllers@patch:@metamask/assets-controllers@npm%3A45.1.0#~/.yarn/patches/@metamask-assets-controllers-npm-45.1.0-d914c453f0.patch::version=45.1.0&hash=86167d"
resolution: "@metamask/assets-controllers@patch:@metamask/assets-controllers@npm%3A45.1.0#~/.yarn/patches/@metamask-assets-controllers-npm-45.1.0-d914c453f0.patch::version=45.1.0&hash=cfcadc"
dependencies:
"@ethereumjs/util": "npm:^8.1.0"
"@ethersproject/abi": "npm:^5.7.0"
Expand Down Expand Up @@ -5008,7 +5008,7 @@ __metadata:
"@metamask/keyring-controller": ^19.0.0
"@metamask/network-controller": ^22.0.0
"@metamask/preferences-controller": ^15.0.0
checksum: 10/985ec7dffb75aaff8eea00f556157e42cd5db063cbfa94dfd4f070c5b9d98b1315f3680fa7370f4c734a1688598bbda9c44a7c33c342e1d123d6ee2edd6120fc
checksum: 10/d2f7d5bb07feceb5b972beda019f411cd073ece3ed682b21373fc6d4c06812ec10245b40c78ce6316c5fb1718278fd269b73e13d37c2ff07b5bb3ecdfd8278f7
languageName: node
linkType: hard

Expand Down
Loading