Skip to content

Commit

Permalink
fix: add early exit to useEffect hook for price adjustment
Browse files Browse the repository at this point in the history
  • Loading branch information
crnbarr93 committed Dec 10, 2024
1 parent 0b3f55a commit b989ce7
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions packages/web/components/place-limit-tool/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -290,19 +290,18 @@ export const PlaceLimitTool: FunctionComponent<PlaceLimitToolProps> = 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(
Expand All @@ -329,6 +328,21 @@ export const PlaceLimitTool: FunctionComponent<PlaceLimitToolProps> = 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);
},
[
Expand All @@ -341,6 +355,8 @@ export const PlaceLimitTool: FunctionComponent<PlaceLimitToolProps> = observer(
type,
resetSlippage,
featureFlags.inGivenOut,
fiatAmount,
tokenAmount,
]
);

Expand All @@ -352,7 +368,6 @@ export const PlaceLimitTool: FunctionComponent<PlaceLimitToolProps> = observer(
type === "market"
)
return;

const value = tokenAmount.length > 0 ? new Dec(tokenAmount) : undefined;
const fiatValue = value
? swapState.priceState.price.mul(value)
Expand Down

0 comments on commit b989ce7

Please sign in to comment.