Skip to content

Commit

Permalink
fix hook to update swap slippage
Browse files Browse the repository at this point in the history
  • Loading branch information
webdev403 committed Mar 21, 2024
1 parent a4d5fd7 commit 7b2b6b8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/state/swap/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 &&
Expand All @@ -300,6 +303,7 @@ export function useDerivedSwapInfo(): {
setUserSlippageTolerance,
chainIdToUse,
slippageManuallySet,
swapSlippage,
]);

return {
Expand Down
7 changes: 6 additions & 1 deletion src/state/swap/v3/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand All @@ -273,6 +277,7 @@ export function useDerivedSwapInfo(): {
setUserSlippageTolerance,
chainIdToUse,
slippageManuallySet,
swapSlippage,
]);

return {
Expand Down

0 comments on commit 7b2b6b8

Please sign in to comment.