Skip to content
This repository has been archived by the owner on Jan 15, 2021. It is now read-only.

Resetting prices when token selection changes #1255

Merged
merged 1 commit into from
Jul 23, 2020
Merged
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
13 changes: 11 additions & 2 deletions src/components/TradeWidget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -669,10 +669,17 @@ const TradeWidget: React.FC = () => {

const { placeOrder, placeMultipleOrders, isSubmitting, setIsSubmitting } = usePlaceOrder()

const resetPrices = useCallback((): void => {
setValue(priceInputId, '0')
setValue(priceInverseInputId, '0')
}, [setValue])

const swapTokens = useCallback((): void => {
setSellToken(receiveTokenBalance)
setReceiveToken(sellTokenBalance)
}, [receiveTokenBalance, sellTokenBalance])
// selected price no longer has meaning, reset and force user pick/insert new one
resetPrices()
}, [receiveTokenBalance, resetPrices, sellTokenBalance])

const onSelectChangeFactory = useCallback(
(
Expand All @@ -684,10 +691,12 @@ const TradeWidget: React.FC = () => {
swapTokens()
} else {
setToken(selected)
// selected price no longer has meaning, reset and force user pick/insert new one
resetPrices()
}
}
},
[swapTokens],
[swapTokens, resetPrices],
)

const sameToken = sellToken === receiveToken
Expand Down