diff --git a/package-lock.json b/package-lock.json index d492faf6e..4d61b4518 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,7 +22,7 @@ "@material-ui/icons": "^4.11.2", "@material-ui/lab": "^4.0.0-alpha.60", "@material-ui/styles": "^4.11.5", - "@orbs-network/liquidity-hub-sdk": "^1.0.45", + "@orbs-network/liquidity-hub-sdk": "^1.0.47", "@orbs-network/swap-ui": "^0.0.14", "@orbs-network/twap-sdk": "^2.0.33", "@orderly.network/hooks": "^1.4.3", @@ -10760,9 +10760,9 @@ } }, "node_modules/@orbs-network/liquidity-hub-sdk": { - "version": "1.0.45", - "resolved": "https://registry.npmjs.org/@orbs-network/liquidity-hub-sdk/-/liquidity-hub-sdk-1.0.45.tgz", - "integrity": "sha512-xgb0xmiY04Iv4YcEuW14Bxi7bRaCGYQkjRIAKNUS079CL0hkG5jJUmf8Ekwqn7OrDqpkX64S2bj8HBR0PH+ZTw==" + "version": "1.0.47", + "resolved": "https://registry.npmjs.org/@orbs-network/liquidity-hub-sdk/-/liquidity-hub-sdk-1.0.47.tgz", + "integrity": "sha512-EPdH2O9KpJA/ZwSL9W/0b90nFr8xg184PllIkXtVcHZ6E0F85cLDCkrkBeoyEzEKsWNVBzCK2PLBWZ3ZWa3e+g==" }, "node_modules/@orbs-network/swap-ui": { "version": "0.0.14", diff --git a/package.json b/package.json index 2aff7af84..783308544 100755 --- a/package.json +++ b/package.json @@ -98,7 +98,7 @@ "@material-ui/icons": "^4.11.2", "@material-ui/lab": "^4.0.0-alpha.60", "@material-ui/styles": "^4.11.5", - "@orbs-network/liquidity-hub-sdk": "^1.0.45", + "@orbs-network/liquidity-hub-sdk": "^1.0.47", "@orbs-network/swap-ui": "^0.0.14", "@orbs-network/twap-sdk": "^2.0.33", "@orderly.network/hooks": "^1.4.3", diff --git a/public/locales/en.json b/public/locales/en.json index 00287917e..ec4ccb4c8 100755 --- a/public/locales/en.json +++ b/public/locales/en.json @@ -1038,5 +1038,7 @@ "networkFeeHelper": "Network fees are paid for transaction", "dragonEggAlert": "Screenshot this and DM @QuickswapDEX on X (Twitter) for a chance to win prizes! First come, first serve.", "cancelOrder": "Cancel Order", - "seekingBetterPrice": "Seeking better price" + "seekingBetterPrice": "Seeking better price", + "wrapError": "Your {{ native }} has been wrapped to {{ wrapped }}", + "txFailed": "Transaction failed" } diff --git a/src/components/Footer/Footer.tsx b/src/components/Footer/Footer.tsx index fd4e69fa3..5ea130d5a 100755 --- a/src/components/Footer/Footer.tsx +++ b/src/components/Footer/Footer.tsx @@ -30,7 +30,7 @@ const Footer: React.FC = () => { title: t('Products'), items: [ { title: t('swap'), link: '/swap' }, - { title: t('Perps - zkEVM V1'), link: process.env.REACT_APP_PERPS_URL }, + { title: t('Hydra'), link: process.env.REACT_APP_HYDRA_URL }, { title: 'Perps - PoS', link: '/falkor', isNew: true }, { title: t('pool'), link: '/pools' }, { title: t('farm'), link: '/farm' }, diff --git a/src/components/Header/Header.tsx b/src/components/Header/Header.tsx index 0b1a2ab90..1dfd3254c 100644 --- a/src/components/Header/Header.tsx +++ b/src/components/Header/Header.tsx @@ -186,7 +186,7 @@ const Header: React.FC<{ onUpdateNewsletter: (val: boolean) => void }> = ({ menuItems.push(hydraItem); } } - if (showPerps) { + if (showPerps && process.env.NODE_ENV !== 'production') { if (showHydra || showPerpsV2) { perpsTab.items?.push(perpsItem); } else { diff --git a/src/components/Header/MobileHeader.tsx b/src/components/Header/MobileHeader.tsx index 866e3c83e..38bd5fc5d 100644 --- a/src/components/Header/MobileHeader.tsx +++ b/src/components/Header/MobileHeader.tsx @@ -70,7 +70,7 @@ const MobileHeader: React.FC = ({ }, }); } - if (showPerps) { + if (showPerps && process.env.NODE_ENV !== 'production') { perpMenuItems.push({ id: 'perps-v1-page-link', link: process.env.REACT_APP_PERPS_URL || '#', diff --git a/src/components/Swap/SwapBestTrade.tsx b/src/components/Swap/SwapBestTrade.tsx index c626d5461..e1b6721a9 100644 --- a/src/components/Swap/SwapBestTrade.tsx +++ b/src/components/Swap/SwapBestTrade.tsx @@ -453,7 +453,6 @@ const SwapBestTrade: React.FC<{ isLoading: liquidityHubQuoteLoading, error: liquidityHubQuoteError, refetch: fetchLiquidityHubQuote, - getLatestQuote, } = useLiquidityHubQuote({ allowedSlippage, inAmount: parsedAmount?.raw.toString(), @@ -1279,6 +1278,8 @@ const SwapBestTrade: React.FC<{ } }, [handleParaswap, onApprove, showApproveFlow]); + const getLatestOptimalRate = useCallback(() => optimalRate, [optimalRate]); + return ( diff --git a/src/components/Swap/orbs/ConfirmationModal.tsx b/src/components/Swap/orbs/ConfirmationModal.tsx index b727047da..c8eca9a7e 100644 --- a/src/components/Swap/orbs/ConfirmationModal.tsx +++ b/src/components/Swap/orbs/ConfirmationModal.tsx @@ -51,7 +51,6 @@ export type ConfirmationState = { txHash?: string; steps?: Steps[]; error?: string; - stapStatus?: SwapStatus; }; interface ConfirmationModalProps extends SharedProps { @@ -117,14 +116,14 @@ const ConfirmationProvider = (props: ContextProps) => { ); const onDismiss = useCallback(() => { + if (store.swapStatus) { + dispatch(updateUserBalance()); + } setTimeout(() => { resetStore(); }, 5_00); props.onDismiss(); - if (store.stapStatus === SwapStatus.SUCCESS) { - dispatch(updateUserBalance()); - } - }, [props, resetStore, store.stapStatus, dispatch]); + }, [props, resetStore, store.swapStatus, dispatch]); return ( { const { - onDismiss, + onDismiss: _onDismiss, inAmount, - state: { shouldUnwrap, error }, + state: { shouldUnwrap }, } = useConfirmationContext(); const { t } = useTranslation(); const { chainId } = useActiveWeb3React(); const nativeSymbol = ETHER[chainId].symbol; + const wSymbol = WETH[chainId].symbol; + const [isLoading, setIsLoading] = useState(false); - const { execute, wrapType } = useWrapCallback( + const { execute, inputError } = useWrapCallback( WETH[chainId], ETHER[chainId], inAmount, ); + const [success, setSuccess] = useState(false); - const isLoading = wrapType === WrapType.UNWRAPPING; const unwrap = useCallback(async () => { try { + setIsLoading(true); await execute?.(); setSuccess(true); } catch (error) { console.error(error); + } finally { + setIsLoading(false); } }, [execute]); + const onDismiss = useCallback(() => { + _onDismiss(); + setSuccess(false); + }, [_onDismiss]); + if (success) { return ( { return ( - + - {error && Transaction Failed} + {shouldUnwrap && ( + + {t('wrapError', { native: nativeSymbol, wrapped: wSymbol })} + + )} - {shouldUnwrap ? ( + {!inputError && shouldUnwrap ? ( {t('unwrap')} @@ -324,24 +343,6 @@ export const Error = () => { ); }; -const SwapButton = ({ - text, - onSubmit, -}: { - text?: string; - onSubmit: () => void; -}) => { - return ( - - - - {text} - - - - ); -}; - export const Main = ({ parseSteps, swapDetails, diff --git a/src/components/Swap/orbs/LiquidityHub/LiquidityHubSwapConfirmation.tsx b/src/components/Swap/orbs/LiquidityHub/LiquidityHubSwapConfirmation.tsx index 12bc0b69a..982a631f1 100644 --- a/src/components/Swap/orbs/LiquidityHub/LiquidityHubSwapConfirmation.tsx +++ b/src/components/Swap/orbs/LiquidityHub/LiquidityHubSwapConfirmation.tsx @@ -9,13 +9,7 @@ import { useMutation } from '@tanstack/react-query'; import { useCallback } from 'react'; import { Currency, WETH } from '@uniswap/sdk'; import { useActiveWeb3React } from 'hooks'; -import { - fromRawAmount, - subtractSlippage, - isRejectedError, - isTimeoutError, - promiseWithTimeout, -} from '../utils'; +import { fromRawAmount, isRejectedError, isTimeoutError } from '../utils'; import { OptimalRate } from '@paraswap/sdk'; import { useParaswap } from 'hooks/useParaswap'; import { wrappedCurrency } from 'utils/wrappedCurrency'; @@ -41,18 +35,16 @@ import { useLiquidityHubSDK } from './hooks'; import useWrapCallback from 'hooks/useWrapCallback'; import { useSwapActionHandlers } from 'state/swap/hooks'; import { Field } from 'state/swap/actions'; -import { useAppDispatch } from 'state'; -import { updateUserBalance } from 'state/balance/actions'; export interface LiquidityHubConfirmationProps { inCurrency?: Currency; outCurrency?: Currency; isOpen: boolean; onDismiss: () => void; - getLatestQuote: () => Quote | undefined; + fetchLiquidityHubQuote: () => Promise; quote?: Quote | null; onSwapFailed: () => void; - optimalRate?: OptimalRate; + getOptimalRate: () => OptimalRate | undefined; allowedSlippage?: number; onLiquidityHubSwapInProgress: (value: boolean) => void; inAmount?: string; @@ -156,6 +148,7 @@ const useAmounts = () => { const useParseSteps = () => { const { inCurrency, signature } = useLiquidityHubConfirmationContext(); + const { chainId } = useActiveWeb3React(); const getLogo = useGetLogoCallback(); return useCallback( @@ -171,7 +164,9 @@ const useParseSteps = () => { } if (step === Steps.APPROVE) { return { - title: `Approve ${inCurrency?.symbol} spending`, + title: `Approve ${ + wrappedCurrency(inCurrency, chainId)?.symbol + } spending`, icon: , id: Steps.APPROVE, }; @@ -185,7 +180,7 @@ const useParseSteps = () => { }; }); }, - [inCurrency, signature, getLogo], + [inCurrency, signature, getLogo, chainId], ); }; @@ -366,15 +361,15 @@ const useSwapCallback = () => { return useMutation({ mutationFn: async ({ - acceptedQuote, + quote, signature, }: { - acceptedQuote: Quote; + quote: Quote; signature: string; }) => { const txParams = await getParaswapTxParams(); - const txHash = await liquidityHub.swap(acceptedQuote, signature, { + const txHash = await liquidityHub.swap(quote, signature, { data: txParams?.data || '', to: txParams?.to, }); @@ -392,9 +387,8 @@ const useLiquidityHubSwapCallback = () => { onAcceptQuote, inCurrency, outCurrency, - getLatestQuote, + fetchLiquidityHubQuote, onLiquidityHubSwapInProgress, - quote, } = useLiquidityHubConfirmationContext(); const { mutateAsync: signCallback } = useSignEIP712Callback(); const getSteps = useGetStepsCallback(); @@ -403,7 +397,7 @@ const useLiquidityHubSwapCallback = () => { const { mutateAsync: approvalCallback } = useApproveCallback(); const onTradeSuccess = useOnTradeSuccessCallback(); const { onUserInput } = useSwapActionHandlers(); - const dispatch = useAppDispatch(); + const liquidityHubSdk = useLiquidityHubSDK(); return useMutation({ mutationFn: async ( @@ -436,29 +430,34 @@ const useLiquidityHubSwapCallback = () => { await approvalCallback(); } - const acceptedQuote = getLatestQuote() || quote; + const latestQuote = await fetchLiquidityHubQuote(); - if (!acceptedQuote) { + if (!latestQuote) { throw new Error('missing quote'); } - onAcceptQuote(acceptedQuote); + onAcceptQuote(latestQuote); updateStore({ currentStep: Steps.SWAP }); - const signature = await signCallback(acceptedQuote.permitData); + const signature = await signCallback(latestQuote.permitData); onSignature(signature); const txHash = await swapCallback({ - acceptedQuote, + quote: latestQuote, signature, }); - const transaction = await library.getTransaction(txHash); - const receipt = await transaction.wait(); + const details = await liquidityHubSdk.getTransactionDetails( + txHash, + latestQuote, + ); + + if (!details) { + throw new Error('missing transaction details'); + } + onUserInput(Field.INPUT, ''); - dispatch(updateUserBalance()); updateStore({ swapStatus: SwapStatus.SUCCESS }); - onTradeSuccess(acceptedQuote); - return receipt; + onTradeSuccess(latestQuote); } catch (error) { const isRejectedOrTimeout = isRejectedError(error) || isTimeoutError(error); @@ -502,29 +501,28 @@ const useOnTradeSuccessCallback = () => { ); } catch (error) {} }, - [liquidityHubSDK, outTokenUsdPrice, outToken, outCurrency], + [liquidityHubSDK, outTokenUsdPrice, outCurrency], ); }; const useParaswapTxParamsCallback = () => { const paraswap = useParaswap(); - const { account, chainId } = useActiveWeb3React(); + const { account } = useActiveWeb3React(); const { allowedSlippage, - optimalRate, - inCurrency, + getOptimalRate, } = useLiquidityHubConfirmationContext(); return useMutation({ mutationFn: async () => { - const inToken = wrappedCurrency(inCurrency, chainId); - if (!optimalRate || !allowedSlippage || !inToken || !account) { + const optimalRate = getOptimalRate(); + if (!optimalRate || !allowedSlippage || !account) { throw new Error('useParaswapTxParamsCallback missing args'); } try { const result = await paraswap.buildTx( { - srcToken: inToken.address, + srcToken: optimalRate.srcToken, destToken: optimalRate.destToken, srcAmount: optimalRate.srcAmount, destAmount: optimalRate.destAmount, diff --git a/src/components/Swap/orbs/LiquidityHub/hooks.ts b/src/components/Swap/orbs/LiquidityHub/hooks.ts index 45c3099f6..3e63d6479 100644 --- a/src/components/Swap/orbs/LiquidityHub/hooks.ts +++ b/src/components/Swap/orbs/LiquidityHub/hooks.ts @@ -69,8 +69,8 @@ export const useLiquidityHubQuote = ({ : wrappedCurrency(outCurrency, chainId)?.address; }, [outCurrency, isNativeCurrency, chainId]); - const queryKey = useMemo( - () => [ + const query = useQuery({ + queryKey: [ 'useLiquidityHubQuote', fromToken, toToken, @@ -78,11 +78,6 @@ export const useLiquidityHubQuote = ({ allowedSlippage, chainId, ], - [fromToken, toToken, inAmount, allowedSlippage, chainId], - ); - - const query = useQuery({ - queryKey, queryFn: async ({ signal }) => { if (!fromToken || !toToken || !inAmount || !chainId || !allowedSlippage) { throw new Error('useLiquidityHubQuote Missing required parameters'); @@ -118,15 +113,14 @@ export const useLiquidityHubQuote = ({ isSupported, }); - const queryClient = useQueryClient(); + const refetch = useCallback(async () => { + return (await query.refetch()).data; + }, [query.refetch]); - return useMemo(() => { - return { - ...query, - getLatestQuote: () => queryClient.getQueryData(queryKey), - refetch: async () => (await query.refetch()).data, - }; - }, [query, queryClient, queryKey]); + return { + ...query, + refetch, + }; }; export const useGetBetterPrice = ( @@ -147,7 +141,7 @@ export const useGetBetterPrice = ( try { if (skip) return false; setSeekingBestPrice(true); - const quote = await promiseWithTimeout(fetchLiquidityHubQuote(), 5_000); + const quote = await promiseWithTimeout(fetchLiquidityHubQuote(), 8_000); const dexMinAmountOut = subtractSlippage(allowedSlippage, dexOutAmount) || 0; return BN(quote?.userMinOutAmountWithGas || 0).gt(dexMinAmountOut); diff --git a/src/components/Swap/orbs/utils.ts b/src/components/Swap/orbs/utils.ts index b6804525e..da66649cb 100644 --- a/src/components/Swap/orbs/utils.ts +++ b/src/components/Swap/orbs/utils.ts @@ -52,7 +52,7 @@ export const isRejectedError = (error: any) => { export const isTimeoutError = (error: any) => { const message = error.message?.toLowerCase(); - return message?.includes('timeout'); + return message === 'timeout'; }; export const makeElipsisAddress = (address?: string, padding = 6): string => { diff --git a/src/constants/abis/token-locker-abi.json b/src/constants/abis/token-locker-abi.json index 97c6cde7c..45797831a 100644 --- a/src/constants/abis/token-locker-abi.json +++ b/src/constants/abis/token-locker-abi.json @@ -1322,4 +1322,4 @@ "stateMutability": "nonpayable", "type": "function" } -] \ No newline at end of file +] diff --git a/src/pages/PerpsPage/FooterOrdersTable.tsx b/src/pages/PerpsPage/FooterOrdersTable.tsx index 0861cdff2..3ff13e15b 100644 --- a/src/pages/PerpsPage/FooterOrdersTable.tsx +++ b/src/pages/PerpsPage/FooterOrdersTable.tsx @@ -61,7 +61,6 @@ const FooterOrdersTable: React.FC<{ const [o, { cancelOrder, cancelAlgoOrder, isLoading }] = useOrderStream({ symbol: token, status: orderStatus, - excludes: [AlgoOrderRootType.TP_SL, AlgoOrderRootType.POSITIONAL_TP_SL], }); const orders = o as Order[] | null;
Transaction Failed
+ {t('wrapError', { native: nativeSymbol, wrapped: wSymbol })} +
; quote?: Quote | null; onSwapFailed: () => void; - optimalRate?: OptimalRate; + getOptimalRate: () => OptimalRate | undefined; allowedSlippage?: number; onLiquidityHubSwapInProgress: (value: boolean) => void; inAmount?: string; @@ -156,6 +148,7 @@ const useAmounts = () => { const useParseSteps = () => { const { inCurrency, signature } = useLiquidityHubConfirmationContext(); + const { chainId } = useActiveWeb3React(); const getLogo = useGetLogoCallback(); return useCallback( @@ -171,7 +164,9 @@ const useParseSteps = () => { } if (step === Steps.APPROVE) { return { - title: `Approve ${inCurrency?.symbol} spending`, + title: `Approve ${ + wrappedCurrency(inCurrency, chainId)?.symbol + } spending`, icon: , id: Steps.APPROVE, }; @@ -185,7 +180,7 @@ const useParseSteps = () => { }; }); }, - [inCurrency, signature, getLogo], + [inCurrency, signature, getLogo, chainId], ); }; @@ -366,15 +361,15 @@ const useSwapCallback = () => { return useMutation({ mutationFn: async ({ - acceptedQuote, + quote, signature, }: { - acceptedQuote: Quote; + quote: Quote; signature: string; }) => { const txParams = await getParaswapTxParams(); - const txHash = await liquidityHub.swap(acceptedQuote, signature, { + const txHash = await liquidityHub.swap(quote, signature, { data: txParams?.data || '', to: txParams?.to, }); @@ -392,9 +387,8 @@ const useLiquidityHubSwapCallback = () => { onAcceptQuote, inCurrency, outCurrency, - getLatestQuote, + fetchLiquidityHubQuote, onLiquidityHubSwapInProgress, - quote, } = useLiquidityHubConfirmationContext(); const { mutateAsync: signCallback } = useSignEIP712Callback(); const getSteps = useGetStepsCallback(); @@ -403,7 +397,7 @@ const useLiquidityHubSwapCallback = () => { const { mutateAsync: approvalCallback } = useApproveCallback(); const onTradeSuccess = useOnTradeSuccessCallback(); const { onUserInput } = useSwapActionHandlers(); - const dispatch = useAppDispatch(); + const liquidityHubSdk = useLiquidityHubSDK(); return useMutation({ mutationFn: async ( @@ -436,29 +430,34 @@ const useLiquidityHubSwapCallback = () => { await approvalCallback(); } - const acceptedQuote = getLatestQuote() || quote; + const latestQuote = await fetchLiquidityHubQuote(); - if (!acceptedQuote) { + if (!latestQuote) { throw new Error('missing quote'); } - onAcceptQuote(acceptedQuote); + onAcceptQuote(latestQuote); updateStore({ currentStep: Steps.SWAP }); - const signature = await signCallback(acceptedQuote.permitData); + const signature = await signCallback(latestQuote.permitData); onSignature(signature); const txHash = await swapCallback({ - acceptedQuote, + quote: latestQuote, signature, }); - const transaction = await library.getTransaction(txHash); - const receipt = await transaction.wait(); + const details = await liquidityHubSdk.getTransactionDetails( + txHash, + latestQuote, + ); + + if (!details) { + throw new Error('missing transaction details'); + } + onUserInput(Field.INPUT, ''); - dispatch(updateUserBalance()); updateStore({ swapStatus: SwapStatus.SUCCESS }); - onTradeSuccess(acceptedQuote); - return receipt; + onTradeSuccess(latestQuote); } catch (error) { const isRejectedOrTimeout = isRejectedError(error) || isTimeoutError(error); @@ -502,29 +501,28 @@ const useOnTradeSuccessCallback = () => { ); } catch (error) {} }, - [liquidityHubSDK, outTokenUsdPrice, outToken, outCurrency], + [liquidityHubSDK, outTokenUsdPrice, outCurrency], ); }; const useParaswapTxParamsCallback = () => { const paraswap = useParaswap(); - const { account, chainId } = useActiveWeb3React(); + const { account } = useActiveWeb3React(); const { allowedSlippage, - optimalRate, - inCurrency, + getOptimalRate, } = useLiquidityHubConfirmationContext(); return useMutation({ mutationFn: async () => { - const inToken = wrappedCurrency(inCurrency, chainId); - if (!optimalRate || !allowedSlippage || !inToken || !account) { + const optimalRate = getOptimalRate(); + if (!optimalRate || !allowedSlippage || !account) { throw new Error('useParaswapTxParamsCallback missing args'); } try { const result = await paraswap.buildTx( { - srcToken: inToken.address, + srcToken: optimalRate.srcToken, destToken: optimalRate.destToken, srcAmount: optimalRate.srcAmount, destAmount: optimalRate.destAmount, diff --git a/src/components/Swap/orbs/LiquidityHub/hooks.ts b/src/components/Swap/orbs/LiquidityHub/hooks.ts index 45c3099f6..3e63d6479 100644 --- a/src/components/Swap/orbs/LiquidityHub/hooks.ts +++ b/src/components/Swap/orbs/LiquidityHub/hooks.ts @@ -69,8 +69,8 @@ export const useLiquidityHubQuote = ({ : wrappedCurrency(outCurrency, chainId)?.address; }, [outCurrency, isNativeCurrency, chainId]); - const queryKey = useMemo( - () => [ + const query = useQuery({ + queryKey: [ 'useLiquidityHubQuote', fromToken, toToken, @@ -78,11 +78,6 @@ export const useLiquidityHubQuote = ({ allowedSlippage, chainId, ], - [fromToken, toToken, inAmount, allowedSlippage, chainId], - ); - - const query = useQuery({ - queryKey, queryFn: async ({ signal }) => { if (!fromToken || !toToken || !inAmount || !chainId || !allowedSlippage) { throw new Error('useLiquidityHubQuote Missing required parameters'); @@ -118,15 +113,14 @@ export const useLiquidityHubQuote = ({ isSupported, }); - const queryClient = useQueryClient(); + const refetch = useCallback(async () => { + return (await query.refetch()).data; + }, [query.refetch]); - return useMemo(() => { - return { - ...query, - getLatestQuote: () => queryClient.getQueryData(queryKey), - refetch: async () => (await query.refetch()).data, - }; - }, [query, queryClient, queryKey]); + return { + ...query, + refetch, + }; }; export const useGetBetterPrice = ( @@ -147,7 +141,7 @@ export const useGetBetterPrice = ( try { if (skip) return false; setSeekingBestPrice(true); - const quote = await promiseWithTimeout(fetchLiquidityHubQuote(), 5_000); + const quote = await promiseWithTimeout(fetchLiquidityHubQuote(), 8_000); const dexMinAmountOut = subtractSlippage(allowedSlippage, dexOutAmount) || 0; return BN(quote?.userMinOutAmountWithGas || 0).gt(dexMinAmountOut); diff --git a/src/components/Swap/orbs/utils.ts b/src/components/Swap/orbs/utils.ts index b6804525e..da66649cb 100644 --- a/src/components/Swap/orbs/utils.ts +++ b/src/components/Swap/orbs/utils.ts @@ -52,7 +52,7 @@ export const isRejectedError = (error: any) => { export const isTimeoutError = (error: any) => { const message = error.message?.toLowerCase(); - return message?.includes('timeout'); + return message === 'timeout'; }; export const makeElipsisAddress = (address?: string, padding = 6): string => { diff --git a/src/constants/abis/token-locker-abi.json b/src/constants/abis/token-locker-abi.json index 97c6cde7c..45797831a 100644 --- a/src/constants/abis/token-locker-abi.json +++ b/src/constants/abis/token-locker-abi.json @@ -1322,4 +1322,4 @@ "stateMutability": "nonpayable", "type": "function" } -] \ No newline at end of file +] diff --git a/src/pages/PerpsPage/FooterOrdersTable.tsx b/src/pages/PerpsPage/FooterOrdersTable.tsx index 0861cdff2..3ff13e15b 100644 --- a/src/pages/PerpsPage/FooterOrdersTable.tsx +++ b/src/pages/PerpsPage/FooterOrdersTable.tsx @@ -61,7 +61,6 @@ const FooterOrdersTable: React.FC<{ const [o, { cancelOrder, cancelAlgoOrder, isLoading }] = useOrderStream({ symbol: token, status: orderStatus, - excludes: [AlgoOrderRootType.TP_SL, AlgoOrderRootType.POSITIONAL_TP_SL], }); const orders = o as Order[] | null;
({ + queryKey: [ 'useLiquidityHubQuote', fromToken, toToken, @@ -78,11 +78,6 @@ export const useLiquidityHubQuote = ({ allowedSlippage, chainId, ], - [fromToken, toToken, inAmount, allowedSlippage, chainId], - ); - - const query = useQuery({ - queryKey, queryFn: async ({ signal }) => { if (!fromToken || !toToken || !inAmount || !chainId || !allowedSlippage) { throw new Error('useLiquidityHubQuote Missing required parameters'); @@ -118,15 +113,14 @@ export const useLiquidityHubQuote = ({ isSupported, }); - const queryClient = useQueryClient(); + const refetch = useCallback(async () => { + return (await query.refetch()).data; + }, [query.refetch]); - return useMemo(() => { - return { - ...query, - getLatestQuote: () => queryClient.getQueryData(queryKey), - refetch: async () => (await query.refetch()).data, - }; - }, [query, queryClient, queryKey]); + return { + ...query, + refetch, + }; }; export const useGetBetterPrice = ( @@ -147,7 +141,7 @@ export const useGetBetterPrice = ( try { if (skip) return false; setSeekingBestPrice(true); - const quote = await promiseWithTimeout(fetchLiquidityHubQuote(), 5_000); + const quote = await promiseWithTimeout(fetchLiquidityHubQuote(), 8_000); const dexMinAmountOut = subtractSlippage(allowedSlippage, dexOutAmount) || 0; return BN(quote?.userMinOutAmountWithGas || 0).gt(dexMinAmountOut); diff --git a/src/components/Swap/orbs/utils.ts b/src/components/Swap/orbs/utils.ts index b6804525e..da66649cb 100644 --- a/src/components/Swap/orbs/utils.ts +++ b/src/components/Swap/orbs/utils.ts @@ -52,7 +52,7 @@ export const isRejectedError = (error: any) => { export const isTimeoutError = (error: any) => { const message = error.message?.toLowerCase(); - return message?.includes('timeout'); + return message === 'timeout'; }; export const makeElipsisAddress = (address?: string, padding = 6): string => { diff --git a/src/constants/abis/token-locker-abi.json b/src/constants/abis/token-locker-abi.json index 97c6cde7c..45797831a 100644 --- a/src/constants/abis/token-locker-abi.json +++ b/src/constants/abis/token-locker-abi.json @@ -1322,4 +1322,4 @@ "stateMutability": "nonpayable", "type": "function" } -] \ No newline at end of file +] diff --git a/src/pages/PerpsPage/FooterOrdersTable.tsx b/src/pages/PerpsPage/FooterOrdersTable.tsx index 0861cdff2..3ff13e15b 100644 --- a/src/pages/PerpsPage/FooterOrdersTable.tsx +++ b/src/pages/PerpsPage/FooterOrdersTable.tsx @@ -61,7 +61,6 @@ const FooterOrdersTable: React.FC<{ const [o, { cancelOrder, cancelAlgoOrder, isLoading }] = useOrderStream({ symbol: token, status: orderStatus, - excludes: [AlgoOrderRootType.TP_SL, AlgoOrderRootType.POSITIONAL_TP_SL], }); const orders = o as Order[] | null;
({ - queryKey, queryFn: async ({ signal }) => { if (!fromToken || !toToken || !inAmount || !chainId || !allowedSlippage) { throw new Error('useLiquidityHubQuote Missing required parameters'); @@ -118,15 +113,14 @@ export const useLiquidityHubQuote = ({ isSupported, }); - const queryClient = useQueryClient(); + const refetch = useCallback(async () => { + return (await query.refetch()).data; + }, [query.refetch]); - return useMemo(() => { - return { - ...query, - getLatestQuote: () => queryClient.getQueryData(queryKey), - refetch: async () => (await query.refetch()).data, - }; - }, [query, queryClient, queryKey]); + return { + ...query, + refetch, + }; }; export const useGetBetterPrice = ( @@ -147,7 +141,7 @@ export const useGetBetterPrice = ( try { if (skip) return false; setSeekingBestPrice(true); - const quote = await promiseWithTimeout(fetchLiquidityHubQuote(), 5_000); + const quote = await promiseWithTimeout(fetchLiquidityHubQuote(), 8_000); const dexMinAmountOut = subtractSlippage(allowedSlippage, dexOutAmount) || 0; return BN(quote?.userMinOutAmountWithGas || 0).gt(dexMinAmountOut); diff --git a/src/components/Swap/orbs/utils.ts b/src/components/Swap/orbs/utils.ts index b6804525e..da66649cb 100644 --- a/src/components/Swap/orbs/utils.ts +++ b/src/components/Swap/orbs/utils.ts @@ -52,7 +52,7 @@ export const isRejectedError = (error: any) => { export const isTimeoutError = (error: any) => { const message = error.message?.toLowerCase(); - return message?.includes('timeout'); + return message === 'timeout'; }; export const makeElipsisAddress = (address?: string, padding = 6): string => { diff --git a/src/constants/abis/token-locker-abi.json b/src/constants/abis/token-locker-abi.json index 97c6cde7c..45797831a 100644 --- a/src/constants/abis/token-locker-abi.json +++ b/src/constants/abis/token-locker-abi.json @@ -1322,4 +1322,4 @@ "stateMutability": "nonpayable", "type": "function" } -] \ No newline at end of file +] diff --git a/src/pages/PerpsPage/FooterOrdersTable.tsx b/src/pages/PerpsPage/FooterOrdersTable.tsx index 0861cdff2..3ff13e15b 100644 --- a/src/pages/PerpsPage/FooterOrdersTable.tsx +++ b/src/pages/PerpsPage/FooterOrdersTable.tsx @@ -61,7 +61,6 @@ const FooterOrdersTable: React.FC<{ const [o, { cancelOrder, cancelAlgoOrder, isLoading }] = useOrderStream({ symbol: token, status: orderStatus, - excludes: [AlgoOrderRootType.TP_SL, AlgoOrderRootType.POSITIONAL_TP_SL], }); const orders = o as Order[] | null;
(queryKey), - refetch: async () => (await query.refetch()).data, - }; - }, [query, queryClient, queryKey]); + return { + ...query, + refetch, + }; }; export const useGetBetterPrice = ( @@ -147,7 +141,7 @@ export const useGetBetterPrice = ( try { if (skip) return false; setSeekingBestPrice(true); - const quote = await promiseWithTimeout(fetchLiquidityHubQuote(), 5_000); + const quote = await promiseWithTimeout(fetchLiquidityHubQuote(), 8_000); const dexMinAmountOut = subtractSlippage(allowedSlippage, dexOutAmount) || 0; return BN(quote?.userMinOutAmountWithGas || 0).gt(dexMinAmountOut); diff --git a/src/components/Swap/orbs/utils.ts b/src/components/Swap/orbs/utils.ts index b6804525e..da66649cb 100644 --- a/src/components/Swap/orbs/utils.ts +++ b/src/components/Swap/orbs/utils.ts @@ -52,7 +52,7 @@ export const isRejectedError = (error: any) => { export const isTimeoutError = (error: any) => { const message = error.message?.toLowerCase(); - return message?.includes('timeout'); + return message === 'timeout'; }; export const makeElipsisAddress = (address?: string, padding = 6): string => { diff --git a/src/constants/abis/token-locker-abi.json b/src/constants/abis/token-locker-abi.json index 97c6cde7c..45797831a 100644 --- a/src/constants/abis/token-locker-abi.json +++ b/src/constants/abis/token-locker-abi.json @@ -1322,4 +1322,4 @@ "stateMutability": "nonpayable", "type": "function" } -] \ No newline at end of file +] diff --git a/src/pages/PerpsPage/FooterOrdersTable.tsx b/src/pages/PerpsPage/FooterOrdersTable.tsx index 0861cdff2..3ff13e15b 100644 --- a/src/pages/PerpsPage/FooterOrdersTable.tsx +++ b/src/pages/PerpsPage/FooterOrdersTable.tsx @@ -61,7 +61,6 @@ const FooterOrdersTable: React.FC<{ const [o, { cancelOrder, cancelAlgoOrder, isLoading }] = useOrderStream({ symbol: token, status: orderStatus, - excludes: [AlgoOrderRootType.TP_SL, AlgoOrderRootType.POSITIONAL_TP_SL], }); const orders = o as Order[] | null;