forked from Uniswap/interface
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(pool): use agnostic ticks query for liquidity chart
- Loading branch information
1 parent
2031a50
commit 1e7c705
Showing
3 changed files
with
70 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { useQuery } from '@apollo/client' | ||
import { gql } from 'graphql-tag' | ||
import { AllV3TicksQuery } from 'graphql/thegraph/__generated__/types-and-hooks' | ||
import ms from 'ms' | ||
import { useMemo } from 'react' | ||
import { client } from '../client' | ||
|
||
const POOL_TICKS_QUERY = gql` | ||
query PoolTicksQuery($poolAddress: String = "") { | ||
explore_pool_liquidity(pool_address: $poolAddress) { | ||
tick | ||
liquidity_net | ||
price0 | ||
price1 | ||
} | ||
} | ||
` | ||
|
||
type PoolTicksQuery = { | ||
explore_pool_liquidity?: { | ||
tick: string | ||
liquidity_net: string | ||
price0: string | ||
price1: string | ||
}[] | ||
} | ||
|
||
type PoolTicksVariables = { | ||
poolAddress?: string | ||
} | ||
|
||
// eslint-disable-next-line import/no-unused-modules | ||
export function usePoolTicksQuery(poolAddress?: string, skip = false) { | ||
const { data, ...rest } = useQuery<PoolTicksQuery, PoolTicksVariables>(POOL_TICKS_QUERY, { | ||
client, | ||
variables: { poolAddress }, | ||
skip: !poolAddress || skip, | ||
pollInterval: ms(`30s`), | ||
context: { | ||
headers: { | ||
'Cache-control': 'no-cache', | ||
}, | ||
}, | ||
}) | ||
|
||
return { ...rest, data: useMemo(() => transform(data), [data]) } | ||
} | ||
|
||
function transform(data?: PoolTicksQuery): AllV3TicksQuery | undefined { | ||
if (!data?.explore_pool_liquidity) return undefined | ||
|
||
return { | ||
ticks: data.explore_pool_liquidity.map((t) => ({ | ||
liquidityNet: t.liquidity_net, | ||
price0: t.price0, | ||
price1: t.price1, | ||
tick: t.tick, | ||
})), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters