From 6dd5a0c946e9102e997e470b68f247686de79eff Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 12 Jun 2024 13:56:17 -0500 Subject: [PATCH] fix issue where user rejected request errors are not correctly handled in either wallet_switchEthereumChain nor wallet_addEthereumChain calls --- .../handlers/ethereum-chain-utils.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) 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 38e35897d53f..8b10cbb9cd6f 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 @@ -230,11 +230,19 @@ export async function switchChain( await setActiveNetwork(networkClientId); res.result = null; } catch (error) { - return end( - error.code === errorCodes.provider.userRejectedRequest - ? undefined - : error, - ); + // We don't want to return an error if user rejects the request + // and this is a chained switch request after wallet_addEthereumChain. + // approvalFlowId is only defined when this call is of a + // wallet_addEthereumChain request so we can use it to determine + // if we should return an error + if ( + error.code === errorCodes.provider.userRejectedRequest && + approvalFlowId + ) { + res.result = null; + return end(); + } + return end(error); } finally { if (approvalFlowId) { endApprovalFlow({ id: approvalFlowId });