Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear url params on the network change #397

Merged
merged 2 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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