From 7e626461f0b2794065a4d417be723286aab808f6 Mon Sep 17 00:00:00 2001 From: Jaden Date: Tue, 28 Nov 2023 16:12:47 -0500 Subject: [PATCH] fix: fixing redirect from portfolio to home page on chain switch --- components/common/ChainToggle.tsx | 15 +++++---------- components/navbar/index.tsx | 5 ++--- context/ChainContextProvider.tsx | 14 ++------------ pages/portfolio/[[...address]].tsx | 2 +- 4 files changed, 10 insertions(+), 26 deletions(-) diff --git a/components/common/ChainToggle.tsx b/components/common/ChainToggle.tsx index 904b14540..b2277b103 100644 --- a/components/common/ChainToggle.tsx +++ b/components/common/ChainToggle.tsx @@ -102,12 +102,9 @@ const ChainToggle: FC = () => { key={supportedChain.id} css={{ py: '$3', px: '$1', display: 'flex', gap: '$2' }} onClick={() => { - const newUrl = router.asPath.replace( - chain.routePrefix, - supportedChain.routePrefix - ) + router.query.chain = supportedChain.routePrefix + router.push(router, undefined, { shallow: true }) - router.replace(newUrl, undefined, { scroll: false }) switchCurrentChain(supportedChain.id) }} > @@ -139,12 +136,10 @@ const ChainToggle: FC = () => { value={chainOption.name} disabled={chainOption.name === chain.name} onClick={() => { - const newUrl = router.asPath.replace( - chain.routePrefix, - chainOption.routePrefix - ) + router.query.chain = chainOption.routePrefix + router.push(router, undefined, { shallow: true }) + switchCurrentChain(chainOption.id) - router.replace(newUrl, undefined, { scroll: false }) }} > { const isMobile = useMediaQuery({ query: '(max-width: 960px' }) const isMounted = useMounted() const { routePrefix } = useMarketplaceChain() - const { address } = useAccount(); - + const { address } = useAccount() let searchRef = useRef(null) @@ -246,7 +245,7 @@ const Navbar = () => { {isConnected && ( - + Portfolio diff --git a/context/ChainContextProvider.tsx b/context/ChainContextProvider.tsx index c16b61493..eb84e5407 100644 --- a/context/ChainContextProvider.tsx +++ b/context/ChainContextProvider.tsx @@ -37,12 +37,8 @@ const ChainContextProvider: FC = ({ children }) => { } if (!router.query.chain && selectedChain) { - router.replace({ - query: { - ...router.query, - chain: selectedChain.routePrefix, - }, - }) + router.query.chain = selectedChain.routePrefix + router.push(router, undefined, { shallow: true }) } const id = selectedChain?.id || DefaultChain.id @@ -57,12 +53,6 @@ const ChainContextProvider: FC = ({ children }) => { } setGlobalChainId(+chainId) - router.replace({ - query: { - ...router.query, - chain: supportedChainsMap[+chainId].routePrefix, - }, - }) if (typeof window !== 'undefined') { localStorage.setItem('reservoir.chainId', `${chainId}`) diff --git a/pages/portfolio/[[...address]].tsx b/pages/portfolio/[[...address]].tsx index df95cca8f..b5efa9082 100644 --- a/pages/portfolio/[[...address]].tsx +++ b/pages/portfolio/[[...address]].tsx @@ -165,7 +165,7 @@ const IndexPage: NextPage = () => { router.query.tab = tabValue router.push(router, undefined, { shallow: true }) } - }, [tabValue]) + }, [tabValue, router]) if (!isMounted) { return null