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
@@ -420,12 +439,14 @@ export function SwapForm() {