import { useState } from "react"; import { Loader2, MenuSquareIcon, MoveVertical, MoveUp, MoveDown, Link as LinkIcon, } from "lucide-react"; import Link from "next/link"; import Head from "next/head"; import { config } from "@/Config"; import { cn, formatNumber, formatPercent } from "@/lib/utils"; import { formatAndDelocalizeFromTime } from "@/utils/TimeUtils"; import useWitnesses from "@/hooks/api/common/useWitnesses"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; import VotersDialog from "@/components/Witnesses/VotersDialog"; import VotesHistoryDialog from "@/components/Witnesses/VotesHistoryDialog"; import WitnessScheduleIcon from "@/components/WitnessScheduleIcon"; import LastUpdatedTooltip from "@/components/LastUpdatedTooltip"; const TABLE_CELLS = [ "Rank", "Name", "Votes", "Voters", "Block Size", "Missed Blocks", "APR", "Price Feed", "Feed Age", "Version", "Last Block Produced", ]; const sortKeyByCell: { [objectKey: string]: string } = { rank: "rank", name: "witness", votes: "votes", voters: "voters_num", "block size": "block_size", "missed blocks": "missed_blocks", apr: "hbd_interest_rate", "price feed": "price_feed", "feed age": "feed_updated_at", version: "version", "last block produced": "last_confirmed_block_num", }; const renderSortArrow = ( cell: string, orderBy: string, isOrderAscending: boolean ) => { // Remove this code block when sorting by `missed_blocks` and `hbd_interest_rate` and `last_confirmed_block_num` will be available const hideSort = cell === "missed blocks" || cell === "apr" || cell === "version" || cell === "last block produced"; if (hideSort) return; // if (sortKeyByCell[cell] !== orderBy) { return ( ); } else { return isOrderAscending ? ( ) : ( ); } }; // Remove this code block when sorting by `missed_blocks` and `hbd_interest_rate` and `last_confirmed_block_num` will be available const isCellUnsortable = (cell: string) => { return ( cell === "APR" || cell === "Missed Blocks" || cell === "Version" || cell === "Last Block Produced" ); }; // export default function Witnesses() { const [voterAccount, setVoterAccount] = useState(""); const [isVotersOpen, setIsVotersOpen] = useState(false); const [isVotesHistoryOpen, setIsVotesHistoryOpen] = useState(false); const [sort, setSort] = useState({ orderBy: "rank", isOrderAscending: true, }); const { witnessesData, isWitnessDataLoading } = useWitnesses( config.witnessesPerPages.witnesses, sort.orderBy, sort.isOrderAscending ? "asc" : "desc" ); const handleSortBy = (tableCell: string) => { setSort({ orderBy: sortKeyByCell[tableCell], isOrderAscending: !sort.isOrderAscending, }); }; if (isWitnessDataLoading) { return ( ); } if (!witnessesData || !witnessesData.witnesses.length) return; const changeVotersDialogue = (isOpen: boolean) => { setIsVotersOpen(isOpen); }; const changeVotesHistoryDialog = (isOpen: boolean) => { setIsVotesHistoryOpen(isOpen); }; const buildTableHeader = () => { return TABLE_CELLS.map((cell) => { const toLowerCase = cell.toLocaleLowerCase(); const className = "first:sticky first:left-0 [&:nth-child(2)]:sticky [&:nth-child(2)]:left-16 text-center"; return ( ); }); }; return ( <> Witnesses - Hive Explorer
{buildTableHeader()} {witnessesData.witnesses.map((singleWitness: any, index: any) => ( {singleWitness.rank}
{singleWitness.witness_name}
{formatNumber(singleWitness.vests || 0, true).split(".")[0]} { setVoterAccount(singleWitness.witness_name); setIsVotesHistoryOpen(true); }} data-testid="witness-votes-button" /> {singleWitness.voters_num.toLocaleString()} { setVoterAccount(singleWitness.witness_name); setIsVotersOpen(true); }} data-testid="witness-voters-button" /> {singleWitness.block_size ? singleWitness.block_size.toLocaleString() : "--"} {singleWitness.block_size ? singleWitness.missed_blocks.toLocaleString() : "--"} {singleWitness.hbd_interest_rate ? formatPercent(singleWitness.hbd_interest_rate) : "--"} {singleWitness.price_feed ? singleWitness.price_feed.toLocaleString() : "--"} {singleWitness.feed_updated_at ? formatAndDelocalizeFromTime(singleWitness.feed_updated_at) : "--"} {singleWitness.version} {singleWitness.last_confirmed_block_num ? ( {singleWitness.last_confirmed_block_num.toLocaleString()} ) : ( "--" )}
))}
); }