mango-v4-ui/components/account/MangoAccountSummary.tsx

94 lines
2.9 KiB
TypeScript
Raw Normal View History

2022-09-12 08:53:57 -07:00
import mangoStore from '@store/mangoStore'
2022-08-11 12:29:07 -07:00
import {
HealthType,
toUiDecimalsForQuote,
} from '@blockworks-foundation/mango-v4'
import { formatDecimal, formatFixedDecimals } from '../../utils/numbers'
2022-07-15 04:09:23 -07:00
import { useTranslation } from 'next-i18next'
2022-11-18 09:09:39 -08:00
import useMangoAccount from 'hooks/useMangoAccount'
2022-07-14 20:38:02 -07:00
2022-10-05 17:04:16 -07:00
const MangoAccountSummary = () => {
2022-07-15 04:09:23 -07:00
const { t } = useTranslation('common')
const group = mangoStore.getState().group
2022-11-18 09:09:39 -08:00
const { mangoAccount } = useMangoAccount()
2022-07-14 20:38:02 -07:00
// 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])
2022-10-04 20:30:19 -07:00
2022-07-14 20:38:02 -07:00
return (
<>
<div className="space-y-2">
2022-09-07 05:00:21 -07:00
<div>
<p className="text-sm text-th-fgd-3">{t('health')}</p>
2022-10-05 16:03:10 -07:00
<p className="font-mono text-sm text-th-fgd-1">
{group && mangoAccount
? mangoAccount.getHealthRatioUi(group, HealthType.maint)
: 0}
2022-09-07 05:00:21 -07:00
%
</p>
</div>
<div>
<p className="text-sm text-th-fgd-3">{t('account-value')}</p>
2022-10-05 16:03:10 -07:00
<p className="font-mono text-sm text-th-fgd-1">
2022-07-14 20:38:02 -07:00
$
{group && mangoAccount
2022-07-14 20:38:02 -07:00
? formatDecimal(
toUiDecimalsForQuote(
2022-11-20 15:35:59 -08:00
mangoAccount.getEquity(group).toNumber()
),
2022-07-14 20:38:02 -07:00
2
)
: (0).toFixed(2)}
</p>
</div>
2022-10-04 19:45:06 -07:00
<div>
<p className="text-sm text-th-fgd-3">{t('free-collateral')}</p>
2022-10-05 16:03:10 -07:00
<p className="font-mono text-sm text-th-fgd-1">
{group && mangoAccount
? formatFixedDecimals(
2022-10-04 19:45:06 -07:00
toUiDecimalsForQuote(
2022-11-20 15:35:59 -08:00
mangoAccount.getCollateralValue(group).toNumber()
2022-10-04 19:45:06 -07:00
),
true
2022-10-04 19:45:06 -07:00
)
: `$${(0).toFixed(2)}`}
2022-10-04 19:45:06 -07:00
</p>
</div>
2022-09-07 05:00:21 -07:00
<div>
<p className="text-sm text-th-fgd-3">{t('total-collateral')}</p>
2022-10-05 16:03:10 -07:00
<p className="font-mono text-sm text-th-fgd-1">
{group && mangoAccount
? formatFixedDecimals(
2022-08-11 12:29:07 -07:00
toUiDecimalsForQuote(
mangoAccount
2022-11-20 15:35:59 -08:00
.getAssetsValue(group, HealthType.init)
.toNumber()
2022-08-11 12:29:07 -07:00
),
true
2022-07-14 20:38:02 -07:00
)
: `$${(0).toFixed(2)}`}
2022-07-14 20:38:02 -07:00
</p>
</div>
{/* <div>
<p className="text-sm text-th-fgd-3">{t('leverage')}</p>
2022-10-05 16:03:10 -07:00
<p className="font-mono text-sm text-th-fgd-1">
2022-10-04 20:30:19 -07:00
{leverage.toFixed(2)}x
</p>
</div> */}
2022-07-14 20:38:02 -07:00
</div>
</>
)
}
export default MangoAccountSummary