From 7b2b6b860d81fa8992a0fef36f76291e87e090e5 Mon Sep 17 00:00:00 2001 From: webdev403 Date: Thu, 21 Mar 2024 05:11:23 -0400 Subject: [PATCH] fix hook to update swap slippage --- src/state/swap/hooks.ts | 6 +++++- src/state/swap/v3/hooks.ts | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/state/swap/hooks.ts b/src/state/swap/hooks.ts index fa0a2af..d15d5ad 100644 --- a/src/state/swap/hooks.ts +++ b/src/state/swap/hooks.ts @@ -186,6 +186,9 @@ export function useDerivedSwapInfo(): { const chainIdToUse = chainId ?? ChainId.MATIC; const parsedQuery = useParsedQueryString(); const swapType = parsedQuery ? parsedQuery.swapIndex : undefined; + const swapSlippage = parsedQuery?.slippage + ? (parsedQuery.slippage as string) + : undefined; const { independentField, @@ -282,7 +285,7 @@ export function useDerivedSwapInfo(): { stableCoins && stableCoins.length > 0 ? stableCoins.map((token) => token.address.toLowerCase()) : []; - if (!slippageManuallySet) { + if (!swapSlippage && !slippageManuallySet) { if ( inputCurrencyId && outputCurrencyId && @@ -300,6 +303,7 @@ export function useDerivedSwapInfo(): { setUserSlippageTolerance, chainIdToUse, slippageManuallySet, + swapSlippage, ]); return { diff --git a/src/state/swap/v3/hooks.ts b/src/state/swap/v3/hooks.ts index e55f191..0711eae 100644 --- a/src/state/swap/v3/hooks.ts +++ b/src/state/swap/v3/hooks.ts @@ -249,13 +249,17 @@ export function useDerivedSwapInfo(): { inputError = `Insufficient ${amountIn.currency.symbol} balance`; } + const parsedQs = useParsedQueryString(); + const swapSlippage = parsedQs.slippage + ? (parsedQs.slippage as string) + : undefined; useEffect(() => { const stableCoins = GlobalData.stableCoins[chainIdToUse]; const stableCoinAddresses = stableCoins && stableCoins.length > 0 ? stableCoins.map((token) => token.address.toLowerCase()) : []; - if (!slippageManuallySet) { + if (!swapSlippage && !slippageManuallySet) { if ( inputCurrencyId && outputCurrencyId && @@ -273,6 +277,7 @@ export function useDerivedSwapInfo(): { setUserSlippageTolerance, chainIdToUse, slippageManuallySet, + swapSlippage, ]); return {