Skip to content

Commit 894102b

Browse files
committed
Update charts
Update charts Update loading Add Skeleton Update loading skeleton
1 parent ea788ce commit 894102b

File tree

11 files changed

+345
-88
lines changed

11 files changed

+345
-88
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { type ComponentProps } from 'react'
2+
import LoadingSkeleton from 'react-loading-skeleton'
3+
import { createGlobalStyle } from 'styled-components'
4+
5+
import useTheme from 'hooks/useTheme'
6+
7+
export type SkeletonProps = ComponentProps<typeof LoadingSkeleton>
8+
9+
const SKELETON_CONTAINER_CLASSNAME = 'ks-skeleton-container'
10+
11+
const SkeletonGlobalStyle = createGlobalStyle`
12+
.${SKELETON_CONTAINER_CLASSNAME} {
13+
display: block;
14+
line-height: 0;
15+
}
16+
`
17+
18+
const Skeleton = ({ baseColor, containerClassName, highlightColor, ...props }: SkeletonProps) => {
19+
const theme = useTheme()
20+
const mergedContainerClassName = containerClassName
21+
? `${SKELETON_CONTAINER_CLASSNAME} ${containerClassName}`
22+
: SKELETON_CONTAINER_CLASSNAME
23+
24+
return (
25+
<>
26+
<SkeletonGlobalStyle />
27+
<LoadingSkeleton
28+
{...props}
29+
baseColor={baseColor ?? theme.background}
30+
containerClassName={mergedContainerClassName}
31+
highlightColor={highlightColor ?? theme.buttonGray}
32+
/>
33+
</>
34+
)
35+
}
36+
37+
export default Skeleton

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

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,16 @@
1-
import { useState } from 'react'
2-
31
import { Stack } from 'components/Stack'
4-
import { formatUsd, getPoolLiquidityUsd } from 'pages/Earns/PoolDetail/Information/utils'
52
import LiquidityFlowsChart from 'pages/Earns/PoolDetail/components/LiquidityFlowsChart'
63
import PoolPriceChart from 'pages/Earns/PoolDetail/components/PoolPriceChart'
7-
import TopMetricsStrip from 'pages/Earns/PoolDetail/components/TopMetricsStrip'
84
import { usePoolDetailContext } from 'pages/Earns/PoolDetail/context'
9-
import { useTokenPrices } from 'state/tokenPrices/hooks'
105

116
const AnalyticsTab = () => {
12-
const { chainId, pool, poolAddress } = usePoolDetailContext()
13-
const [currentTvl, setCurrentTvl] = useState<number | undefined>()
14-
15-
const tokenPrices = useTokenPrices(
16-
pool.tokens.map(token => token.address),
17-
chainId,
18-
)
19-
const totalTvl = pool.poolStats?.tvl
20-
21-
const liquidityUsdValue = getPoolLiquidityUsd(pool, tokenPrices)
22-
23-
const metrics = [
24-
{ label: 'TVL', value: formatUsd(totalTvl) },
25-
{ label: 'Current TVL', value: formatUsd(currentTvl ?? totalTvl) },
26-
{ label: 'Liquidity', value: formatUsd(liquidityUsdValue) },
27-
]
7+
const { chainId, poolAddress } = usePoolDetailContext()
288

299
return (
3010
<Stack gap={20}>
31-
<TopMetricsStrip items={metrics} split />
32-
3311
<PoolPriceChart chainId={chainId} poolAddress={poolAddress} />
3412

35-
<LiquidityFlowsChart chainId={chainId} poolAddress={poolAddress} onCurrentTvlChange={setCurrentTvl} />
13+
<LiquidityFlowsChart chainId={chainId} poolAddress={poolAddress} />
3614
</Stack>
3715
)
3816
}

apps/kyberswap-interface/src/pages/Earns/PoolDetail/Information/InformationTab.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const InformationTab = () => {
4646

4747
return (
4848
<Stack gap={20}>
49-
<TopMetricsStrip items={topMetrics} />
49+
<TopMetricsStrip items={topMetrics} split={true} />
5050

5151
<AprHistoryChart chainId={chainId} poolAddress={poolAddress} />
5252
</Stack>

apps/kyberswap-interface/src/pages/Earns/PoolDetail/Information/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const PoolInformation = () => {
4848
const currentTab: PoolInfoTab = activeTab || 'information'
4949

5050
return (
51-
<Panel width="100%" gap={16}>
51+
<Panel width="100%" gap={20}>
5252
<HStack align="center" gap={16} wrap="wrap">
5353
{POOL_INFO_TABS.map((tab, index) => (
5454
<HStack key={tab.id} align="center" gap={16}>

apps/kyberswap-interface/src/pages/Earns/PoolDetail/components/AprHistoryChart.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import PoolChartState, { PoolChartWrapper } from 'pages/Earns/PoolDetail/compone
1919
import { MEDIA_WIDTHS } from 'theme'
2020

2121
const TooltipCard = styled(Stack)`
22-
gap: 8px;
22+
gap: 12px;
23+
min-width: 220px;
2324
padding: 12px 16px;
2425
border: 1px solid ${({ theme }) => theme.border};
2526
background: ${({ theme }) => theme.tableHeader};
@@ -141,9 +142,9 @@ const AprHistoryChart = ({ chainId, poolAddress }: AprHistoryChartProps) => {
141142
const gridColor = rgba(theme.text, 0.06)
142143

143144
const {
144-
currentData: aprHistoryData,
145+
data: aprHistoryData,
145146
isError,
146-
isFetching,
147+
isLoading,
147148
} = usePoolAprHistoryQuery({
148149
chainId,
149150
address: poolAddress,
@@ -222,7 +223,8 @@ const AprHistoryChart = ({ chainId, poolAddress }: AprHistoryChartProps) => {
222223
height={chartHeight}
223224
isEmpty={!chartData.length}
224225
isError={isError}
225-
isLoading={isFetching && !aprHistoryData}
226+
isLoading={isLoading}
227+
skeletonType="line"
226228
>
227229
<PoolChartWrapper $height={chartHeight}>
228230
<ResponsiveContainer width="100%" height="100%">

apps/kyberswap-interface/src/pages/Earns/PoolDetail/components/LiquidityFlowsChart.tsx

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { rgba } from 'polished'
2-
import { useEffect, useMemo, useState } from 'react'
2+
import { useMemo, useState } from 'react'
33
import { useMedia } from 'react-use'
44
import { Text } from 'rebass'
55
import {
@@ -74,7 +74,6 @@ type TooltipContentProps = {
7474

7575
type LiquidityFlowsChartProps = {
7676
chainId: number
77-
onCurrentTvlChange?: (value?: number) => void
7877
poolAddress: string
7978
}
8079

@@ -110,7 +109,7 @@ const LiquidityFlowsTooltip = ({
110109
{formatUsd(Math.abs(point.removeUsd))}
111110
</Text>
112111
<Text color={theme.subText} fontSize={12}>
113-
Net Liquidity Flow
112+
Net Flow
114113
</Text>
115114
<Text color={theme.text} fontSize={12} fontWeight={500} textAlign="right">
116115
{formatUsd(Math.abs(point.lpVolumeUsd))}
@@ -126,7 +125,7 @@ const LiquidityFlowsTooltip = ({
126125
)
127126
}
128127

129-
const LiquidityFlowsChart = ({ chainId, onCurrentTvlChange, poolAddress }: LiquidityFlowsChartProps) => {
128+
const LiquidityFlowsChart = ({ chainId, poolAddress }: LiquidityFlowsChartProps) => {
130129
const theme = useTheme()
131130

132131
const [window, setWindow] = useState<PoolAnalyticsWindow>('7d')
@@ -143,9 +142,9 @@ const LiquidityFlowsChart = ({ chainId, onCurrentTvlChange, poolAddress }: Liqui
143142
const removeLiquidityColor = rgba(theme.red, 0.5)
144143

145144
const {
146-
currentData: liquidityFlowData,
145+
data: liquidityFlowData,
147146
isError,
148-
isFetching,
147+
isLoading,
149148
} = usePoolLiquidityFlowsQuery({
150149
chainId,
151150
address: poolAddress,
@@ -162,14 +161,7 @@ const LiquidityFlowsChart = ({ chainId, onCurrentTvlChange, poolAddress }: Liqui
162161
[liquidityFlowData?.buckets],
163162
)
164163

165-
const latestBucket = liquidityFlowData?.buckets.at(-1)
166-
167-
useEffect(() => {
168-
onCurrentTvlChange?.(latestBucket?.tvlUsd)
169-
}, [latestBucket?.tvlUsd, onCurrentTvlChange])
170-
171164
const handleSelectWindow = (value: PoolAnalyticsWindow) => {
172-
onCurrentTvlChange?.(undefined)
173165
setWindow(value)
174166
}
175167

@@ -186,10 +178,11 @@ const LiquidityFlowsChart = ({ chainId, onCurrentTvlChange, poolAddress }: Liqui
186178
<PoolChartState
187179
emptyMessage="No liquidity flow data available for this pool."
188180
errorMessage="Unable to load liquidity flows."
181+
exclusiveType="liquidity-flow"
189182
height={chartHeight}
190183
isEmpty={!chartData.length}
191184
isError={isError}
192-
isLoading={isFetching && !liquidityFlowData}
185+
isLoading={isLoading}
193186
>
194187
<Stack gap={12}>
195188
<PoolChartWrapper $height={chartHeight}>
@@ -297,7 +290,7 @@ const LiquidityFlowsChart = ({ chainId, onCurrentTvlChange, poolAddress }: Liqui
297290
<HStack align="center" gap={8}>
298291
<LegendLine $color={theme.primary} />
299292
<Text color={theme.subText} fontSize={12}>
300-
Net Liquidity Flow
293+
Net Flow
301294
</Text>
302295
</HStack>
303296
<HStack align="center" gap={8}>

0 commit comments

Comments
 (0)