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

wrap fix #1631

Merged
merged 1 commit into from
Dec 5, 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
6 changes: 5 additions & 1 deletion src/components/Swap/SwapBestTrade.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,10 @@ const SwapBestTrade: React.FC<{
const betterPriceFound = await getBetterPrice({
dexOutAmount: optimalRate?.destAmount,
allowedSlippage,
skip: liquidityHubDisabled,
skip:
liquidityHubDisabled ||
wrapType === WrapType.WRAP ||
wrapType === WrapType.UNWRAP,
});

if (betterPriceFound) {
Expand All @@ -1067,6 +1070,7 @@ const SwapBestTrade: React.FC<{
getBetterPrice,
isLhPureAggregationMode,
onPureAggregationSubmit,
wrapType,
]);

const paraRate = optimalRate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ const useLiquidityHubSwapCallback = () => {
outCurrency,
getLatestQuote,
onLiquidityHubSwapInProgress,
quote,
} = useLiquidityHubConfirmationContext();
const { mutateAsync: signCallback } = useSignEIP712Callback();
const getSteps = useGetStepsCallback();
Expand Down Expand Up @@ -431,17 +432,15 @@ const useLiquidityHubSwapCallback = () => {
await approvalCallback();
}

const acceptedQuote = getLatestQuote();
const acceptedQuote = getLatestQuote() || quote;

if (!acceptedQuote) {
throw new Error('Failed to fetch quote');
throw new Error('missing quote');
}

onAcceptQuote(acceptedQuote);
updateStore({ currentStep: Steps.SWAP });
const signature = await promiseWithTimeout(
signCallback(acceptedQuote.permitData),
SIGNATURE_TIMEOUT,
);
const signature = await signCallback(acceptedQuote.permitData);
onSignature(signature);

const txHash = await swapCallback({
Expand Down
49 changes: 24 additions & 25 deletions src/components/Swap/orbs/LiquidityHub/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ChainId, Currency } from '@uniswap/sdk';
import { useActiveWeb3React } from 'hooks';
import { useMemo, useState } from 'react';
import { useCallback, useMemo, useState } from 'react';
import { getConfig } from 'config';
import { wrappedCurrency } from 'utils/wrappedCurrency';
import {
Expand Down Expand Up @@ -134,37 +134,36 @@ export const useGetBetterPrice = (
) => {
const [seekingBetterPrice, setSeekingBestPrice] = useState(false);

const mutation = useMutation({
mutationFn: async ({
dexOutAmount = '',
allowedSlippage = 0,
const getBetterPrice = useCallback(
async ({
skip,
allowedSlippage = 0,
dexOutAmount = '',
}: {
dexOutAmount?: string;
skip: boolean;
allowedSlippage?: number;
skip?: boolean;
dexOutAmount?: string;
}) => {
if (skip) return false;
setSeekingBestPrice(true);
const quote = await promiseWithTimeout(fetchLiquidityHubQuote(), 5_000);
const dexMinAmountOut =
subtractSlippage(allowedSlippage, dexOutAmount) || 0;
return BN(quote?.userMinOutAmountWithGas || 0).gt(dexMinAmountOut);
},
onError: (error) => {
console.error('useSeekingBetterPrice', error);
},
onSettled: () => {
setTimeout(() => {
setSeekingBestPrice(false);
}, 50);
try {
if (skip) return false;
setSeekingBestPrice(true);
const quote = await promiseWithTimeout(fetchLiquidityHubQuote(), 5_000);
const dexMinAmountOut =
subtractSlippage(allowedSlippage, dexOutAmount) || 0;
return BN(quote?.userMinOutAmountWithGas || 0).gt(dexMinAmountOut);
} catch (error) {
console.error('useSeekingBetterPrice', error);
} finally {
setTimeout(() => {
setSeekingBestPrice(false);
}, 50);
}
},
});
[fetchLiquidityHubQuote],
);

return {
seekingBetterPrice,
quote: mutation.data,
error: mutation.error,
getBetterPrice: mutation.mutateAsync,
getBetterPrice,
};
};
Loading