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 { Risk } from '@blockworks-foundation/mango-v4' import { PublicKey } from '@solana/web3.js' import { formatNumericValue } from 'utils/numbers' import { MANGO_DATA_API_URL } from 'utils/constants' export async function getStaticProps({ locale }: { locale: string }) { return { props: { ...(await serverSideTranslations(locale, [ 'account', 'close-account', 'common', 'notifications', 'onboarding', 'profile', 'search', 'settings', 'token', 'trade', ])), }, } } type TableRow = { val: string | number | PublicKey highlight: boolean } type TableData = { title: string data: Array> } type RiskData = { timestamp: string payload: Risk } const formatValue = (val: string | number | PublicKey) => { if (val instanceof PublicKey || typeof val === 'object') { return val.toString() } if (typeof val === 'string') { return val } else { return formatNumericValue(val) } } const RiskDashboard: NextPage = () => { const { group } = useMangoGroup() const { data } = useQuery( ['risks'], async () => { try { const data = await fetch( `${MANGO_DATA_API_URL}/user-data/risk-dashboard`, ) const res = await data.json() console.log(res) return res as RiskData } catch (e) { console.log('Failed to load current season', e) } }, { cacheTime: 1000 * 60 * 5, staleTime: 1000 * 60 * 5, retry: 0, refetchOnWindowFocus: false, enabled: true, }, ) return (
{data?.timestamp ? (
As of: {data.timestamp} UTC
) : null} {group && data && data.payload ? (
{Object.entries(data.payload).map( ([tableType, table]: [string, TableData]) => { if (!table?.data?.length) return null return (

{table.title}

{Object.keys(table.data[0]).map((colName: string) => { return ( ) })} {table.data.map((rowData, index: number) => { return ( {Object.values(rowData).map((val, idx: number) => { return ( ) })} ) })}
{colName}{' '} {colName.toLowerCase().includes('fee') || colName.toLowerCase().includes('slippage') ? '(bps)' : ''} {colName.toLowerCase().includes('assets') || colName.toLowerCase().includes('liabs') || colName.toLowerCase().includes('equity') || colName.toLowerCase().includes('price') || colName.toLowerCase().includes('position') ? '($)' : ''}
{formatValue(val?.val)}
) }, )}
) : (
Loading... make take up to 60 seconds
)}
) } export default RiskDashboard