import { useMemo } from 'react' import { // ChartBarIcon, ScaleIcon, CurrencyDollarIcon, GiftIcon, HeartIcon, } from '@heroicons/react/outline' import { nativeToUi, ZERO_BN } from '@blockworks-foundation/mango-client' import useMangoStore, { MNGO_INDEX } from '../../stores/useMangoStore' import { formatUsdValue } from '../../utils' import { notify } from '../../utils/notifications' import { LinkButton } from '../Button' import BalancesTable from '../BalancesTable' import PositionsTable from '../PerpPositionsTable' import Switch from '../Switch' import useLocalStorageState from '../../hooks/useLocalStorageState' import { ExclamationIcon } from '@heroicons/react/solid' import { useTranslation } from 'next-i18next' const SHOW_ZERO_BALANCE_KEY = 'showZeroAccountBalances-0.2' export default function AccountOverview() { const { t } = useTranslation('common') const actions = useMangoStore((s) => s.actions) const mangoAccount = useMangoStore((s) => s.selectedMangoAccount.current) const mangoGroup = useMangoStore((s) => s.selectedMangoGroup.current) const mangoCache = useMangoStore((s) => s.selectedMangoGroup.cache) const mangoClient = useMangoStore((s) => s.connection.client) const [showZeroBalances, setShowZeroBalances] = useLocalStorageState( SHOW_ZERO_BALANCE_KEY, true ) const maintHealthRatio = useMemo(() => { return mangoAccount ? mangoAccount.getHealthRatio(mangoGroup, mangoCache, 'Maint') : 100 }, [mangoAccount, mangoGroup, mangoCache]) const initHealthRatio = useMemo(() => { return mangoAccount ? mangoAccount.getHealthRatio(mangoGroup, mangoCache, 'Init') : 100 }, [mangoAccount, mangoGroup, mangoCache]) const mngoAccrued = useMemo(() => { return mangoAccount ? mangoAccount.perpAccounts.reduce((acc, perpAcct) => { return perpAcct.mngoAccrued.add(acc) }, ZERO_BN) : ZERO_BN }, [mangoAccount]) const handleRedeemMngo = async () => { const wallet = useMangoStore.getState().wallet.current const mngoNodeBank = mangoGroup.rootBankAccounts[MNGO_INDEX].nodeBankAccounts[0] try { const txid = await mangoClient.redeemAllMngo( mangoGroup, mangoAccount, wallet, mangoGroup.tokens[MNGO_INDEX].rootBank, mngoNodeBank.publicKey, mngoNodeBank.vault ) actions.reloadMangoAccount() notify({ title: t('redeem-success'), description: '', txid, }) } catch (e) { notify({ title: t('redeem-failure'), description: e.message, txid: e.txid, type: 'error', }) } } return mangoAccount ? ( <>