Skip to content

Commit d565e9b

Browse files
committed
Analytics first look
1 parent bd53155 commit d565e9b

File tree

6 files changed

+885
-3
lines changed

6 files changed

+885
-3
lines changed

apps/kyberswap-interface/.env.production

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ VITE_REFERRAL_URL=https://referral.kyberswap.com/api
4545

4646
VITE_TOKEN_API_URL=https://token-api.kyberswap.com/api
4747
VITE_ZAP_EARN_URL=https://earn-service.kyberswap.com/api
48+
VITE_ZAP_EARN_ANALYTICS_URL=https://pre-zap-earn-service.kyberengineering.io/api
4849

4950
VITE_AFFILIATE_SERVICE=https://affiliate-service.kyberswap.com/api
5051
VITE_SOLANA_RPC=https://solana.kyberengineering.io

apps/kyberswap-interface/src/pages/Earns/PoolDetail/tabs/AnalyticsTab.tsx

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,91 @@
1+
import { useMemo, useState } from 'react'
12
import { Text } from 'rebass'
3+
import { type PoolAnalyticsWindow, usePoolLiquidityFlowsQuery, usePoolPriceQuery } from 'services/zapEarn'
24

5+
import { Stack } from 'components/Stack'
36
import useTheme from 'hooks/useTheme'
7+
import { usePoolDetailContext } from 'pages/Earns/PoolDetail/context'
8+
import LiquidityFlowsChart from 'pages/Earns/PoolDetail/tabs/analytics/LiquidityFlowsChart'
9+
import PoolPriceChart from 'pages/Earns/PoolDetail/tabs/analytics/PoolPriceChart'
10+
import { MetricCard, MetricsStrip, formatNumber, formatUsd } from 'pages/Earns/PoolDetail/tabs/analytics/shared'
411

512
const AnalyticsTab = () => {
613
const theme = useTheme()
14+
const { pool, poolParams } = usePoolDetailContext()
15+
const [window, setWindow] = useState<PoolAnalyticsWindow>('7d')
16+
17+
const {
18+
data: priceAnalytics,
19+
isError: isPriceError,
20+
isLoading: isPriceLoading,
21+
} = usePoolPriceQuery({
22+
chainId: poolParams.poolChainId,
23+
address: poolParams.poolAddress,
24+
window,
25+
})
26+
27+
const {
28+
data: liquidityFlows,
29+
isError: isLiquidityFlowsError,
30+
isLoading: isLiquidityFlowsLoading,
31+
} = usePoolLiquidityFlowsQuery({
32+
chainId: poolParams.poolChainId,
33+
address: poolParams.poolAddress,
34+
window,
35+
})
36+
37+
const currentLiquidityBucket = liquidityFlows?.buckets?.[liquidityFlows.buckets.length - 1]
38+
39+
const totalTvl = useMemo(() => {
40+
if (pool?.tvl !== undefined) return pool.tvl
41+
if (pool?.poolStats?.tvl !== undefined) return pool.poolStats.tvl
42+
if (pool?.reserveUsd !== undefined) {
43+
const parsedReserveUsd = Number(pool.reserveUsd)
44+
if (!Number.isNaN(parsedReserveUsd)) return parsedReserveUsd
45+
}
46+
47+
return undefined
48+
}, [pool?.poolStats?.tvl, pool?.reserveUsd, pool?.tvl])
49+
50+
const metrics = [
51+
{ label: 'TVL', value: formatUsd(totalTvl) },
52+
{ label: 'Current TVL', value: formatUsd(currentLiquidityBucket?.tvlUsd ?? totalTvl) },
53+
{ label: 'Liquidity Provider', value: formatNumber(pool?.liquidity) },
54+
]
755

856
return (
9-
<Text as="div" color={theme.subText} fontSize={14}>
10-
Analytics content will be updated when the final data and design are ready.
11-
</Text>
57+
<Stack gap={16}>
58+
<MetricsStrip>
59+
{metrics.map(metric => (
60+
<MetricCard gap={4} key={metric.label}>
61+
<Text color={theme.subText} fontSize={14}>
62+
{metric.label}
63+
</Text>
64+
<Text color={theme.text} fontSize={20} fontWeight={500}>
65+
{metric.value}
66+
</Text>
67+
</MetricCard>
68+
))}
69+
</MetricsStrip>
70+
71+
<PoolPriceChart
72+
analytics={priceAnalytics}
73+
baseSymbol={pool.tokens[0]?.symbol}
74+
isError={isPriceError}
75+
isLoading={isPriceLoading}
76+
onSelectWindow={setWindow}
77+
quoteSymbol={pool.tokens[1]?.symbol}
78+
window={window}
79+
/>
80+
81+
<LiquidityFlowsChart
82+
analytics={liquidityFlows}
83+
isError={isLiquidityFlowsError}
84+
isLoading={isLiquidityFlowsLoading}
85+
onSelectWindow={setWindow}
86+
window={window}
87+
/>
88+
</Stack>
1289
)
1390
}
1491

0 commit comments

Comments
 (0)