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
This commit is contained in:
Tina 2022-01-26 10:03:48 -08:00 committed by GitHub
parent d1e0812684
commit 779625a04e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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) {