Skip to content

Commit 11a3678

Browse files
fix: (cp-7.46.0) network switcher - use additional checks for non-evm networks (#15283)
## **Description** I have not been able to replicate this [bug](#15272), but this is some additional checks to ensure we are correctly checking against EVM networks and ignore non-EVM networks. We already added checks into main from #15184 ^ However this targets `@metamask/multichain-network-controller@^0.4.0`, whereas the RC uses `0.3.0` ## **Related issues** Fixes: #15272 ## **Manual testing steps** N/A, I still haven't figured out how to repro this. 1. Go to this page... 2. 3. ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --------- Co-authored-by: Nico MASSART <NicolasMassart@users.noreply.github.com>
1 parent 60820d8 commit 11a3678

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import React from 'react';
2+
import { backgroundState } from '../../../../../../util/test/initial-root-state';
3+
import renderWithProvider from '../../../../../../util/test/renderWithProvider';
4+
import CustomNetwork from './CustomNetwork';
5+
import { CustomNetworkProps } from './CustomNetwork.types';
6+
import { PopularList } from '../../../../../../util/networks/customNetworks';
7+
8+
const getMockState = () => ({ engine: { backgroundState } });
9+
10+
jest.mock('@react-navigation/native', () => {
11+
const actualNav = jest.requireActual('@react-navigation/native');
12+
return {
13+
...actualNav,
14+
useNavigation: () => ({
15+
navigate: jest.fn(),
16+
}),
17+
};
18+
});
19+
20+
describe('CustomNetwork component', () => {
21+
const getMockCustomNetworkProps = (
22+
overrides?: Partial<CustomNetworkProps>,
23+
) => {
24+
const mockCloseNetworkModal = jest.fn();
25+
const mockShowNetworkModal = jest.fn();
26+
const mockCustomNetworkProps: CustomNetworkProps = {
27+
showPopularNetworkModal: false,
28+
isNetworkModalVisible: false,
29+
closeNetworkModal: mockCloseNetworkModal,
30+
selectedNetwork: {
31+
chainId: '0x1',
32+
nickname: 'Ethereum Mainnet',
33+
rpcUrl: 'https://mainnet.infura.io/v3/your-api-key',
34+
ticker: 'ETH',
35+
rpcPrefs: {
36+
blockExplorerUrl: 'https://etherscan.io',
37+
},
38+
},
39+
showNetworkModal: mockShowNetworkModal,
40+
shouldNetworkSwitchPopToWallet: false,
41+
...overrides,
42+
};
43+
return mockCustomNetworkProps;
44+
};
45+
46+
it('filters out CAIP-2 networks when showing all networks (included added networks)', () => {
47+
const props = getMockCustomNetworkProps({ showAddedNetworks: true });
48+
const mockState = getMockState();
49+
const { getByText, queryByText } = renderWithProvider(
50+
<CustomNetwork {...props} />,
51+
{
52+
state: mockState,
53+
},
54+
);
55+
56+
const additionalNetworksVisible = PopularList.map((p) => p.nickname);
57+
additionalNetworksVisible.forEach((name) => {
58+
expect(getByText(name)).toBeOnTheScreen();
59+
});
60+
61+
Object.values(
62+
Object.values(
63+
mockState.engine.backgroundState.MultichainNetworkController
64+
.multichainNetworkConfigurationsByChainId,
65+
),
66+
).forEach((n) => {
67+
expect(queryByText(n.name)).not.toBeOnTheScreen();
68+
});
69+
});
70+
});

app/components/Views/Settings/NetworksSettings/NetworkSettings/CustomNetworkView/CustomNetwork.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ const CustomNetwork = ({
5151
) => {
5252
if (
5353
isNonEvmChainId(networkConfiguration.chainId) ||
54-
isNonEvmChainId(savedNetwork.chainId)
54+
isNonEvmChainId(savedNetwork.chainId) ||
55+
('isEvm' in savedNetwork && savedNetwork.isEvm === false)
5556
) {
5657
return false;
5758
}

0 commit comments

Comments
 (0)