fix nan on risk dashboard
This commit is contained in:
parent
83f60f6277
commit
ff471e6283
|
@ -4,10 +4,15 @@ import { serverSideTranslations } from 'next-i18next/serverSideTranslations'
|
||||||
import { DashboardNavbar } from '.'
|
import { DashboardNavbar } from '.'
|
||||||
import { Table, Td, Th, TrBody, TrHead } from '@components/shared/TableElements'
|
import { Table, Td, Th, TrBody, TrHead } from '@components/shared/TableElements'
|
||||||
import { useQuery } from '@tanstack/react-query'
|
import { useQuery } from '@tanstack/react-query'
|
||||||
import mangoStore from '@store/mangoStore'
|
import { emptyWallet } from '@store/mangoStore'
|
||||||
import { getRiskStats } from '@blockworks-foundation/mango-v4'
|
import {
|
||||||
|
MANGO_V4_ID,
|
||||||
|
MangoClient,
|
||||||
|
getRiskStats,
|
||||||
|
} from '@blockworks-foundation/mango-v4'
|
||||||
import { PublicKey } from '@solana/web3.js'
|
import { PublicKey } from '@solana/web3.js'
|
||||||
import { formatNumericValue } from 'utils/numbers'
|
import { formatNumericValue } from 'utils/numbers'
|
||||||
|
import { AnchorProvider, web3 } from '@project-serum/anchor'
|
||||||
|
|
||||||
export async function getStaticProps({ locale }: { locale: string }) {
|
export async function getStaticProps({ locale }: { locale: string }) {
|
||||||
return {
|
return {
|
||||||
|
@ -19,9 +24,7 @@ export async function getStaticProps({ locale }: { locale: string }) {
|
||||||
|
|
||||||
type TableData = {
|
type TableData = {
|
||||||
title: string
|
title: string
|
||||||
data: Array<
|
data: Array<Record<string, string | number | PublicKey>>
|
||||||
Record<string, { val: string | number | PublicKey; highlight: boolean }>
|
|
||||||
>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const formatValue = (val: string | number | PublicKey) => {
|
const formatValue = (val: string | number | PublicKey) => {
|
||||||
|
@ -37,11 +40,27 @@ const formatValue = (val: string | number | PublicKey) => {
|
||||||
|
|
||||||
const RiskDashboard: NextPage = () => {
|
const RiskDashboard: NextPage = () => {
|
||||||
const { group } = useMangoGroup()
|
const { group } = useMangoGroup()
|
||||||
const client = mangoStore((s) => s.client)
|
|
||||||
|
|
||||||
const { data, isLoading, isFetching } = useQuery(
|
const { data, isLoading, isFetching } = useQuery(
|
||||||
['risks'],
|
['risks'],
|
||||||
() => group && getRiskStats(client, group),
|
() => {
|
||||||
|
const provider = new AnchorProvider(
|
||||||
|
new web3.Connection(
|
||||||
|
'https://mango.rpcpool.com/0f9acc0d45173b51bf7d7e09c1e5',
|
||||||
|
'processed'
|
||||||
|
),
|
||||||
|
emptyWallet,
|
||||||
|
AnchorProvider.defaultOptions()
|
||||||
|
)
|
||||||
|
const client = MangoClient.connect(
|
||||||
|
provider,
|
||||||
|
'mainnet-beta',
|
||||||
|
MANGO_V4_ID['mainnet-beta']
|
||||||
|
)
|
||||||
|
if (group) {
|
||||||
|
return getRiskStats(client, group)
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
cacheTime: 1000 * 60 * 5,
|
cacheTime: 1000 * 60 * 5,
|
||||||
staleTime: 1000 * 60 * 5,
|
staleTime: 1000 * 60 * 5,
|
||||||
|
@ -99,27 +118,18 @@ const RiskDashboard: NextPage = () => {
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{table.data.map((rowData, index: number) => {
|
{table.data.map((rowData, index: number) => {
|
||||||
|
console.log('rowData', Object.values(rowData))
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TrBody key={index}>
|
<TrBody key={index}>
|
||||||
{Object.values(rowData).map(
|
{Object.values(rowData).map(
|
||||||
(
|
(
|
||||||
col: {
|
val: string | number | PublicKey,
|
||||||
val: string | number | PublicKey
|
|
||||||
highlight: boolean
|
|
||||||
},
|
|
||||||
idx: number
|
idx: number
|
||||||
) => {
|
) => {
|
||||||
return (
|
return (
|
||||||
<Td
|
<Td xBorder className={''} key={idx}>
|
||||||
xBorder
|
{formatValue(val)}
|
||||||
className={
|
|
||||||
col.highlight
|
|
||||||
? 'text-left text-th-warning'
|
|
||||||
: ''
|
|
||||||
}
|
|
||||||
key={idx}
|
|
||||||
>
|
|
||||||
{formatValue(col.val)}
|
|
||||||
</Td>
|
</Td>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,7 +93,7 @@ const ENDPOINTS = [
|
||||||
const options = AnchorProvider.defaultOptions()
|
const options = AnchorProvider.defaultOptions()
|
||||||
export const CLUSTER: 'mainnet-beta' | 'devnet' = 'mainnet-beta'
|
export const CLUSTER: 'mainnet-beta' | 'devnet' = 'mainnet-beta'
|
||||||
const ENDPOINT = ENDPOINTS.find((e) => e.name === CLUSTER) || ENDPOINTS[0]
|
const ENDPOINT = ENDPOINTS.find((e) => e.name === CLUSTER) || ENDPOINTS[0]
|
||||||
const emptyWallet = new EmptyWallet(Keypair.generate())
|
export const emptyWallet = new EmptyWallet(Keypair.generate())
|
||||||
|
|
||||||
const initMangoClient = (
|
const initMangoClient = (
|
||||||
provider: AnchorProvider,
|
provider: AnchorProvider,
|
||||||
|
|
Loading…
Reference in New Issue