Skip to content

Commit

Permalink
Clear url params on the network change (#397)
Browse files Browse the repository at this point in the history
* Clear url params on the network change

* Fix for missing default token
  • Loading branch information
nenadV91 authored Apr 8, 2022
1 parent 09084d8 commit 736db8d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/custom/pages/Swap/SwapMod.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ import CowSubsidyModal from 'components/CowSubsidyModal'

export default function Swap({
history,
location,
TradeBasicDetails,
EthWethWrapMessage,
SwitchToWethBtn,
Expand All @@ -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] = [
Expand Down Expand Up @@ -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<boolean>(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) {
Expand Down
2 changes: 1 addition & 1 deletion src/custom/state/swap/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ export function useDefaultsFromURLSearch(): DefaultFromUrlSearch {

setResult({ inputCurrencyId, outputCurrencyId })
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [chainId])
}, [chainId, parsedQs])

return result
}
Expand Down

0 comments on commit 736db8d

Please sign in to comment.