Skip to content

Commit 9787615

Browse files
committed
fix: prevent non-current network tokens from being hidden incorrectly
1 parent 23ec947 commit 9787615

File tree

3 files changed

+77
-2
lines changed

3 files changed

+77
-2
lines changed

.yarn/patches/@metamask-assets-controllers-npm-45.1.0-d914c453f0.patch

+24
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,27 @@ index a13403446a2376d4d905a9ef733941798da89c88..3c8229f9ea40f4c1ee760a22884e1066
3333
/**
3434
* The list of currencies that can be supplied as the `vsCurrency` parameter to
3535
* the `/spot-prices` endpoint, in lowercase form.
36+
diff --git a/dist/TokensController.cjs b/dist/TokensController.cjs
37+
index 343b343b8300136756d96acac77aab8140efc95a..69d8e2ea84d6303a3af02bd95458ef3060c76f2b 100644
38+
--- a/dist/TokensController.cjs
39+
+++ b/dist/TokensController.cjs
40+
@@ -270,13 +270,16 @@ class TokensController extends base_controller_1.BaseController {
41+
* @param networkClientId - Optional network client ID used to determine interacting chain ID.
42+
*/
43+
ignoreTokens(tokenAddressesToIgnore, networkClientId) {
44+
- const { ignoredTokens, detectedTokens, tokens } = this.state;
45+
- const ignoredTokensMap = {};
46+
- let newIgnoredTokens = [...ignoredTokens];
47+
let interactingChainId;
48+
if (networkClientId) {
49+
interactingChainId = this.messagingSystem.call('NetworkController:getNetworkClientById', networkClientId).configuration.chainId;
50+
}
51+
+ const { allTokens, allDetectedTokens, allIgnoredTokens } = this.state;
52+
+ const ignoredTokensMap = {};
53+
+ const ignoredTokens = allIgnoredTokens[interactingChainId ?? __classPrivateFieldGet(this, _TokensController_chainId, "f")]?.[__classPrivateFieldGet(this, _TokensController_instances, "m", _TokensController_getSelectedAddress).call(this)] || [];
54+
+ let newIgnoredTokens = [...ignoredTokens];
55+
+ const tokens = allTokens[interactingChainId ?? __classPrivateFieldGet(this, _TokensController_chainId, "f")]?.[__classPrivateFieldGet(this, _TokensController_instances, "m", _TokensController_getSelectedAddress).call(this)] || [];
56+
+ const detectedTokens = allDetectedTokens[interactingChainId ?? __classPrivateFieldGet(this, _TokensController_chainId, "f")]?.[__classPrivateFieldGet(this, _TokensController_instances, "m", _TokensController_getSelectedAddress).call(this)] || [];
57+
const checksummedTokenAddresses = tokenAddressesToIgnore.map((address) => {
58+
const checksumAddress = (0, controller_utils_1.toChecksumHexAddress)(address);
59+
ignoredTokensMap[address.toLowerCase()] = true;

ui/components/app/modals/hide-token-confirmation-modal/hide-token-confirmation-modal.test.js

+51
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import thunk from 'redux-thunk';
55
import * as actions from '../../../../store/actions';
66
import { renderWithProvider } from '../../../../../test/lib/render-helpers';
77
import mockState from '../../../../../test/data/mock-state.json';
8+
import { mockNetworkState } from '../../../../../test/stub/networks';
89
import HideTokenConfirmationModal from '.';
910

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

29+
const tokenState2 = {
30+
address: '0xTokenAddress2',
31+
symbol: 'TKN2',
32+
image: '',
33+
chainId: '0x89',
34+
};
35+
2836
const tokenModalState = {
2937
...mockState,
3038
appState: {
@@ -82,4 +90,47 @@ describe('Hide Token Confirmation Modal', () => {
8290
networkClientId: 'goerli',
8391
});
8492
});
93+
94+
it('should hide token from another chain', () => {
95+
const tokenModalStateWithDifferentChain = {
96+
...mockState,
97+
metamask: {
98+
...mockState.metamask,
99+
selectedNetworkClientId: 'bsc',
100+
...mockNetworkState({ chainId: '0x89', id: 'bsc' }),
101+
},
102+
appState: {
103+
...mockState.appState,
104+
modal: {
105+
modalState: {
106+
props: {
107+
history: {
108+
push: mockHistoryPush,
109+
},
110+
token: tokenState2,
111+
},
112+
},
113+
},
114+
},
115+
};
116+
117+
const mockStoreDifferentChain = configureMockStore([thunk])(
118+
tokenModalStateWithDifferentChain,
119+
);
120+
121+
const { queryByTestId } = renderWithProvider(
122+
<HideTokenConfirmationModal />,
123+
mockStoreDifferentChain,
124+
);
125+
126+
const hideButton = queryByTestId('hide-token-confirmation__hide');
127+
128+
fireEvent.click(hideButton);
129+
130+
expect(mockHideModal).toHaveBeenCalled();
131+
expect(actions.ignoreTokens).toHaveBeenCalledWith({
132+
tokensToIgnore: tokenState2.address,
133+
networkClientId: 'bsc',
134+
});
135+
});
85136
});

yarn.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -4975,7 +4975,7 @@ __metadata:
49754975

49764976
"@metamask/assets-controllers@patch:@metamask/assets-controllers@npm%3A45.1.0#~/.yarn/patches/@metamask-assets-controllers-npm-45.1.0-d914c453f0.patch":
49774977
version: 45.1.0
4978-
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"
4978+
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"
49794979
dependencies:
49804980
"@ethereumjs/util": "npm:^8.1.0"
49814981
"@ethersproject/abi": "npm:^5.7.0"
@@ -5008,7 +5008,7 @@ __metadata:
50085008
"@metamask/keyring-controller": ^19.0.0
50095009
"@metamask/network-controller": ^22.0.0
50105010
"@metamask/preferences-controller": ^15.0.0
5011-
checksum: 10/985ec7dffb75aaff8eea00f556157e42cd5db063cbfa94dfd4f070c5b9d98b1315f3680fa7370f4c734a1688598bbda9c44a7c33c342e1d123d6ee2edd6120fc
5011+
checksum: 10/d2f7d5bb07feceb5b972beda019f411cd073ece3ed682b21373fc6d4c06812ec10245b40c78ce6316c5fb1718278fd269b73e13d37c2ff07b5bb3ecdfd8278f7
50125012
languageName: node
50135013
linkType: hard
50145014

0 commit comments

Comments
 (0)