From 2289e47e879da1bfb8b40b64f68bb994a69b415c Mon Sep 17 00:00:00 2001 From: Erik Marks <25517051+rekmarks@users.noreply.github.com> Date: Mon, 10 May 2021 15:29:07 -0700 Subject: [PATCH] Update switchEthereumChain unrecognized chain error (#11030) --- .../handlers/switch-ethereum-chain.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/scripts/lib/rpc-method-middleware/handlers/switch-ethereum-chain.js b/app/scripts/lib/rpc-method-middleware/handlers/switch-ethereum-chain.js index b52deb232..97b5d0f3c 100644 --- a/app/scripts/lib/rpc-method-middleware/handlers/switch-ethereum-chain.js +++ b/app/scripts/lib/rpc-method-middleware/handlers/switch-ethereum-chain.js @@ -63,7 +63,7 @@ async function switchEthereumChainHandler( const existingNetwork = findCustomRpcBy({ chainId: _chainId }); - if (existingNetwork !== null) { + if (existingNetwork) { const currentChainId = getCurrentChainId(); if (currentChainId === _chainId) { res.result = null; @@ -88,5 +88,10 @@ async function switchEthereumChainHandler( } return end(); } - return end(ethErrors.provider.userRejectedRequest()); + return end( + ethErrors.provider.custom({ + code: 4902, // To-be-standardized "unrecognized chain ID" error + message: `Unrecognized chain ID "${chainId}". Try adding the chain using ${MESSAGE_TYPE.ADD_ETHEREUM_CHAIN} first.`, + }), + ); }