diff --git a/src/custom/pages/Swap/SwapMod.tsx b/src/custom/pages/Swap/SwapMod.tsx index 7037f9c628..b93b2182ab 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.replace(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) { 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 }