Commit 3a94a992 authored by Zach Pomerantz's avatar Zach Pomerantz Committed by GitHub

fix: debouncing as a loading state (#7183)

fix: consider debouncing as loading state
parent e893bc26
...@@ -65,13 +65,16 @@ export function useDebouncedTrade( ...@@ -65,13 +65,16 @@ export function useDebouncedTrade(
const autoRouterSupported = useAutoRouterSupported() const autoRouterSupported = useAutoRouterSupported()
const isWindowVisible = useIsWindowVisible() const isWindowVisible = useIsWindowVisible()
const debouncedSwapQuoteFlagEnabled = useDebounceSwapQuoteFlag() === DebounceSwapQuoteVariant.Enabled const inputs = useMemo<[CurrencyAmount<Currency> | undefined, Currency | undefined]>(
const [debouncedAmount, debouncedOtherCurrency] = useDebounce( () => [amountSpecified, otherCurrency],
useMemo(() => [amountSpecified, otherCurrency], [amountSpecified, otherCurrency]), [amountSpecified, otherCurrency]
debouncedSwapQuoteFlagEnabled ? DEBOUNCE_TIME_INCREASED : DEBOUNCE_TIME
) )
const debouncedSwapQuoteFlagEnabled = useDebounceSwapQuoteFlag() === DebounceSwapQuoteVariant.Enabled
const debouncedInputs = useDebounce(inputs, debouncedSwapQuoteFlagEnabled ? DEBOUNCE_TIME_INCREASED : DEBOUNCE_TIME)
const isDebouncing = debouncedInputs !== inputs
const [debouncedAmount, debouncedOtherCurrency] = debouncedInputs
const isAWrapTransaction = useMemo(() => { const isWrap = useMemo(() => {
if (!chainId || !amountSpecified || !debouncedOtherCurrency) return false if (!chainId || !amountSpecified || !debouncedOtherCurrency) return false
const weth = WRAPPED_NATIVE_CURRENCY[chainId] const weth = WRAPPED_NATIVE_CURRENCY[chainId]
return ( return (
...@@ -80,7 +83,7 @@ export function useDebouncedTrade( ...@@ -80,7 +83,7 @@ export function useDebouncedTrade(
) )
}, [amountSpecified, chainId, debouncedOtherCurrency]) }, [amountSpecified, chainId, debouncedOtherCurrency])
const shouldGetTrade = !isAWrapTransaction && isWindowVisible const shouldGetTrade = !isWrap && isWindowVisible
const [routerPreference] = useRouterPreference() const [routerPreference] = useRouterPreference()
const routingAPITrade = useRoutingAPITrade( const routingAPITrade = useRoutingAPITrade(
...@@ -92,9 +95,8 @@ export function useDebouncedTrade( ...@@ -92,9 +95,8 @@ export function useDebouncedTrade(
account account
) )
const inDebounce = // If the user is debouncing, we want to show the loading state until the debounce is complete.
(!debouncedAmount && Boolean(amountSpecified)) || (!debouncedOtherCurrency && Boolean(otherCurrency)) const isLoading = (routingAPITrade.state === TradeState.LOADING || isDebouncing) && !isWrap
const isLoading = routingAPITrade.state === TradeState.LOADING || inDebounce
return useMemo( return useMemo(
() => ({ () => ({
......
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