diff --git a/components/leaderboards/lands-chart.tsx b/components/leaderboards/lands-chart.tsx index a0d0a5b0..92997784 100644 --- a/components/leaderboards/lands-chart.tsx +++ b/components/leaderboards/lands-chart.tsx @@ -1,91 +1,136 @@ -import { TrendingUp } from "lucide-react" -import { Bar, BarChart, CartesianGrid, LabelList, XAxis, YAxis } from "recharts" +import { TrendingUp } from "lucide-react"; import { - Card, - CardContent, - CardDescription, - CardFooter, - CardHeader, - CardTitle, -} from "@components/ui/card" + Bar, + BarChart, + CartesianGrid, + XAxis, + YAxis, + ResponsiveContainer, + Tooltip, + Cell, +} from "recharts"; import { - ChartConfig, - ChartContainer, - ChartTooltip, - ChartTooltipContent, -} from "@components/ui/chart" + Card, + CardContent, + CardDescription, + CardFooter, + CardHeader, + CardTitle, +} from "@components/ui/card"; +import { + ChartConfig, + ChartContainer, + ChartTooltip, + ChartTooltipContent, +} from "@components/ui/chart"; +import { useState, useEffect } from "react"; export function LandsChart({ chartData, chartConfig }: { chartData: any[], chartConfig: ChartConfig }) { - return ( - - - Total Tokens Staked - By Percentage of Total Supply - - - - (false); + + useEffect(() => { + function handleResize() { + setIsMobile(window.innerWidth < 768); + } + handleResize(); + window.addEventListener("resize", handleResize); + return () => window.removeEventListener("resize", handleResize); + }, []); - > + // generates unique colors for each token + const COLORS = chartData.map((_, index) => + `hsl(${(index * 137.508) % 360}, 65%, 55%)` + ); - - item.id.length * (isMobile ? 7 : 10))), + isMobile ? 100 : 150 + ); - /> - - - } + // set maximum height for the chart container + const maxChartHeight = 400; - /> - - - `${(value * 100).toFixed(2)}%`} - /> - - - - - {/* - - Trending up by 5.2% this month - - - Showing total tokens for the last 6 months - - */} - - ) + return ( + + + Total Tokens Staked + By Percentage of Total Supply + + + + maxChartHeight + ? chartData.length * (isMobile ? 40 : 30) + : maxChartHeight + } + > + + {/* I got rid of vertical grid lines */} + + + + `${(value * 100).toFixed(2)}%`} + contentStyle={{ + backgroundColor: "#170202", // tooltip background color + borderColor: "#710707", + borderRadius: "5px", + padding: "5px 19px", + }} + itemStyle={{ color: "#fff" }} // tooltip text color + /> + + {chartData.map((entry, index) => ( + + ))} + + + + + + {/* + + Trending up by 5.2% this month + + + Showing total tokens for the last 6 months + + */} + + ); } diff --git a/components/leaderboards/tokens-difficulty-chart.tsx b/components/leaderboards/tokens-difficulty-chart.tsx index 12d9035f..f68c9b1f 100644 --- a/components/leaderboards/tokens-difficulty-chart.tsx +++ b/components/leaderboards/tokens-difficulty-chart.tsx @@ -1,91 +1,110 @@ -import { TrendingUp } from "lucide-react" -import { Bar, BarChart, CartesianGrid, LabelList, XAxis, YAxis } from "recharts" +import React, { useState } from 'react'; import { - Card, - CardContent, - CardDescription, - CardFooter, - CardHeader, - CardTitle, -} from "@components/ui/card" + Card, + CardContent, + CardDescription, + CardHeader, + CardTitle, +} from '@components/ui/card'; +import numeral from 'numeral'; +import { ChartConfig } from '@components/ui/chart'; import { - ChartConfig, - ChartContainer, - ChartTooltip, - ChartTooltipContent, -} from "@components/ui/chart" + Table, + TableBody, + TableCell, + TableHead, + TableHeader, + TableRow, +} from "@components/ui/table"; -export function TokensDifficultyChart({ chartData, chartConfig }: { chartData: any[], chartConfig: ChartConfig }) { - return ( - - - Energy Output of Staked Tokens - Normalized with Difficulty Adjustment - - - - +export function TokensDifficultyChart({ chartData, chartConfig }: { chartData: any[], chartConfig: ChartConfig }) { + // State for sorting between ascending and descending + const [sortConfig, setSortConfig] = useState<{ + key: keyof ChartDataItem; + direction: 'ascending' | 'descending'; + }>({ key: 'score', direction: 'descending' }); - - { + const sortableItems = [...chartData]; + sortableItems.sort((a, b) => { + if (a[sortConfig.key] < b[sortConfig.key]) { + return sortConfig.direction === 'ascending' ? -1 : 1; + } + if (a[sortConfig.key] > b[sortConfig.key]) { + return sortConfig.direction === 'ascending' ? 1 : -1; + } + return 0; + }); + return sortableItems; + }, [chartData, sortConfig]); - /> - - - } + const requestSort = (key: keyof ChartDataItem) => { + let direction: 'ascending' | 'descending' = 'ascending'; + if ( + sortConfig.key === key && + sortConfig.direction === 'ascending' + ) { + direction = 'descending'; + } + setSortConfig({ key, direction }); + }; - /> - - - `${value.toFixed(0)}`} - /> - - - - - {/* - - Trending up by 5.2% this month - - - Showing total tokens for the last 6 months - - */} - - ) + return ( + + + Energy Output of Staked Tokens + + Normalized with Difficulty Adjustment + + + + + + + + requestSort('id')} + className="px-6 py-3 text-left text-xs font-medium uppercase tracking-wider cursor-pointer" + > + Token{' '} + {sortConfig.key === 'id' && + (sortConfig.direction === 'ascending' + ? '▲' + : '▼')} + + requestSort('score')} + className="px-6 py-3 text-left text-xs font-medium uppercase tracking-wider cursor-pointer" + > + Energy Output{' '} + {sortConfig.key === 'score' && + (sortConfig.direction === 'ascending' + ? '▲' + : '▼')} + + + + + {sortedData.map((item) => ( + + + {item.id} + + + {numeral(item.score).format('0,0')} + + + ))} + + + + + + ); } diff --git a/next-env.d.ts b/next-env.d.ts index 4f11a03d..a4a7b3f5 100644 --- a/next-env.d.ts +++ b/next-env.d.ts @@ -2,4 +2,4 @@ /// // NOTE: This file should not be edited -// see https://nextjs.org/docs/basic-features/typescript for more information. +// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information. diff --git a/pages/governance/index.tsx b/pages/governance/index.tsx index e53e6011..6db15681 100644 --- a/pages/governance/index.tsx +++ b/pages/governance/index.tsx @@ -44,7 +44,7 @@ const Card: React.FC = ({ href, src, alt, title, subtitle }) => ( 'overflow-hidden' )} > - + = ({ href, src, alt, title, subtitle }) => ( )} /> - + {title} {subtitle} @@ -207,7 +207,7 @@ export default function Governance({ data }: Props) { - + Proposals @@ -217,7 +217,7 @@ export default function Governance({ data }: Props) { - + Contributer Guide 📕 @@ -226,7 +226,7 @@ export default function Governance({ data }: Props) { - + {cards.map((card, index) => ( ))} @@ -242,6 +242,8 @@ export default function Governance({ data }: Props) { export const getServerSideProps: GetServerSideProps = async () => { try { + // TODO: utilize the new proposal data provided by chainhooks to get initial list of proposals + // we will still need to enrich this data with proposal metadata, tbd const [proposals, transactions] = await Promise.all([ getProposals(), fetchAllContractTransactions(