Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: get lock snapshots from api #100

Merged
merged 6 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions packages/lib/modules/vebal/VebalStats/VebalStatsLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
'use client'

import { Stack } from '@chakra-ui/react'
import { Skeleton, Stack } from '@chakra-ui/react'
import { VebalStats } from '@repo/lib/modules/vebal/VebalStats/VebalStats'
import { VeBALLocksChart } from '@repo/lib/modules/vebal/vebal-chart/VebalLocksChart'
import { VebalLocksChart } from '@repo/lib/modules/vebal/vebal-chart/VebalLocksChart'
import { useVebalLockInfo } from '@repo/lib/modules/vebal/useVebalLockInfo'
import { useVebalUserData } from '@repo/lib/modules/vebal/useVebalUserData'
import { useMemo } from 'react'

export function VebalStatsLayout() {
const lockInfo = useVebalLockInfo()
const { loading, data } = useVebalUserData()

const lockSnapshots = useMemo(() => data?.veBalGetUser.lockSnapshots ?? [], [data])

return (
<Stack direction={{ base: 'column', md: 'row' }} justifyContent="stretch" spacing="md" w="full">
<VebalStats w={{ base: 'full', md: 'md' }} />
<VeBALLocksChart h={{ base: 'md', md: 'auto' }} w="full" />
{loading || lockInfo.isLoading ? (
<Skeleton h={{ base: 'md', md: 'auto' }} w="full" />
) : (
<VebalLocksChart
h={{ base: 'md', md: 'auto' }}
lockSnapshots={lockSnapshots}
mainnetLockedInfo={lockInfo.mainnetLockedInfo}
w="full"
/>
)}
</Stack>
)
}
2 changes: 2 additions & 0 deletions packages/lib/modules/vebal/useVebalLockInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ interface MulticallLockInfoResponse {
}
}

export type UseVebalLockInfoResult = ReturnType<typeof useVebalLockInfo>

export function useVebalLockInfo() {
const { userAddress, isConnected } = useUserAccount()

Expand Down
39 changes: 29 additions & 10 deletions packages/lib/modules/vebal/vebal-chart/VebalLocksChart.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,38 @@
import { Card, CardProps } from '@chakra-ui/react'
import { Card, CardProps, Text, VStack } from '@chakra-ui/react'

import ReactECharts from 'echarts-for-react'
import { useVebalLocksChart } from './useVebalLocksChart'
import { useVebalLocksChart, UseVebalLocksChartParams } from './useVebalLocksChart'
import { ChartBubbleIcon } from '@repo/lib/shared/components/icons/ChartBubbleIcon'

export function VeBALLocksChart(props: CardProps) {
const { options, onChartReady, onEvents } = useVebalLocksChart()
export function VebalLocksChart({
mainnetLockedInfo,
lockSnapshots,
...props
}: CardProps & UseVebalLocksChartParams) {
const { options, onChartReady, onEvents, insufficientData } = useVebalLocksChart({
mainnetLockedInfo,
lockSnapshots,
})

return (
<Card position="relative" {...props}>
<ReactECharts
onChartReady={onChartReady}
onEvents={onEvents}
option={options}
style={{ height: '100%', width: '100%' }}
/>
{insufficientData ? (
<VStack h="full" justifyContent="center">
<Text variant="secondary">
<ChartBubbleIcon size={16} />
</Text>
<Text fontSize="lg" fontWeight={700} variant="secondary">
Not enough data
</Text>
</VStack>
) : (
<ReactECharts
onChartReady={onChartReady}
onEvents={onEvents}
option={options}
style={{ height: '100%', width: '100%' }}
/>
)}
</Card>
)
}
254 changes: 0 additions & 254 deletions packages/lib/modules/vebal/vebal-chart/test-locks.ts

This file was deleted.

Loading
Loading