import mangoStore from '@store/mangoStore' import { HealthType, toUiDecimalsForQuote, } from '@blockworks-foundation/mango-v4' import { formatDecimal, formatFixedDecimals } from '../../utils/numbers' import Button from '../shared/Button' import { useMemo, useState } from 'react' import DepositModal from '../modals/DepositModal' import WithdrawModal from '../modals/WithdrawModal' import { useTranslation } from 'next-i18next' import { ArrowDownTrayIcon } from '@heroicons/react/20/solid' import { useWallet } from '@solana/wallet-adapter-react' import useMangoAccount from 'hooks/useMangoAccount' const MangoAccountSummary = () => { const { t } = useTranslation('common') const { connected } = useWallet() const group = mangoStore.getState().group const { mangoAccount } = useMangoAccount() const [showDepositModal, setShowDepositModal] = useState(false) const [showWithdrawModal, setShowWithdrawModal] = useState(false) const leverage = useMemo(() => { if (!group || !mangoAccount) return 0 const liabsValue = mangoAccount .getLiabsValue(group, HealthType.init)! .toNumber() const totalCollateral = mangoAccount .getAssetsValue(group, HealthType.init)! .toNumber() if (isNaN(liabsValue / totalCollateral)) { return 0 } else return liabsValue / totalCollateral }, [mangoAccount]) return ( <>

{t('health')}

{group && mangoAccount ? mangoAccount.getHealthRatioUi(group, HealthType.maint) : 0} %

{t('account-value')}

$ {group && mangoAccount ? formatDecimal( toUiDecimalsForQuote( mangoAccount.getEquity(group)!.toNumber() ), 2 ) : (0).toFixed(2)}

{t('free-collateral')}

{group && mangoAccount ? formatFixedDecimals( toUiDecimalsForQuote( mangoAccount.getCollateralValue(group)!.toNumber() ), true ) : `$${(0).toFixed(2)}`}

{t('total-collateral')}

{group && mangoAccount ? formatFixedDecimals( toUiDecimalsForQuote( mangoAccount .getAssetsValue(group, HealthType.init)! .toNumber() ), true ) : `$${(0).toFixed(2)}`}

{t('leverage')}

{leverage.toFixed(2)}x

{showDepositModal ? ( setShowDepositModal(false)} /> ) : null} {showWithdrawModal ? ( setShowWithdrawModal(false)} /> ) : null} ) } export default MangoAccountSummary