From 7b2b6b860d81fa8992a0fef36f76291e87e090e5 Mon Sep 17 00:00:00 2001 From: webdev403 Date: Thu, 21 Mar 2024 05:11:23 -0400 Subject: [PATCH 1/2] 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 { From cb3585606a765b0da58b470323be117cab179da3 Mon Sep 17 00:00:00 2001 From: webdev403 Date: Thu, 21 Mar 2024 05:24:04 -0400 Subject: [PATCH 2/2] fix hooks for swap --- src/state/swap/hooks.ts | 4 ++-- src/state/swap/v3/hooks.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/state/swap/hooks.ts b/src/state/swap/hooks.ts index d15d5ad..0a413a4 100644 --- a/src/state/swap/hooks.ts +++ b/src/state/swap/hooks.ts @@ -185,9 +185,9 @@ export function useDerivedSwapInfo(): { const { account, chainId } = useActiveWeb3React(); const chainIdToUse = chainId ?? ChainId.MATIC; const parsedQuery = useParsedQueryString(); - const swapType = parsedQuery ? parsedQuery.swapIndex : undefined; + const swapType = parsedQuery?.swapIndex; const swapSlippage = parsedQuery?.slippage - ? (parsedQuery.slippage as string) + ? (parsedQuery?.slippage as string) : undefined; const { diff --git a/src/state/swap/v3/hooks.ts b/src/state/swap/v3/hooks.ts index 0711eae..90b7e6f 100644 --- a/src/state/swap/v3/hooks.ts +++ b/src/state/swap/v3/hooks.ts @@ -250,8 +250,8 @@ export function useDerivedSwapInfo(): { } const parsedQs = useParsedQueryString(); - const swapSlippage = parsedQs.slippage - ? (parsedQs.slippage as string) + const swapSlippage = parsedQs?.slippage + ? (parsedQs?.slippage as string) : undefined; useEffect(() => { const stableCoins = GlobalData.stableCoins[chainIdToUse];