fix: respond to updated amounts immediately (#3289)

This commit is contained in:
Zach Pomerantz 2022-02-10 19:35:34 -08:00 committed by GitHub
parent 8404c6076c
commit 636abe3b7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 7 deletions

@ -40,10 +40,6 @@ export default function Toolbar({ disabled }: { disabled?: boolean }) {
return <Caption.UnsupportedNetwork />
}
if (balance && trade?.inputAmount.greaterThan(balance)) {
return <Caption.InsufficientBalance currency={trade.inputAmount.currency} />
}
if (inputCurrency && outputCurrency && isAmountPopulated) {
if (!trade || routeIsLoading) {
return <Caption.LoadingTrade />
@ -51,6 +47,9 @@ export default function Toolbar({ disabled }: { disabled?: boolean }) {
if (!routeFound) {
return <Caption.InsufficientLiquidity />
}
if (balance && trade?.inputAmount.greaterThan(balance)) {
return <Caption.InsufficientBalance currency={trade.inputAmount.currency} />
}
if (trade.inputAmount && trade.outputAmount) {
return <Caption.Trade trade={trade} />
}

@ -57,6 +57,8 @@ function useComputeSwapInfo(): SwapInfo {
() => tryParseCurrencyAmount(amount, (isExactIn ? inputCurrency : outputCurrency) ?? undefined),
[inputCurrency, isExactIn, outputCurrency, amount]
)
const parsedAmountIn = isExactIn ? parsedAmount : undefined
const parsedAmountOut = isExactIn ? undefined : parsedAmount
//@TODO(ianlapham): this would eventually be replaced with routing api logic.
const trade = useBestTrade(
@ -83,10 +85,10 @@ function useComputeSwapInfo(): SwapInfo {
const currencyAmounts = useMemo(
() => ({
[Field.INPUT]: trade.trade?.inputAmount,
[Field.OUTPUT]: trade.trade?.outputAmount,
[Field.INPUT]: parsedAmountIn || trade.trade?.inputAmount,
[Field.OUTPUT]: parsedAmountOut || trade.trade?.outputAmount,
}),
[trade.trade?.inputAmount, trade.trade?.outputAmount]
[parsedAmountIn, parsedAmountOut, trade.trade?.inputAmount, trade.trade?.outputAmount]
)
const allowedSlippage = useAllowedSlippage(trade.trade)