From dd0f87579486dfd20f61276717dd43b2a261e419 Mon Sep 17 00:00:00 2001 From: Sukh Singh Date: Thu, 3 Oct 2024 15:48:36 +0100 Subject: [PATCH] add slippage field --- src/trade/swap/swap.tsx | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/trade/swap/swap.tsx b/src/trade/swap/swap.tsx index 2cee13f..33c16e3 100644 --- a/src/trade/swap/swap.tsx +++ b/src/trade/swap/swap.tsx @@ -36,8 +36,7 @@ import { } from '@/components/ui/popover' import { Switch } from '@/components/ui/switch' import { Label } from '@/components/ui/label' - -const slippage = 0.5 +import { Input } from '@/components/ui/input' export function Swap() { const { tokensWithBalances, refetch: refetchBalances } = @@ -57,6 +56,7 @@ export function Swap() { const [swapConfirmOpen, setSwapConfirmOpen] = useState(false) const [signature, setSignature] = useState(undefined) const [forceLiquidityHub, setForceLiquidityHub] = useState(false) + const [slippage, setSlippage] = useState(0.5) // Get wagmi account const account = useAccount() @@ -182,7 +182,7 @@ export function Swap() { console.error(error) toast.error(getErrorMessage(error, 'An error occurred while swapping')) } - }, [optimalRate, paraswapSwapCallback, resetSwap]) + }, [optimalRate, paraswapSwapCallback, resetSwap, slippage]) const swapWithLiquidityHub = useCallback(async () => { if (!optimalRate) { @@ -218,6 +218,7 @@ export function Swap() { getLatestQuote, onAcceptQuote, resetSwap, + slippage, swapWithParaswap, ]) @@ -244,12 +245,26 @@ export function Swap() { -
-
+
+
+ +
+ setSlippage(e.target.valueAsNumber)} + value={slippage} + step={0.1} + className="text-right w-16 [&::-webkit-inner-spin-button]:appearance-none p-2 h-7" + /> +
%
+
+
+