From 8a2b79d7fc8348113f24a1888c661c01ceeb0b34 Mon Sep 17 00:00:00 2001 From: Murat Akdeniz Date: Mon, 30 Mar 2026 16:53:56 -0700 Subject: [PATCH] Optimize swap quoting debounce timings for faster UX MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reduce artificial delays in the input → validated quote pipeline. The 1.5s barter debounce was unnecessary since it fires after the quote RPC already absorbed typing latency. The 1.5s minimum display timer forced users to wait even when results were ready instantly. - Barter validation debounce: 1500ms → 300ms - Min "Calculating..." display: 1500ms → 500ms - Quote fetch debounce: 500ms → 300ms Expected improvement: ~2s faster quote display after user stops typing. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/hooks/use-barter-validation.ts | 2 +- src/hooks/use-swap-form.ts | 2 +- src/hooks/use-swap-quote.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/hooks/use-barter-validation.ts b/src/hooks/use-barter-validation.ts index aec74abf..fac231b6 100644 --- a/src/hooks/use-barter-validation.ts +++ b/src/hooks/use-barter-validation.ts @@ -6,7 +6,7 @@ import { fetchBarterRoute } from "@/lib/barter-api" import { ZERO_ADDRESS, WETH_ADDRESS } from "@/lib/swap-constants" import type { Token } from "@/types/swap" -const DEBOUNCE_MS = 1500 +const DEBOUNCE_MS = 300 const MAX_SLIPPAGE_PCT = 2.0 interface UseBarterValidationParams { diff --git a/src/hooks/use-swap-form.ts b/src/hooks/use-swap-form.ts index 9cac9598..03fbab0a 100644 --- a/src/hooks/use-swap-form.ts +++ b/src/hooks/use-swap-form.ts @@ -278,7 +278,7 @@ export function useSwapForm(allTokens: Token[]) { // --- Minimum "Calculating..." display time --- // The combined validating signal (quote loading OR barter validating) must stay true // for at least 1.5s to prevent the swap button text from flickering. - const MIN_VALIDATING_DISPLAY_MS = 1500 + const MIN_VALIDATING_DISPLAY_MS = 500 const rawValidating = isBarterValidating || (isQuoteLoading && !isWrapUnwrap) const [debouncedValidating, setDebouncedValidating] = useState(false) const validatingSinceRef = useRef(0) diff --git a/src/hooks/use-swap-quote.ts b/src/hooks/use-swap-quote.ts index 5b324449..80da5261 100644 --- a/src/hooks/use-swap-quote.ts +++ b/src/hooks/use-swap-quote.ts @@ -399,7 +399,7 @@ export function useQuote({ amountIn, slippage, enabled = true, - debounceMs = 500, + debounceMs = 300, tradeType = "exactIn", tokenList = [], }: UseQuoteProps): UseQuoteReturn {