From 779625a04e949f377c96e6dc557f28a0010e39d6 Mon Sep 17 00:00:00 2001 From: Tina <59578595+tinaszheng@users.noreply.github.com> Date: Wed, 26 Jan 2022 10:03:48 -0800 Subject: [PATCH] fix: chain parameter should be able to switch chains on initial load (#3180) * fix switch network on load * dont run useeffect when chainId isnt defined yet * remove newline --- src/components/Header/NetworkSelector.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/Header/NetworkSelector.tsx b/src/components/Header/NetworkSelector.tsx index 40d1d9b39b..eabe53aaad 100644 --- a/src/components/Header/NetworkSelector.tsx +++ b/src/components/Header/NetworkSelector.tsx @@ -282,8 +282,10 @@ export default function NetworkSelector() { ) useEffect(() => { + if (!chainId || !prevChainId) return + // when network change originates from wallet or dropdown selector, just update URL - if (chainId && chainId !== prevChainId) { + if (chainId !== prevChainId) { history.replace({ search: replaceURLParam(history.location.search, 'chain', getChainNameFromId(chainId)) }) // otherwise assume network change originates from URL } else if (urlChainId && urlChainId !== chainId) {