Skip to content

Commit

Permalink
chore: Remove unused info hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
memoyil committed Jan 7, 2025
1 parent 8615f7e commit 135423d
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 159 deletions.
74 changes: 1 addition & 73 deletions apps/web/src/state/info/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 }
} => {
Expand Down Expand Up @@ -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()
Expand Down
12 changes: 0 additions & 12 deletions apps/web/src/state/info/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}
24 changes: 0 additions & 24 deletions apps/web/src/views/Info/hooks/useBlocksFromTimestamps.ts

This file was deleted.

11 changes: 0 additions & 11 deletions apps/web/src/views/V3Info/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
39 changes: 0 additions & 39 deletions apps/web/src/views/V3Info/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 135423d

Please sign in to comment.