From 8c048fb0467393431e75965a2d21ae11dbee4736 Mon Sep 17 00:00:00 2001 From: nenadV91 Date: Thu, 7 Apr 2022 14:38:40 +0200 Subject: [PATCH 1/2] Clear url params on the network change --- src/custom/pages/Swap/SwapMod.tsx | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/custom/pages/Swap/SwapMod.tsx b/src/custom/pages/Swap/SwapMod.tsx index 7037f9c628..417ce8bfc4 100644 --- a/src/custom/pages/Swap/SwapMod.tsx +++ b/src/custom/pages/Swap/SwapMod.tsx @@ -107,6 +107,7 @@ import CowSubsidyModal from 'components/CowSubsidyModal' export default function Swap({ history, + location, TradeBasicDetails, EthWethWrapMessage, SwitchToWethBtn, @@ -124,6 +125,7 @@ export default function Swap({ const { account, chainId } = useActiveWeb3React() const { isSupportedWallet } = useWalletInfo() const loadedUrlParams = useDefaultsFromURLSearch() + const previousChainId = usePrevious(chainId) // token warning stuff const [loadedInputCurrency, loadedOutputCurrency] = [ @@ -373,6 +375,13 @@ export default function Swap({ // check if user has gone through approval process, used to show two step buttons, reset on token change const [approvalSubmitted, setApprovalSubmitted] = useState(false) + // reset url query on network change + useEffect(() => { + if (chainId && previousChainId && chainId !== previousChainId) { + history.push(location.pathname) + } + }, [chainId, history, location.pathname, previousChainId]) + // mark when a user has submitted an approval, reset onTokenSelection for input field useEffect(() => { if (approvalState === ApprovalState.PENDING) { From eb3cbab665cf791f2904d910f564e7a94691a907 Mon Sep 17 00:00:00 2001 From: nenadV91 Date: Thu, 7 Apr 2022 17:59:08 +0200 Subject: [PATCH 2/2] Fix for missing default token --- src/custom/pages/Swap/SwapMod.tsx | 2 +- src/custom/state/swap/hooks.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/custom/pages/Swap/SwapMod.tsx b/src/custom/pages/Swap/SwapMod.tsx index 417ce8bfc4..b93b2182ab 100644 --- a/src/custom/pages/Swap/SwapMod.tsx +++ b/src/custom/pages/Swap/SwapMod.tsx @@ -378,7 +378,7 @@ export default function Swap({ // reset url query on network change useEffect(() => { if (chainId && previousChainId && chainId !== previousChainId) { - history.push(location.pathname) + history.replace(location.pathname) } }, [chainId, history, location.pathname, previousChainId]) diff --git a/src/custom/state/swap/hooks.ts b/src/custom/state/swap/hooks.ts index 7190b421fa..1ac3b93e95 100644 --- a/src/custom/state/swap/hooks.ts +++ b/src/custom/state/swap/hooks.ts @@ -465,7 +465,7 @@ export function useDefaultsFromURLSearch(): DefaultFromUrlSearch { setResult({ inputCurrencyId, outputCurrencyId }) // eslint-disable-next-line react-hooks/exhaustive-deps - }, [chainId]) + }, [chainId, parsedQs]) return result }