From 99afec239e98712d67ad1d552f1a8ef13fca65cb Mon Sep 17 00:00:00 2001 From: Diogo Ferreira Date: Wed, 18 Dec 2024 17:40:13 +0700 Subject: [PATCH] hot fix: don't reset chainId to default network (arbitrum) if chain is set --- packages/app/contexts/NetworkContext.tsx | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/app/contexts/NetworkContext.tsx b/packages/app/contexts/NetworkContext.tsx index c5f4a0a9..a58fa0fe 100644 --- a/packages/app/contexts/NetworkContext.tsx +++ b/packages/app/contexts/NetworkContext.tsx @@ -43,6 +43,8 @@ interface NetworkContextProviderProps { children: ReactNode; } +const INVALID_CHAIN_ID = 0; + export const NetworkContextProvider = ({ children, }: NetworkContextProviderProps) => { @@ -90,7 +92,8 @@ export const NetworkContextProvider = ({ useEffect(() => { const parsedSearchParamsChainId = searchParamsChainId ? parseInt(searchParamsChainId) - : 0; + : INVALID_CHAIN_ID; + const newChainIsDiferentFromCurrent = parsedSearchParamsChainId !== chain?.id; @@ -116,9 +119,14 @@ export const NetworkContextProvider = ({ } } } - // set default chain - setSelectedChain(arbitrum); - setSelectedChainId(arbitrum.id); + + const chainIsNotSet = !chain?.id; + + if (!isValidSearchParamsChainId && chainIsNotSet) { + // set default chain + setSelectedChain(arbitrum); + setSelectedChainId(arbitrum.id); + } // eslint-disable-next-line react-hooks/exhaustive-deps }, [isConnected, chains, searchParamsChainId, switchChain]);