Skip to content

Commit

Permalink
Merge pull request #3 from QuickSwap/hotfix/swap-slippage
Browse files Browse the repository at this point in the history
fix hook to update swap slippage
  • Loading branch information
sameepsi authored Mar 22, 2024
2 parents a4d5fd7 + cb35856 commit e16f8e3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/state/swap/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,10 @@ 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)
: 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 e16f8e3

Please sign in to comment.