Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

feat: vebal page chart and stats layout #1153

Merged
merged 3 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 12 additions & 0 deletions app/(app)/vebal/manage/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use client'

import { VebalManage } from '@/lib/modules/vebal/VebalManage'
import { Stack } from '@chakra-ui/react'

export default function VebalManagePage() {
return (
<Stack gap="lg">
<VebalManage />
</Stack>
)
}
11 changes: 2 additions & 9 deletions app/(app)/vebal/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
'use client'

import { VebalInfo } from '@/lib/modules/vebal/VebalInfo'
import { Stack } from '@chakra-ui/react'

export default function VebalPage() {
return (
<Stack gap="lg">
<VebalInfo />
</Stack>
)
export default function VeBALPage() {
return <Stack></Stack>
}
31 changes: 31 additions & 0 deletions lib/modules/vebal/VebalBreadcrumbs.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Box, Breadcrumb, BreadcrumbItem, BreadcrumbLink, Button } from '@chakra-ui/react'
import { ChevronRight, Home } from 'react-feather'

export function VebalBreadcrumbs() {
return (
<Breadcrumb
color="grayText"
spacing="sm"
fontSize="sm"
separator={
<Box color="border.base">
<ChevronRight size={16} />
</Box>
}
>
<BreadcrumbItem>
<BreadcrumbLink href="/">
<Button variant="link" size="xs" color="grayText">
<Home size={16} />
</Button>
</BreadcrumbLink>
</BreadcrumbItem>
<BreadcrumbItem>
<BreadcrumbLink href={'/vebal/manage'}>veBAL</BreadcrumbLink>
</BreadcrumbItem>
<BreadcrumbItem isCurrentPage>
<BreadcrumbLink href="#">Manage</BreadcrumbLink>
</BreadcrumbItem>
</Breadcrumb>
)
}
85 changes: 0 additions & 85 deletions lib/modules/vebal/VebalInfo.tsx

This file was deleted.

54 changes: 54 additions & 0 deletions lib/modules/vebal/VebalManage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { useUserAccount } from '../web3/UserAccountProvider'
import { Button, Heading, Stack, Text, VStack } from '@chakra-ui/react'
import { VebalStatsLayout } from './VebalStats/VebalStatsLayout'
import { VebalBreadcrumbs } from '@/lib/modules/vebal/VebalBreadcrumbs'

export function VebalManage() {
const { isConnected } = useUserAccount()

if (!isConnected) {
return <Text>Not connected</Text>
}

return (
<Stack spacing="lg">
<VebalBreadcrumbs />
<VStack align="start" w="full">
<Stack
w="full"
justify="space-between"
alignItems="center"
spacing="md"
direction={{ base: 'column', md: 'row' }}
>
<Heading as="h2" size="lg" variant="special">
Manage veBAL
</Heading>

<Stack spacing="md" direction={{ base: 'column', md: 'row' }}>
<Button
onClick={() => {
//
}}
size="lg"
isDisabled={false}
>
Extend lock
</Button>
<Button
onClick={() => {
//
}}
variant="primary"
size="lg"
isDisabled={false}
>
Get veBAL
</Button>
</Stack>
</Stack>
</VStack>
<VebalStatsLayout />
</Stack>
)
}
14 changes: 14 additions & 0 deletions lib/modules/vebal/VebalStats/AllVebalStatsValues.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use client'
import { Stack } from '@chakra-ui/react'
import BigNumber from 'bignumber.js'

export type VebalAllStatsValues = {
balance: string | undefined
rank: number | undefined
percentOfAllSupply: BigNumber | undefined
lockedUntil: string | undefined
}

export function AllVebalStatsValues() {
return <Stack></Stack>
}
115 changes: 115 additions & 0 deletions lib/modules/vebal/VebalStats/UserVebalStatsValues.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
'use client'

import React, { useMemo } from 'react'
import { Heading, Skeleton, Text, Tooltip, VStack } from '@chakra-ui/react'
import { bn, fNum } from '@/lib/shared/utils/numbers'
import { useVebalUserData } from '@/lib/modules/vebal/useVebalUserData'
import { useVebalLockInfo } from '@/lib/modules/vebal/useVebalLockInfo'
import { differenceInDays, format } from 'date-fns'
import BigNumber from 'bignumber.js'

export type VebalUserStatsValues = {
balance: string | undefined
rank: number | undefined
percentOfAllSupply: BigNumber | undefined
lockedUntil: string | undefined
}

export function UserVebalStatsValues() {
const lockInfo = useVebalLockInfo()
const vebalUserData = useVebalUserData()

const vebalUserStatsValues: VebalUserStatsValues | undefined = useMemo(() => {
if (vebalUserData.isConnected) {
const balance = vebalUserData.data?.veBalGetUser.balance
const rank = vebalUserData.data?.veBalGetUser.rank ?? undefined
const percentOfAllSupply = vebalUserData.data
? bn(vebalUserData.data.veBalGetUser.balance || 0).div(
lockInfo.mainnetLockedInfo.totalSupply || 0
)
: undefined
const lockedUntil =
!lockInfo.mainnetLockedInfo.lockedEndDate || lockInfo.mainnetLockedInfo.isExpired
? undefined
: format(lockInfo.mainnetLockedInfo.lockedEndDate, 'yyyy-MM-dd')

return {
balance,
rank,
percentOfAllSupply,
lockedUntil,
}
}
}, [lockInfo.mainnetLockedInfo, vebalUserData.isConnected, vebalUserData.data])

return (
<>
<VStack spacing="0" align="flex-start" w="full">
<Text variant="secondary" fontWeight="semibold" fontSize="sm" mt="xxs">
My veBAL
</Text>
{vebalUserData.loading ? (
<Skeleton height="28px" w="100px" />
) : (
<Heading size="h4">
{typeof vebalUserStatsValues?.balance === 'string' ? (
fNum('token', vebalUserStatsValues.balance)
) : (
<>&mdash;</>
)}
</Heading>
)}
</VStack>
<VStack spacing="0" align="flex-start" w="full">
<Text variant="secondary" fontWeight="semibold" fontSize="sm" mt="xxs">
My rank
</Text>
{vebalUserData.loading ? (
<Skeleton height="28px" w="100px" />
) : (
<Heading size="h4">{vebalUserStatsValues?.rank ?? <>&mdash;</>}</Heading>
)}
</VStack>
<VStack spacing="0" align="flex-start" w="full">
<Text variant="secondary" fontWeight="semibold" fontSize="sm" mt="xxs">
My share of veBAL
</Text>
{vebalUserData.loading ? (
<Skeleton height="28px" w="100px" />
) : (
<Heading size="h4">
{vebalUserStatsValues?.percentOfAllSupply ? (
fNum('feePercent', vebalUserStatsValues.percentOfAllSupply)
) : (
<>&mdash;</>
)}
</Heading>
)}
</VStack>
<VStack spacing="0" align="flex-start" w="full">
<Text variant="secondary" fontWeight="semibold" fontSize="sm" mt="xxs">
Expiry date
</Text>
{lockInfo.isLoading ? (
<Skeleton height="28px" w="100px" />
) : (
<Tooltip
label={
vebalUserStatsValues?.lockedUntil
? `Expires ${format(new Date(vebalUserStatsValues.lockedUntil), 'dd MMM yyyy')}`
: undefined
}
>
<Heading size="h4">
{vebalUserStatsValues?.lockedUntil ? (
`${differenceInDays(new Date(vebalUserStatsValues.lockedUntil), new Date())} days`
) : (
<>&mdash;</>
)}
</Heading>
</Tooltip>
)}
</VStack>
</>
)
}
Loading
Loading