diff --git a/apps/web/src/state/info/hooks.ts b/apps/web/src/state/info/hooks.ts index 7c87264d6e288..dc9e8704e96f6 100644 --- a/apps/web/src/state/info/hooks.ts +++ b/apps/web/src/state/info/hooks.ts @@ -6,13 +6,11 @@ import { useCallback, useEffect, useMemo, useState } from 'react' import { STABLE_SUPPORTED_CHAIN_IDS } from '@pancakeswap/stable-swap-sdk' import { keepPreviousData, useQuery } from '@tanstack/react-query' import BigNumber from 'bignumber.js' -import { fetchAllTokenData, fetchAllTokenDataByAddresses } from 'state/info/queries/tokens/tokenData' +import { fetchAllTokenDataByAddresses } from 'state/info/queries/tokens/tokenData' import { Block, Transaction, TransactionType, TvlChartEntry, VolumeChartEntry } from 'state/info/types' import { getAprsForStableFarm } from 'utils/getAprsForStableFarm' -import { getDeltaTimestamps } from 'utils/getDeltaTimestamps' import { getLpFeesAndApr } from 'utils/getLpFeesAndApr' import { getPercentChange } from 'utils/infoDataHelpers' -import { useBlocksFromTimestamps } from 'views/Info/hooks/useBlocksFromTimestamps' import { explorerApiClient } from './api/client' import { useExplorerChainNameByQuery } from './api/hooks' import { operations } from './api/schema' @@ -561,40 +559,6 @@ export const usePoolTransactionsQuery = (address: string): Transaction[] | undef // Tokens hooks -export const useAllTokenHighLight = ({ - enable, - targetChainName, -}: { - enable?: boolean - targetChainName?: MultiChainNameExtend -}): TokenData[] => { - const chainNameByQuery = useChainNameByQuery() - const chainName = targetChainName ?? chainNameByQuery - const [t24h, t48h, t7d, t14d] = getDeltaTimestamps() - const { blocks } = useBlocksFromTimestamps([t24h, t48h, t7d, t14d], undefined, chainName) - const type = checkIsStableSwap() ? 'stableSwap' : 'swap' - const { data, isPending } = useQuery({ - queryKey: [`info/token/data/${type}`, chainName], - queryFn: () => fetchAllTokenData(chainName, blocks ?? []), - enabled: Boolean(enable && blocks && chainName), - ...QUERY_SETTINGS_IMMUTABLE, - ...QUERY_SETTINGS_WITHOUT_INTERVAL_REFETCH, - }) - - const tokensWithData = useMemo(() => { - return data - ? Object.keys(data) - .map((k) => { - return data?.[k]?.data - }) - .filter((d) => d && d.exists) - : [] - }, [data]) - return useMemo(() => { - return isPending ? [] : tokensWithData ?? [] - }, [isPending, tokensWithData]) -} - export const useAllTokenDataQuery = (): { [address: string]: { data?: TokenData } } => { @@ -678,42 +642,6 @@ const fetcher = (addresses: string[], chainName: MultiChainName, blocks: Block[] return Promise.all(addressGroup.map((d) => fetchAllTokenDataByAddresses(chainName, blocks, d))) } -/** - * @deprecated - */ -export const useTokenDatasQuery = (addresses?: string[], withSettings = true): TokenData[] | undefined => { - const name = addresses?.join('') - const chainName = useChainNameByQuery() - const [t24h, t48h, t7d, t14d] = getDeltaTimestamps() - const { blocks } = useBlocksFromTimestamps([t24h, t48h, t7d, t14d]) - const type = checkIsStableSwap() ? 'stableSwap' : 'swap' - const { data, isPending } = useQuery({ - queryKey: [`info/token/data/${name}/${type}`, chainName], - queryFn: () => fetcher(addresses || [], chainName, blocks ?? []), - enabled: Boolean(blocks && chainName), - ...QUERY_SETTINGS_IMMUTABLE, - ...(withSettings ? QUERY_SETTINGS_INTERVAL_REFETCH : QUERY_SETTINGS_WITHOUT_INTERVAL_REFETCH), - }) - const allData = useMemo(() => { - return data && data.length > 0 - ? data.reduce((a, b) => { - return { ...a, ...b } - }, {}) - : {} - }, [data]) - - const tokensWithData = useMemo(() => { - if (!addresses && allData) { - return undefined - } - return addresses?.map((a) => allData?.[a]?.data)?.filter((d) => d && d.exists) - }, [addresses, allData]) - - return useMemo(() => { - return isPending ? [] : tokensWithData ?? undefined - }, [isPending, tokensWithData]) -} - export const useTokenDataQuery = (address: string | undefined): TokenData | undefined => { const chainName = useExplorerChainNameByQuery() const chainId = useChainIdByQuery() diff --git a/apps/web/src/state/info/utils.ts b/apps/web/src/state/info/utils.ts index 744bf5e468d76..54ce28635ea38 100644 --- a/apps/web/src/state/info/utils.ts +++ b/apps/web/src/state/info/utils.ts @@ -17,15 +17,3 @@ export function getTokenInfoPath( multiChainPaths[chainId ?? ''] }/tokens/${address}?chain=${CHAIN_QUERY_NAME[chainId ?? '']}${stableSwapPath.replace('?', '&')}` } - -// TODO: refactor -export function getChainName(chainId: ChainId) { - switch (chainId) { - case ChainId.BSC: - return 'BSC' - case ChainId.ETHEREUM: - return 'ETH' - default: - return 'BSC' - } -} diff --git a/apps/web/src/views/Info/hooks/useBlocksFromTimestamps.ts b/apps/web/src/views/Info/hooks/useBlocksFromTimestamps.ts deleted file mode 100644 index a20dd7209e298..0000000000000 --- a/apps/web/src/views/Info/hooks/useBlocksFromTimestamps.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { useQuery } from '@tanstack/react-query' -import { MultiChainNameExtend, multiChainId, multiChainName } from 'state/info/constant' -import { useChainNameByQuery } from 'state/info/hooks' -import { getBlocksFromTimestamps } from 'utils/getBlocksFromTimestamps' - -export const useBlocksFromTimestamps = ( - timestamps: number[], - sortDirection: 'asc' | 'desc' | undefined = 'desc', - targetChainName?: MultiChainNameExtend, -) => { - const chainNameByQuery = useChainNameByQuery() - const chainName = targetChainName ?? chainNameByQuery - const chainId = multiChainId[chainName] - const timestampsString = JSON.stringify(timestamps) - const timestampsArray = JSON.parse(timestampsString) - const { data } = useQuery({ - queryKey: [`info/blocks/${timestampsString}/${chainId}`, multiChainName[chainId] ?? chainName], - queryFn: () => getBlocksFromTimestamps(timestampsArray, sortDirection, chainName), - refetchOnReconnect: false, - refetchOnMount: false, - refetchOnWindowFocus: false, - }) - return { blocks: data } -} diff --git a/apps/web/src/views/V3Info/constants.ts b/apps/web/src/views/V3Info/constants.ts index 4f345d47e9be8..6b0d947d572fc 100644 --- a/apps/web/src/views/V3Info/constants.ts +++ b/apps/web/src/views/V3Info/constants.ts @@ -54,17 +54,6 @@ export const ONE_HOUR_SECONDS = 3600 export const ONE_DAY_SECONDS = 86400 export const MAX_UINT128 = 2n ** 128n - 1n -export const SUBGRAPH_START_BLOCK = { - [ChainId.BSC]: 26956207, - [ChainId.ETHEREUM]: 16950686, - [ChainId.POLYGON_ZKEVM]: 750149, - [ChainId.ZKSYNC]: 8639214, - [ChainId.ARBITRUM_ONE]: 101028949, - [ChainId.LINEA]: 1444, - [ChainId.BASE]: 2912007, - [ChainId.OPBNB]: 1721753, -} - export const NODE_REAL_ADDRESS_LIMIT = 50 export const DURATION_INTERVAL = { diff --git a/apps/web/src/views/V3Info/hooks/index.ts b/apps/web/src/views/V3Info/hooks/index.ts index ca1902e0f640c..fec430f320b1a 100644 --- a/apps/web/src/views/V3Info/hooks/index.ts +++ b/apps/web/src/views/V3Info/hooks/index.ts @@ -4,17 +4,12 @@ import { useMemo } from 'react' import { multiChainId } from 'state/info/constant' import { useChainNameByQuery } from 'state/info/hooks' import { Block } from 'state/info/types' -import { getChainName } from 'state/info/utils' -import { getDeltaTimestamps } from 'utils/getDeltaTimestamps' -import { v3InfoClients } from 'utils/graphql' -import { useBlocksFromTimestamps } from 'views/Info/hooks/useBlocksFromTimestamps' import { keepPreviousData, useQuery } from '@tanstack/react-query' import { chainIdToExplorerInfoChainName, explorerApiClient } from 'state/info/api/client' import { useExplorerChainNameByQuery } from 'state/info/api/hooks' import { components } from 'state/info/api/schema' import { getPercentChange } from 'views/V3Info/utils/data' -import { SUBGRAPH_START_BLOCK } from '../constants' import { fetchPoolChartData } from '../data/pool/chartData' import { fetchedPoolData } from '../data/pool/poolData' import { PoolTickData, fetchTicksSurroundingPrice } from '../data/pool/tickData' @@ -208,40 +203,6 @@ const tokenDataFetcher = (dataClient: GraphQLClient, tokenAddresses: string[], b return Promise.all(addressGroup.map((d) => fetchedTokenDatas(dataClient, d, blocks))) } -/** - * @deprecated - */ -export const useTokensData = (addresses: string[], targetChainId?: ChainId): TokenData[] | undefined => { - const chainName = useChainNameByQuery() - const chainId = targetChainId ?? multiChainId[chainName] - const [t24, t48, t7d] = getDeltaTimestamps() - const { blocks } = useBlocksFromTimestamps([t24, t48, t7d], undefined, getChainName(chainId)) - - const { data } = useQuery({ - queryKey: [`v3/info/token/tokensData/${targetChainId}/${addresses?.join()}`, chainId], - - queryFn: () => - tokenDataFetcher( - v3InfoClients[chainId], // TODO: v3InfoClients[chainId], - addresses, - blocks?.filter((d) => d.number >= SUBGRAPH_START_BLOCK[chainId]), - ), - - enabled: Boolean(chainId && blocks && addresses && addresses?.length > 0 && blocks?.length > 0), - ...QUERY_SETTINGS_IMMUTABLE, - }) - const allTokensData = useMemo(() => { - if (data) { - return data.reduce((acc, d) => { - return { ...acc, ...d.data } - }, {}) - } - return undefined - }, [data]) - - return useMemo(() => (allTokensData ? Object.values(allTokensData) : undefined), [allTokensData]) -} - export const useTokenData = (address: string): TokenData | undefined => { const chainName = useChainNameByQuery() const chainId = multiChainId[chainName]