Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix hook to update swap slippage #3

Merged
merged 2 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading