From f3277b45ab3261785267d3cb9b86d008d6c7b726 Mon Sep 17 00:00:00 2001 From: surbhi Date: Mon, 1 Dec 2025 13:00:02 -0400 Subject: [PATCH] diabling swab button if slippage exceed 5% --- src/components/swap-form.tsx | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/components/swap-form.tsx b/src/components/swap-form.tsx index 62c6242..4bb61ba 100644 --- a/src/components/swap-form.tsx +++ b/src/components/swap-form.tsx @@ -73,6 +73,14 @@ export function SwapForm() { } }, [selectedFromToken, fromAmount]); + // Check if calculated slippage exceeds 5% + const slippageExceedsLimit = useMemo(() => { + if (!swapAmounts || swapAmounts.length === 0 || swapAmounts[0].calculatedSlippage === undefined) { + return false; + } + return Math.abs(swapAmounts[0].calculatedSlippage) > 5; + }, [swapAmounts]); + // Initialize swap hook const { executeSwap, estimateGas, isSwapping, gasEstimate, isEstimatingGas } = useSwap(); @@ -370,9 +378,20 @@ export function SwapForm() { )} - {/* High slippage warning - show if calculated slippage exceeds max slippage OR 5% */} - {swapAmounts && swapAmounts.length > 0 && swapAmounts[0].calculatedSlippage !== undefined && ( - Math.abs(swapAmounts[0].calculatedSlippage) > Math.max(currentSlippage, 5) + {/* Error message for slippage exceeding 5% */} + {slippageExceedsLimit && ( +
+

⚠️ Slippage Exceeds 5%

+

+ The estimated slippage for this swap is {Math.abs(swapAmounts![0].calculatedSlippage!).toFixed(2)}%. + We cannot process this swap as you may lose too much money due to the high slippage. +

+
+ )} + + {/* High slippage warning - show if calculated slippage exceeds max slippage but is under 5% */} + {!slippageExceedsLimit && swapAmounts && swapAmounts.length > 0 && swapAmounts[0].calculatedSlippage !== undefined && ( + Math.abs(swapAmounts[0].calculatedSlippage) > currentSlippage ) && (

⚠️ High Slippage Warning

@@ -420,12 +439,14 @@ export function SwapForm() {