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'
|
2022-10-04 21:47:50 -07:00
|
|
|
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')
|
2022-10-07 05:22:18 -07:00
|
|
|
const group = mangoStore.getState().group
|
2022-11-18 09:09:39 -08:00
|
|
|
const { mangoAccount } = useMangoAccount()
|
2022-07-14 20:38:02 -07:00
|
|
|
|
2022-12-13 09:38:59 -08: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 (
|
|
|
|
<>
|
2022-12-17 04:37:00 -08:00
|
|
|
<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">
|
2022-10-07 05:22:18 -07:00
|
|
|
{group && mangoAccount
|
|
|
|
? mangoAccount.getHealthRatioUi(group, HealthType.maint)
|
|
|
|
: 0}
|
2022-09-07 05:00:21 -07:00
|
|
|
%
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<div>
|
2022-10-04 21:47:50 -07:00
|
|
|
<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
|
|
|
$
|
2022-10-07 05:22:18 -07:00
|
|
|
{group && mangoAccount
|
2022-07-14 20:38:02 -07:00
|
|
|
? formatDecimal(
|
2022-10-07 05:22:18 -07:00
|
|
|
toUiDecimalsForQuote(
|
2022-11-20 15:35:59 -08:00
|
|
|
mangoAccount.getEquity(group).toNumber()
|
2022-10-07 05:22:18 -07:00
|
|
|
),
|
2022-07-14 20:38:02 -07:00
|
|
|
2
|
|
|
|
)
|
|
|
|
: (0).toFixed(2)}
|
|
|
|
</p>
|
|
|
|
</div>
|
2022-10-04 19:45:06 -07:00
|
|
|
<div>
|
2022-10-04 21:47:50 -07:00
|
|
|
<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">
|
2022-10-07 05:22:18 -07:00
|
|
|
{group && mangoAccount
|
2022-10-04 21:47:50 -07:00
|
|
|
? 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
|
|
|
),
|
2022-10-04 21:47:50 -07:00
|
|
|
true
|
2022-10-04 19:45:06 -07:00
|
|
|
)
|
2022-10-04 21:47:50 -07:00
|
|
|
: `$${(0).toFixed(2)}`}
|
2022-10-04 19:45:06 -07:00
|
|
|
</p>
|
|
|
|
</div>
|
2022-09-07 05:00:21 -07:00
|
|
|
<div>
|
2022-10-04 21:47:50 -07:00
|
|
|
<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">
|
2022-10-07 05:22:18 -07:00
|
|
|
{group && mangoAccount
|
2022-10-04 21:47:50 -07:00
|
|
|
? formatFixedDecimals(
|
2022-08-11 12:29:07 -07:00
|
|
|
toUiDecimalsForQuote(
|
2022-10-07 05:22:18 -07:00
|
|
|
mangoAccount
|
2022-11-20 15:35:59 -08:00
|
|
|
.getAssetsValue(group, HealthType.init)
|
2022-10-07 05:22:18 -07:00
|
|
|
.toNumber()
|
2022-08-11 12:29:07 -07:00
|
|
|
),
|
2022-10-04 21:47:50 -07:00
|
|
|
true
|
2022-07-14 20:38:02 -07:00
|
|
|
)
|
2022-10-04 21:47:50 -07:00
|
|
|
: `$${(0).toFixed(2)}`}
|
2022-07-14 20:38:02 -07:00
|
|
|
</p>
|
|
|
|
</div>
|
2022-12-13 09:38:59 -08:00
|
|
|
{/* <div>
|
2022-10-04 21:47:50 -07:00
|
|
|
<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>
|
2022-12-13 09:38:59 -08:00
|
|
|
</div> */}
|
2022-07-14 20:38:02 -07:00
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default MangoAccountSummary
|