From 4faa3e6022fb2c09e8792c9a00b0771548d2a58a Mon Sep 17 00:00:00 2001 From: AI Date: Sat, 11 Jul 2026 20:09:23 +0530 Subject: [PATCH] Fix MetaMask mobile switch network error code 4902 bug --- src/components/layout/unexpected_chain.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/components/layout/unexpected_chain.tsx b/src/components/layout/unexpected_chain.tsx index 3bae8408..15cf16b0 100644 --- a/src/components/layout/unexpected_chain.tsx +++ b/src/components/layout/unexpected_chain.tsx @@ -22,9 +22,14 @@ export default function UnexpectedChain() { method: 'wallet_switchEthereumChain', params: [{ chainId: toHexString(chainId ?? '0') }], }); - } catch(switchError) { - // @ts-ignore - if (allowAutoAdd && switchError.code === 4902) { + } catch(switchError: any) { + const isMissingChainError = + switchError.code === 4902 || + switchError?.data?.originalError?.code === 4902 || + switchError?.info?.error?.code === 4902 || + switchError?.message?.includes('Unrecognized chain ID'); + + if (allowAutoAdd && isMissingChainError) { addNetwork(); } }