Skip to content

Commit

Permalink
fix: chain parameter should be able to switch chains on initial load (#…
Browse files Browse the repository at this point in the history
…3180)

* fix switch network on load

* dont run useeffect when chainId isnt defined yet

* remove newline
  • Loading branch information
tinaszheng authored Jan 26, 2022
1 parent d1e0812 commit 779625a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/components/Header/NetworkSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 779625a

Please sign in to comment.