From 7f2cc9a3e6ee1bb61d4d3ff55ad509b56ec85928 Mon Sep 17 00:00:00 2001 From: Jordan Frankfurt Date: Wed, 21 Sep 2022 15:35:17 -0500 Subject: [PATCH] feat: add tvl to token details page (#4692) * add tvl to token details page * remove mcap, add explanation of market entities --- .../Tokens/TokenDetails/StatsSection.tsx | 11 +++++----- src/graphql/data/Token.ts | 15 ++++++++++++- src/pages/TokenDetails/index.tsx | 21 ++++++++++--------- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/components/Tokens/TokenDetails/StatsSection.tsx b/src/components/Tokens/TokenDetails/StatsSection.tsx index e2bd29454f..35f024d467 100644 --- a/src/components/Tokens/TokenDetails/StatsSection.tsx +++ b/src/components/Tokens/TokenDetails/StatsSection.tsx @@ -42,17 +42,18 @@ function Stat({ value, title }: { value: NumericStat; title: ReactNode }) { } type StatsSectionProps = { - marketCap?: NumericStat - volume24H?: NumericStat priceLow52W?: NumericStat priceHigh52W?: NumericStat + TVL?: NumericStat + volume24H?: NumericStat } -export default function StatsSection({ marketCap, volume24H, priceLow52W, priceHigh52W }: StatsSectionProps) { - if (marketCap || volume24H || priceLow52W || priceHigh52W) { +export default function StatsSection(props: StatsSectionProps) { + const { priceLow52W, priceHigh52W, TVL, volume24H } = props + if (TVL || volume24H || priceLow52W || priceHigh52W) { return ( - Market Cap} /> + Total Value Locked} /> 24H volume} /> diff --git a/src/graphql/data/Token.ts b/src/graphql/data/Token.ts index 4077e6e291..f6ac3ec033 100644 --- a/src/graphql/data/Token.ts +++ b/src/graphql/data/Token.ts @@ -25,7 +25,14 @@ const tokenPricesFragment = graphql` } } ` - +/* +The difference between Token and TokenProject: + Token: an on-chain entity referring to a contract (e.g. uni token on ethereum 0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984) + TokenProject: an off-chain, aggregated entity that consists of a token and its bridged tokens (e.g. uni token on all chains) + TokenMarket and TokenProjectMarket then are market data entities for the above. + TokenMarket is per-chain market data for contracts pulled from the graph. + TokenProjectMarket is aggregated market data (aggregated over multiple dexes and centralized exchanges) that we get from coingecko. +*/ const tokenQuery = graphql` query TokenQuery($contract: ContractInput!, $duration: HistoryDuration!, $skip: Boolean = false) { tokenProjects(contracts: [$contract]) @skip(if: $skip) { @@ -37,6 +44,12 @@ const tokenQuery = graphql` chain address symbol + market { + totalValueLocked { + value + currency + } + } } prices: markets(currencies: [USD]) { ...TokenPrices diff --git a/src/pages/TokenDetails/index.tsx b/src/pages/TokenDetails/index.tsx index 18b5f96e65..480a1114f9 100644 --- a/src/pages/TokenDetails/index.tsx +++ b/src/pages/TokenDetails/index.tsx @@ -149,8 +149,9 @@ export default function TokenDetails() { }) : null - const tokenData = query.tokenProjects?.[0] - const tokenDetails = tokenData?.markets?.[0] + const tokenProject = query.tokenProjects?.[0] + const tokenProjectMarket = tokenProject?.markets?.[0] + const tokenMarket = tokenProject?.tokens[0].market // TODO: Fix this logic to not automatically redirect on refresh, yet still catch invalid addresses //const location = useLocation() @@ -166,18 +167,18 @@ export default function TokenDetails() { Tokens - +