Commit afe30a2c authored by vignesh mohankumar's avatar vignesh mohankumar Committed by GitHub

fix: reset Widget amount on URL change (#4668)

* fix: reset Widget amount on URL change

* empty
parent 2f9289a2
...@@ -2,13 +2,15 @@ import { Currency, Field, SwapController, SwapEventHandlers, TradeType } from '@ ...@@ -2,13 +2,15 @@ import { Currency, Field, SwapController, SwapEventHandlers, TradeType } from '@
import CurrencySearchModal from 'components/SearchModal/CurrencySearchModal' import CurrencySearchModal from 'components/SearchModal/CurrencySearchModal'
import { useCallback, useEffect, useMemo, useState } from 'react' import { useCallback, useEffect, useMemo, useState } from 'react'
const EMPTY_AMOUNT = ''
/** /**
* Integrates the Widget's inputs. * Integrates the Widget's inputs.
* Treats the Widget as a controlled component, using the app's own token selector for selection. * Treats the Widget as a controlled component, using the app's own token selector for selection.
*/ */
export function useSyncWidgetInputs(defaultToken?: Currency) { export function useSyncWidgetInputs(defaultToken?: Currency) {
const [type, setType] = useState(TradeType.EXACT_INPUT) const [type, setType] = useState(TradeType.EXACT_INPUT)
const [amount, setAmount] = useState('') const [amount, setAmount] = useState(EMPTY_AMOUNT)
const onAmountChange = useCallback((field: Field, amount: string) => { const onAmountChange = useCallback((field: Field, amount: string) => {
setType(toTradeType(field)) setType(toTradeType(field))
setAmount(amount) setAmount(amount)
...@@ -22,6 +24,7 @@ export function useSyncWidgetInputs(defaultToken?: Currency) { ...@@ -22,6 +24,7 @@ export function useSyncWidgetInputs(defaultToken?: Currency) {
setTokens({ setTokens({
[Field.OUTPUT]: defaultToken, [Field.OUTPUT]: defaultToken,
}) })
setAmount(EMPTY_AMOUNT)
}, [defaultToken]) }, [defaultToken])
const onSwitchTokens = useCallback(() => { const onSwitchTokens = useCallback(() => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment