From b989ce76fa2619ed1a27e163f500dda3d69770c0 Mon Sep 17 00:00:00 2001 From: Connor Barr Date: Tue, 10 Dec 2024 10:50:16 +0000 Subject: [PATCH] fix: add early exit to useEffect hook for price adjustment --- .../web/components/place-limit-tool/index.tsx | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/packages/web/components/place-limit-tool/index.tsx b/packages/web/components/place-limit-tool/index.tsx index 32c58b3c4d..e92d202507 100644 --- a/packages/web/components/place-limit-tool/index.tsx +++ b/packages/web/components/place-limit-tool/index.tsx @@ -290,19 +290,18 @@ export const PlaceLimitTool: FunctionComponent = observer( ? swapState.marketState.inAmountInput.setAmount : swapState.marketState.outAmountInput.setAmount; - setQuoteType( - !isMarketOutAmount || !featureFlags.inGivenOut - ? "out-given-in" - : "in-given-out" - ); - // If value is empty clear values - if (!value?.trim()) { + if (!value || value.trim().length === 0) { if (type === "market") { setMarketAmount(""); setOppositeMarketAmount(""); } - return update(""); + + if (fiatAmount.length > 0 || tokenAmount.length > 0) { + return update(""); + } + + return; } const updatedValue = transformAmount( @@ -329,6 +328,21 @@ export const PlaceLimitTool: FunctionComponent = observer( const formattedValue = !isFocused ? trimPlaceholderZeros(updatedValue) : updatedValue; + + if (amountType === "fiat" && fiatAmount === formattedValue) { + return; + } + + if (amountType === "token" && tokenAmount === formattedValue) { + return; + } + + setQuoteType( + !isMarketOutAmount || !featureFlags.inGivenOut + ? "out-given-in" + : "in-given-out" + ); + update(formattedValue); }, [ @@ -341,6 +355,8 @@ export const PlaceLimitTool: FunctionComponent = observer( type, resetSlippage, featureFlags.inGivenOut, + fiatAmount, + tokenAmount, ] ); @@ -352,7 +368,6 @@ export const PlaceLimitTool: FunctionComponent = observer( type === "market" ) return; - const value = tokenAmount.length > 0 ? new Dec(tokenAmount) : undefined; const fiatValue = value ? swapState.priceState.price.mul(value)