Commit 801958d0 authored by cartcrom's avatar cartcrom Committed by GitHub

fix: skip when address undefined (#6172)

* fix: skip when address undefined

* fix: add back lowercase

* fix: use ms

* update loading var name
parent 8392c29a
import { useQuery } from '@apollo/client'
import gql from 'graphql-tag'
import { useMemo } from 'react'
import { AllV3TicksQuery } from './__generated__/types-and-hooks'
import { apolloClient } from './apollo'
const query = gql`
query AllV3Ticks($poolAddress: String!, $skip: Int!) {
gql`
query AllV3Ticks($poolAddress: String, $skip: Int!) {
ticks(first: 1000, skip: $skip, where: { poolAddress: $poolAddress }, orderBy: tickIdx) {
tick: tickIdx
liquidityNet
......@@ -18,27 +15,3 @@ const query = gql`
export type Ticks = AllV3TicksQuery['ticks']
export type TickData = Ticks[number]
export default function useAllV3TicksQuery(poolAddress: string | undefined, skip: number, interval: number) {
const {
data,
loading: isLoading,
error,
} = useQuery<Record<'ticks', Ticks>>(query, {
variables: {
poolAddress: poolAddress?.toLowerCase(),
skip,
},
pollInterval: interval,
client: apolloClient,
})
return useMemo(
() => ({
error,
isLoading,
data,
}),
[data, error, isLoading]
)
}
......@@ -3,7 +3,8 @@ import { FeeAmount, nearestUsableTick, Pool, TICK_SPACINGS, tickToPrice } from '
import { useWeb3React } from '@web3-react/core'
import { SupportedChainId } from 'constants/chains'
import { ZERO_ADDRESS } from 'constants/misc'
import useAllV3TicksQuery, { TickData, Ticks } from 'graphql/thegraph/AllV3TicksQuery'
import { useAllV3TicksQuery } from 'graphql/thegraph/__generated__/types-and-hooks'
import { TickData, Ticks } from 'graphql/thegraph/AllV3TicksQuery'
import JSBI from 'jsbi'
import { useSingleContractMultipleData } from 'lib/hooks/multicall'
import ms from 'ms.macro'
......@@ -155,7 +156,11 @@ function useTicksFromSubgraph(
)
: undefined
return useAllV3TicksQuery(poolAddress, skip, ms`30s`)
return useAllV3TicksQuery({
variables: { poolAddress: poolAddress?.toLowerCase(), skip },
skip: !poolAddress,
pollInterval: ms`30s`,
})
}
const MAX_THE_GRAPH_TICK_FETCH_VALUE = 1000
......@@ -175,12 +180,11 @@ function useAllV3Ticks(
const [skipNumber, setSkipNumber] = useState(0)
const [subgraphTickData, setSubgraphTickData] = useState<Ticks>([])
const { data, error, isLoading } = useTicksFromSubgraph(
useSubgraph ? currencyA : undefined,
currencyB,
feeAmount,
skipNumber
)
const {
data,
error,
loading: isLoading,
} = useTicksFromSubgraph(useSubgraph ? currencyA : undefined, currencyB, feeAmount, skipNumber)
useEffect(() => {
if (data?.ticks.length) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment