Skip to content

Commit

Permalink
fix issue where user rejected request errors are not correctly handle…
Browse files Browse the repository at this point in the history
…d in either wallet_switchEthereumChain nor wallet_addEthereumChain calls
  • Loading branch information
adonesky1 committed Jun 12, 2024
1 parent e407384 commit 6dd5a0c
Showing 1 changed file with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down

0 comments on commit 6dd5a0c

Please sign in to comment.