diff --git a/ui/components/multichain/network-list-menu/network-list-menu.js b/ui/components/multichain/network-list-menu/network-list-menu.js index 9fd49b9bd..baf7e851e 100644 --- a/ui/components/multichain/network-list-menu/network-list-menu.js +++ b/ui/components/multichain/network-list-menu/network-list-menu.js @@ -12,7 +12,7 @@ import { setProviderType, toggleNetworkMenu, } from '../../../store/actions'; -import { CHAIN_IDS, TEST_CHAINS } from '../../../../shared/constants/network'; +import { TEST_CHAINS } from '../../../../shared/constants/network'; import { getShowTestNetworks, getCurrentChainId, @@ -52,12 +52,6 @@ import { isLineaMainnetNetworkReleased, } from '../../../ducks/metamask/metamask'; -const UNREMOVABLE_CHAIN_IDS = [ - CHAIN_IDS.MAINNET, - CHAIN_IDS.LINEA_MAINNET, - ...TEST_CHAINS, -]; - export const NetworkListMenu = ({ onClose }) => { const t = useI18nContext(); @@ -117,9 +111,7 @@ export const NetworkListMenu = ({ onClose }) => { } const isCurrentNetwork = currentNetwork.id === network.id; - - const canDeleteNetwork = - !isCurrentNetwork && !UNREMOVABLE_CHAIN_IDS.includes(network.chainId); + const canDeleteNetwork = !isCurrentNetwork && network.removable; return ( chainId === CHAIN_IDS.LOCALHOST, - ), + ...Object.values(networkConfigurations) + .filter(({ chainId }) => chainId === CHAIN_IDS.LOCALHOST) + .map((network) => ({ ...network, removable: true })), ]; } @@ -1253,6 +1256,7 @@ export function getNonTestNetworks(state) { providerType: NETWORK_TYPES.MAINNET, ticker: CURRENCY_SYMBOLS.ETH, id: NETWORK_TYPES.MAINNET, + removable: false, }, { chainId: CHAIN_IDS.LINEA_MAINNET, @@ -1264,11 +1268,12 @@ export function getNonTestNetworks(state) { providerType: NETWORK_TYPES.LINEA_MAINNET, ticker: TEST_NETWORK_TICKER_MAP[NETWORK_TYPES.LINEA_MAINNET], id: NETWORK_TYPES.LINEA_MAINNET, + removable: false, }, // Custom networks added by the user - ...Object.values(networkConfigurations).filter( - ({ chainId }) => ![CHAIN_IDS.LOCALHOST].includes(chainId), - ), + ...Object.values(networkConfigurations) + .filter(({ chainId }) => ![CHAIN_IDS.LOCALHOST].includes(chainId)) + .map((network) => ({ ...network, removable: true })), ]; } diff --git a/ui/selectors/selectors.test.js b/ui/selectors/selectors.test.js index e63252ee7..307cbde92 100644 --- a/ui/selectors/selectors.test.js +++ b/ui/selectors/selectors.test.js @@ -4,6 +4,7 @@ import { KeyringType } from '../../shared/constants/keyring'; import { CHAIN_IDS, LOCALHOST_DISPLAY_NAME, + NETWORK_TYPES, } from '../../shared/constants/network'; import * as selectors from './selectors'; @@ -314,6 +315,33 @@ describe('Selectors', () => { const lastItem = networks.pop(); expect(lastItem.nickname.toLowerCase()).toContain('localhost'); }); + + it('properly assigns a network as removable', () => { + const networks = selectors.getAllNetworks({ + metamask: { + preferences: { + showTestNetworks: true, + }, + networkConfigurations: { + 'some-config-name': { + chainId: CHAIN_IDS.LOCALHOST, + nickname: LOCALHOST_DISPLAY_NAME, + id: 'some-config-name', + }, + }, + }, + }); + + const mainnet = networks.find( + (network) => network.id === NETWORK_TYPES.MAINNET, + ); + expect(mainnet.removable).toBe(false); + + const customNetwork = networks.find( + (network) => network.id === 'some-config-name', + ); + expect(customNetwork.removable).toBe(true); + }); }); describe('#getCurrentNetwork', () => {