diff --git a/app/scripts/lib/rpc-method-middleware/handlers/add-ethereum-chain.test.js b/app/scripts/lib/rpc-method-middleware/handlers/add-ethereum-chain.test.js index 20fbde395134..0e93bd67623e 100644 --- a/app/scripts/lib/rpc-method-middleware/handlers/add-ethereum-chain.test.js +++ b/app/scripts/lib/rpc-method-middleware/handlers/add-ethereum-chain.test.js @@ -120,6 +120,35 @@ describe('addEthereumChainHandler', () => { expect(mocks.setActiveNetwork).toHaveBeenCalledWith(123); }); + it('creates a new networkConfiguration when called without "blockExplorerUrls" property', async () => { + const mocks = makeMocks({ + permissionsFeatureFlagIsActive: false, + }); + await addEthereumChainHandler( + { + origin: 'example.com', + params: [ + { + chainId: CHAIN_IDS.OPTIMISM, + chainName: 'Optimism Mainnet', + rpcUrls: ['https://optimism.llamarpc.com'], + nativeCurrency: { + symbol: 'ETH', + decimals: 18, + }, + iconUrls: ['https://optimism.icon.com'], + }, + ], + }, + {}, + jest.fn(), + jest.fn(), + mocks, + ); + expect(mocks.upsertNetworkConfiguration).toHaveBeenCalledTimes(1); + expect(mocks.setActiveNetwork).toHaveBeenCalledTimes(1); + }); + describe('if a networkConfiguration for the given chainId already exists', () => { it('creates a new network configuration for the given chainid and switches to it if proposed networkConfiguration has a different rpcUrl from all existing networkConfigurations', async () => { const mocks = makeMocks({ diff --git a/app/scripts/lib/rpc-method-middleware/handlers/ethereum-chain-utils.js b/app/scripts/lib/rpc-method-middleware/handlers/ethereum-chain-utils.js index 8b10cbb9cd6f..80408d0f6e03 100644 --- a/app/scripts/lib/rpc-method-middleware/handlers/ethereum-chain-utils.js +++ b/app/scripts/lib/rpc-method-middleware/handlers/ethereum-chain-utils.js @@ -119,12 +119,11 @@ export function validateAddEthereumChainParams(params, end) { }; const firstValidRPCUrl = rpcUrls.find((rpcUrl) => isLocalhostOrHttps(rpcUrl)); - const firstValidBlockExplorerUrl = - blockExplorerUrls !== null && Array.isArray(blockExplorerUrls) - ? blockExplorerUrls.find((blockExplorerUrl) => - isLocalhostOrHttps(blockExplorerUrl), - ) - : null; + const firstValidBlockExplorerUrl = Array.isArray(blockExplorerUrls) + ? blockExplorerUrls.find((blockExplorerUrl) => + isLocalhostOrHttps(blockExplorerUrl), + ) + : null; if (!firstValidRPCUrl) { throw ethErrors.rpc.invalidParams({ @@ -132,12 +131,6 @@ export function validateAddEthereumChainParams(params, end) { }); } - if (blockExplorerUrls !== null && !firstValidBlockExplorerUrl) { - throw ethErrors.rpc.invalidParams({ - message: `Expected null or array with at least one valid string HTTPS URL 'blockExplorerUrl'. Received: ${blockExplorerUrls}`, - }); - } - if (typeof chainName !== 'string' || !chainName) { throw ethErrors.rpc.invalidParams({ message: `Expected non-empty string 'chainName'. Received:\n${chainName}`,