From 52d5e2ef05a3ecbbb3cd71a99bfde94310715e1c Mon Sep 17 00:00:00 2001 From: chefjackson <116779127+chefjackson@users.noreply.github.com> Date: Tue, 10 Sep 2024 12:00:56 +0800 Subject: [PATCH] fix: not able to get quote from exact output --- apps/web/src/hooks/useBestAMMTrade.ts | 5 +++-- .../src/views/Swap/V3Swap/containers/SwapCommitButton.tsx | 3 +-- apps/web/src/views/Swap/V3Swap/hooks/useSwapBestTrade.ts | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/web/src/hooks/useBestAMMTrade.ts b/apps/web/src/hooks/useBestAMMTrade.ts index c6e19088dbb689..abdc0a45482a49 100644 --- a/apps/web/src/hooks/useBestAMMTrade.ts +++ b/apps/web/src/hooks/useBestAMMTrade.ts @@ -589,10 +589,11 @@ export function useBestTradeFromApi({ }) const serializedRes = await serverRes.json() + const isExactIn = tradeType === TradeType.EXACT_INPUT const result = parseQuoteResponse(serializedRes, { chainId: currency.chainId, - currencyIn: amount.currency, - currencyOut: currency, + currencyIn: isExactIn ? amount.currency : currency, + currencyOut: isExactIn ? currency : amount.currency, tradeType, }) diff --git a/apps/web/src/views/Swap/V3Swap/containers/SwapCommitButton.tsx b/apps/web/src/views/Swap/V3Swap/containers/SwapCommitButton.tsx index 94fe9d55bc0b8d..cf78a98adda22b 100644 --- a/apps/web/src/views/Swap/V3Swap/containers/SwapCommitButton.tsx +++ b/apps/web/src/views/Swap/V3Swap/containers/SwapCommitButton.tsx @@ -39,7 +39,6 @@ interface SwapCommitButtonPropsType { order?: PriceOrder tradeError?: Error | null tradeLoading?: boolean - // setLock: (lock: boolean) => void } const useSettingModal = (onDismiss) => { @@ -163,7 +162,7 @@ const SwapCommitButtonInner = memo(function SwapCommitButtonInner({ } const parsedAmounts = useParsedAmounts(order?.trade, currencyBalances, false) const parsedIndependentFieldAmount = parsedAmounts[independentField] - const swapInputError = useSwapInputError(isClassicOrder(order) ? order : undefined, currencyBalances) + const swapInputError = useSwapInputError(order, currencyBalances) const [tradeToConfirm, setTradeToConfirm] = useState(undefined) const [indirectlyOpenConfirmModalState, setIndirectlyOpenConfirmModalState] = useState(false) diff --git a/apps/web/src/views/Swap/V3Swap/hooks/useSwapBestTrade.ts b/apps/web/src/views/Swap/V3Swap/hooks/useSwapBestTrade.ts index 836bf36c2f097f..c62b034f9d2fc8 100644 --- a/apps/web/src/views/Swap/V3Swap/hooks/useSwapBestTrade.ts +++ b/apps/web/src/views/Swap/V3Swap/hooks/useSwapBestTrade.ts @@ -46,7 +46,7 @@ export function useSwapBestOrder({ maxHops }: Options = {}) { const [xEnabled] = useUserXEnable() - const { isLoading, data, isStale, error, refetch } = useBestTradeFromApi({ + const { fetchStatus, data, isStale, error, refetch } = useBestTradeFromApi({ enabled: xEnabled, amount, currency: dependentCurrency, @@ -65,7 +65,7 @@ export function useSwapBestOrder({ maxHops }: Options = {}) { refresh: refetch, isStale, error, - isLoading: useDeferredValue(Boolean(isLoading || (typedValue && !data && !error))), + isLoading: useDeferredValue(Boolean(fetchStatus === 'fetching' || (typedValue && !data && !error))), order: typedValue ? data : undefined, } }