import ExplorerLink from '@components/shared/ExplorerLink' import useMangoGroup from 'hooks/useMangoGroup' import type { NextPage } from 'next' import { ChangeEvent, ReactNode, useCallback, useEffect, useState } from 'react' import { serverSideTranslations } from 'next-i18next/serverSideTranslations' import useMangoAccount from 'hooks/useMangoAccount' import { toUiDecimalsForQuote, HealthType, PerpOrder, } from '@blockworks-foundation/mango-v4' import mangoStore from '@store/mangoStore' import { DashboardNavbar } from '.' import Input from '@components/forms/Input' import Button from '@components/shared/Button' import { useRouter } from 'next/router' import { MagnifyingGlassIcon } from '@heroicons/react/20/solid' export async function getStaticProps({ locale }: { locale: string }) { return { props: { ...(await serverSideTranslations(locale, ['common', 'settings'])), }, } } const MangoAccountDashboard: NextPage = () => { const { group } = useMangoGroup() const { mangoAccount } = useMangoAccount() const client = mangoStore((s) => s.client) const [openOrders, setOpenOrders] = useState>() const router = useRouter() console.log('router.query', router.query) const [searchString, setSearchString] = useState( router.query['address'] as string, ) const loadOpenOrders = useCallback(async () => { if (!mangoAccount || !group) return const openOrders: Record = {} for (const perpOrder of mangoAccount.perpOrdersActive()) { const market = group.getPerpMarketByMarketIndex(perpOrder.orderMarket) const orders = await mangoAccount.loadPerpOpenOrdersForMarket( client, group, perpOrder.orderMarket, true, ) openOrders[market.publicKey.toString()] = orders } setOpenOrders(openOrders) }, [mangoAccount, client, group]) useEffect(() => { if (mangoAccount) { loadOpenOrders() } }, [mangoAccount, loadOpenOrders]) return (

Dashboard

) => setSearchString(e.target.value) } />
{group && mangoAccount ? (

Mango Account

} /> } /> } /> {/* */}

Token Active Positions

{mangoAccount.tokensActive().map((token) => { const bank = group.getFirstBankByTokenIndex(token.tokenIndex) return (
) })}

Serum3 Active Positions

{mangoAccount.serum3Active().map((serum) => { const market = group.getSerum3MarketByMarketIndex( serum.marketIndex, ) const extMarket = group.getSerum3ExternalMarket( market.serumMarketExternal, ) return (
} /> } />
) })}

Perp Active Positions

{mangoAccount.perpActive().map((perp) => { const market = group.getPerpMarketByMarketIndex( perp.marketIndex, ) return (
} />
) })}

Perp Open Orders

{openOrders ? Object.entries(openOrders).map( ([marketAddress, openOrders]) => { return (
} /> {openOrders.map((openOrder) => { return (
) })}
) }, ) : null}
) : (
Loading account data...
)}
) } const KeyValuePair = ({ label, value, }: { label: string value: number | ReactNode | string }) => { return (
{label} {value}
) } export default MangoAccountDashboard