1+ 'use client' ;
2+
3+ import { Table , TableHead , TableRow } from '@mui/material' ;
4+ import * as S from '@/styles/table' ;
5+ import { motion } from 'framer-motion' ;
6+ import type { RichListTableProps } from './types' ;
7+ import Link from 'next/link' ;
8+ import * as React from 'react' ;
9+
10+ import * as Switch from '@radix-ui/react-switch' ;
11+ import clsx from 'clsx' ;
12+ const MotionTableRow = motion ( TableRow ) ;
13+
14+ interface DataItem {
15+ rank : number ;
16+ account : string ;
17+ amount : number ;
18+ url ?: string ;
19+ }
20+
21+ interface ValidatorsTableProps {
22+ liquidData : DataItem [ ] ;
23+ stakedData : DataItem [ ] ;
24+ }
25+
26+ export default function RichListTable ( { data, data2 } : RichListTableProps ) {
27+ const numberFormat = new Intl . NumberFormat ( 'en-US' , { style : 'decimal' } ) ;
28+
29+ const [ showLiquid , setShowLiquid ] = React . useState ( false ) ; // if (true) default:topstakers
30+ const toggleDataView = ( ) => setShowLiquid ( ! showLiquid ) ;
31+ const dataToDisplay = showLiquid ? data : data2 ;
32+
33+
34+ return (
35+ < >
36+ < div className = 'flex items-center mb-6 justify-center' >
37+ < div
38+ className = { clsx ( 'text-base font-medium leading-none transition' , {
39+ 'text-shade-400' : showLiquid ,
40+ 'text-black' : ! showLiquid ,
41+ } ) }
42+ >
43+ Top Holders
44+ </ div >
45+ < Switch . Root
46+ checked = { showLiquid }
47+ onCheckedChange = { toggleDataView }
48+ className = 'relative mx-4 w-16 rounded-full bg-shade-100 py-1.5 outline-none border'
49+ style = { { WebkitTapHighlightColor : 'rgba(0, 0, 0, 0)' } }
50+ >
51+ < Switch . Thumb className = 'block h-6 w-6 translate-x-1.5 rounded-full bg-indigo-500 transition will-change-transform data-[state=checked]:translate-x-[34px]' />
52+ </ Switch . Root >
53+ < div className = 'relative' >
54+ < div
55+ className = { clsx ( 'text-base font-medium leading-none transition' , {
56+ 'text-shade-400' : ! showLiquid ,
57+ 'text-black' : showLiquid ,
58+ } ) }
59+ >
60+ Top Stakers
61+ </ div >
62+ </ div >
63+ </ div >
64+
65+
66+ < div className = 'w-full overflow-x-auto rounded-md border border-shade-200 bg-white' >
67+ < Table aria-label = 'Validators Table' >
68+ < TableHead >
69+ < S . StyledTableRow >
70+ < S . StyledTableHeadCell size = 'medium' > RANK</ S . StyledTableHeadCell >
71+ < S . StyledTableHeadCell size = 'medium' >
72+ ACCOUNT
73+ </ S . StyledTableHeadCell >
74+ < S . StyledTableHeadCell size = 'medium' >
75+ TOTAL
76+ </ S . StyledTableHeadCell >
77+
78+ </ S . StyledTableRow >
79+ </ TableHead >
80+ < S . StyledTableBody >
81+ { dataToDisplay . map ( ( item , index ) => (
82+ < MotionTableRow
83+ key = { index }
84+ initial = { { height : 0 , opacity : 0 } }
85+ animate = { {
86+ height : 'auto' ,
87+ display : 'table-row' ,
88+ opacity : 1 ,
89+ transition : {
90+ duration : 0.6 ,
91+ } ,
92+ } }
93+ exit = { {
94+ height : 0 ,
95+ opacity : 0 ,
96+ display : 'none' ,
97+ transition : {
98+ duration : 0.2 ,
99+ } ,
100+ } }
101+ >
102+ < S . StyledTableCell size = 'medium' >
103+ < span className = 'text-primary' > { index + 1 } </ span >
104+ </ S . StyledTableCell >
105+ < S . StyledTableCell size = 'medium' >
106+ < Link
107+ href = { `/address/${ item . account } ` }
108+ className = 'inline-block max-w-full truncate align-middle hover:underline'
109+ >
110+ < span className = '' > { item . account } </ span >
111+ </ Link >
112+ </ S . StyledTableCell >
113+ < S . StyledTableCell size = 'medium' >
114+ < span className = '' > { numberFormat . format ( item . amount ) } </ span >
115+ </ S . StyledTableCell >
116+
117+
118+ < S . StyledTableCell size = 'medium' >
119+ < a
120+ href = "{row.url}"
121+ target = '_blank'
122+ className = 'text-primary hover:underline'
123+ >
124+
125+ </ a >
126+ </ S . StyledTableCell >
127+ </ MotionTableRow >
128+ ) ) }
129+ </ S . StyledTableBody >
130+ </ Table >
131+ </ div >
132+ </ >
133+ ) ;
134+ }
0 commit comments