From 3c79fc214656f1b2b818efd171de7c0da3d3f893 Mon Sep 17 00:00:00 2001 From: vuonghuuhung Date: Thu, 26 Sep 2024 14:28:03 +0700 Subject: [PATCH] query indexer & resolve conversation --- .../components/CreatePositionForm/index.tsx | 15 +++++++++++---- src/pages/Pool-V3/components/ZapOutForm/index.tsx | 2 +- src/pages/Pool-V3/hooks/useGetPoolDetail.ts | 4 ++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/pages/Pool-V3/components/CreatePositionForm/index.tsx b/src/pages/Pool-V3/components/CreatePositionForm/index.tsx index 037db3dbf..1e88db5d8 100644 --- a/src/pages/Pool-V3/components/CreatePositionForm/index.tsx +++ b/src/pages/Pool-V3/components/CreatePositionForm/index.tsx @@ -191,9 +191,16 @@ const CreatePositionForm: FC = ({ const [amountTo, setAmountTo] = useState(); const [amountFrom, setAmountFrom] = useState(); - const fromUsd = (extendPrices?.[tokenFrom?.coinGeckoId] * Number(amountFrom || 0)).toFixed(6); - const toUsd = (extendPrices?.[tokenTo?.coinGeckoId] * Number(amountTo || 0)).toFixed(6); - const zapUsd = (extendPrices?.[tokenZap?.coinGeckoId] * Number(zapAmount || 0)).toFixed(6); + const fromUsd = extendPrices?.[tokenFrom?.coinGeckoId] + ? (extendPrices[tokenFrom.coinGeckoId] * Number(amountFrom || 0)).toFixed(6) + : '0'; + const toUsd = extendPrices?.[tokenTo?.coinGeckoId] + ? (extendPrices[tokenTo.coinGeckoId] * Number(amountTo || 0)).toFixed(6) + : '0'; + const zapUsd = extendPrices?.[tokenZap?.coinGeckoId] + ? (extendPrices[tokenZap.coinGeckoId] * Number(zapAmount || 0)).toFixed(6) + : '0'; + const xUsd = zapInResponse && (extendPrices?.[tokenFrom?.coinGeckoId] * (Number(zapInResponse.amountX || 0) / 10 ** tokenFrom.decimals)).toFixed( @@ -952,7 +959,7 @@ const CreatePositionForm: FC = ({ if (error instanceof RouteNotFoundError) { setZapError('No route found, try other tokens or other amount'); } else if (error instanceof RouteNoLiquidity) { - setZapError("No liquidity found for the swap route. Cannot proceed with the swap."); + setZapError('No liquidity found for the swap route. Cannot proceed with the swap.'); } else if (error instanceof SpamTooManyRequestsError) { setZapError('Too many requests, please try again later, after 1 minute'); } else { diff --git a/src/pages/Pool-V3/components/ZapOutForm/index.tsx b/src/pages/Pool-V3/components/ZapOutForm/index.tsx index 319c61ec0..09038ac3f 100644 --- a/src/pages/Pool-V3/components/ZapOutForm/index.tsx +++ b/src/pages/Pool-V3/components/ZapOutForm/index.tsx @@ -344,7 +344,7 @@ const ZapOutForm: FC = ({ if (incentives) { Object.keys(incentives).forEach((key) => { - const token = oraichainTokens.find((e) => extractAddress(e ) === key); + const token = oraichainTokens.find((e) => extractAddress(e) === key); receiveIncentiveTokens.push({ icon: getIcon({ isLightTheme, diff --git a/src/pages/Pool-V3/hooks/useGetPoolDetail.ts b/src/pages/Pool-V3/hooks/useGetPoolDetail.ts index 44a5b5101..e24f07af8 100644 --- a/src/pages/Pool-V3/hooks/useGetPoolDetail.ts +++ b/src/pages/Pool-V3/hooks/useGetPoolDetail.ts @@ -2,7 +2,7 @@ import { useQuery } from '@tanstack/react-query'; import { CoinGeckoPrices } from 'hooks/useCoingecko'; import { PoolFeeAndLiquidityDaily } from 'libs/contractSingleton'; import { useEffect, useState } from 'react'; -import { FeeDailyData, getFeeDailyData, getPoolDetail, getPoolDetailFromBackend, PoolDetail } from 'rest/graphClient'; +import { FeeDailyData, getFeeDailyData, getPoolDetail, PoolDetail } from 'rest/graphClient'; import { toDisplay } from '@oraichain/oraidex-common'; export type LiquidityDistribution = { @@ -24,7 +24,7 @@ export const useGetPoolDetail = (poolKey: string, prices: CoinGeckoPrices(['pool-v3-detail'], () => getPoolDetailFromBackend(poolKey), { + const { data, refetch: refetchPoolDetail } = useQuery(['pool-v3-detail'], () => getPoolDetail(poolKey), { refetchOnWindowFocus: false, placeholderData: null, // cacheTime: 5 * 60 * 1000