import useMangoGroup from 'hooks/useMangoGroup' import type { NextPage } from 'next' import { serverSideTranslations } from 'next-i18next/serverSideTranslations' import { DashboardNavbar } from '.' import { Table, Td, Th, TrBody, TrHead } from '@components/shared/TableElements' import { useQuery } from '@tanstack/react-query' import mangoStore from '@store/mangoStore' import { getRiskStats } from '@blockworks-foundation/mango-v4' import { PublicKey } from '@solana/web3.js' import { formatNumericValue } from 'utils/numbers' export async function getStaticProps({ locale }: { locale: string }) { return { props: { ...(await serverSideTranslations(locale, ['common'])), }, } } type TableData = { title: string data: Array> } const formatValue = (val: string | number | PublicKey) => { if (val instanceof PublicKey) { return val.toString() } if (typeof val === 'string') { return val } else { return formatNumericValue(val) } } const RiskDashboard: NextPage = () => { const { group } = useMangoGroup() const client = mangoStore((s) => s.client) const { data, isLoading, isFetching } = useQuery( ['risks'], () => group && getRiskStats(client, group), { cacheTime: 1000 * 60 * 10, retry: 3, refetchOnWindowFocus: true, enabled: !!group, } ) console.log('resp', isLoading, isFetching, data) return (

Dashboard

{group && data ? (
{Object.entries(data).map( ([tableType, table]: [string, TableData]) => { return (

{table.title}

{Object.keys(table.data[0]).map( (colName: string) => { return ( ) } )} {table.data.map((rowData, index: number) => { return ( {Object.values(rowData).map( ( colVal: string | number | PublicKey, idx: number ) => { return ( ) } )} ) })}
{colName}
{formatValue(colVal)}
) } )}
) : ( 'Loading' )}
) } export default RiskDashboard