import { ChevronRight } from "@mui/icons-material"; import { Box } from "@mui/system"; import { Card, IconButton } from "@mui/material"; import { createColumnHelper, getCoreRowModel, getSortedRowModel, SortingState, useReactTable, getExpandedRowModel, Row, } from "@tanstack/react-table"; import numeral from "numeral"; import { useState, ReactElement } from "react"; import useCustodyData, { CustodyDataResponse } from "../hooks/useCustodyData"; import Table from "./Table"; import TokenDetails from "./TokenDetails"; const columnHelper = createColumnHelper(); const columns = [ columnHelper.display({ id: "_expand", cell: ({ row }) => row.getCanExpand() ? ( ) : null, }), columnHelper.accessor("chainId", { header: () => "Chain Id", sortingFn: `text`, }), columnHelper.accessor("chainName", { header: () => "Chain Name", }), columnHelper.accessor("custodyUSD", { header: () => "Total Value Locked (USD)", cell: (info) => ( ${numeral(info.getValue()).format("0,0.0000")} ), }), columnHelper.accessor("tokens", { header: () => "Locked Tokens", cell: (info) => { const value = info.getValue(); return `${value.length} Token` + (value.length === 1 ? "" : `s`); }, }), columnHelper.accessor("updatedAt", { header: () => "Last Updated", cell: (info) => info.getValue() ? new Date(info.getValue()).toLocaleString() : null, }), ]; /* interface Token { tokenAddress: string; name: string; decimals: number; symbol: string; balance: BigInt; qty: number; tokenPrice: number; tokenBalanceUSD: number; } */ function AddTokenDetails({ row, }: { row: Row; }): ReactElement { const id = row.original._id; return TokenDetails(id); } function CustodyData() { const custody = useCustodyData(); const [sorting, setSorting] = useState([]); const lockedValue = custody .map((x) => x.custodyUSD) .reduce((partialSum, a) => partialSum + a, 0); const table = useReactTable({ columns, data: custody, state: { sorting, }, getRowId: (chain) => chain.chainName, getRowCanExpand: () => true, getCoreRowModel: getCoreRowModel(), getExpandedRowModel: getExpandedRowModel(), getSortedRowModel: getSortedRowModel(), onSortingChange: setSorting, }); return ( Total Locked Value (USD): ${numeral(lockedValue).format("0,0.0000")} table={table} renderSubComponent={AddTokenDetails} /> ); } export default CustodyData;