2022-08-20 11:17: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-07-14 22:20:20 -07:00
|
|
|
import { formatDecimal } from '../../utils/numbers'
|
2022-07-15 04:09:23 -07:00
|
|
|
import Button from '../shared/Button'
|
|
|
|
import { useState } from 'react'
|
|
|
|
import DepositModal from '../modals/DepositModal'
|
|
|
|
import WithdrawModal from '../modals/WithdrawModal'
|
|
|
|
import { useTranslation } from 'next-i18next'
|
2022-07-14 20:38:02 -07:00
|
|
|
|
|
|
|
const MangoAccountSummary = () => {
|
2022-07-15 04:09:23 -07:00
|
|
|
const { t } = useTranslation('common')
|
2022-07-27 23:35:18 -07:00
|
|
|
const mangoAccount = mangoStore((s) => s.mangoAccount.current)
|
2022-07-15 04:09:23 -07:00
|
|
|
const [showDepositModal, setShowDepositModal] = useState(false)
|
|
|
|
const [showWithdrawModal, setShowWithdrawModal] = useState(false)
|
2022-07-14 20:38:02 -07:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2022-07-26 04:15:07 -07:00
|
|
|
<div className="mb-4 space-y-1.5">
|
2022-07-14 20:38:02 -07:00
|
|
|
<div className="flex items-center justify-between">
|
2022-08-03 05:13:40 -07:00
|
|
|
<p className="text-sm text-th-fgd-3">{t('account-value')}</p>
|
2022-08-02 19:15:17 -07:00
|
|
|
<p className="text-sm font-bold text-th-fgd-1">
|
2022-07-14 20:38:02 -07:00
|
|
|
$
|
|
|
|
{mangoAccount
|
|
|
|
? formatDecimal(
|
2022-08-11 12:29:07 -07:00
|
|
|
toUiDecimalsForQuote(mangoAccount.getEquity().toNumber()),
|
2022-07-14 20:38:02 -07:00
|
|
|
2
|
|
|
|
)
|
|
|
|
: (0).toFixed(2)}
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<div className="flex items-center justify-between">
|
2022-08-03 05:13:40 -07:00
|
|
|
<p className="text-sm text-th-fgd-3">{t('free-collateral')}</p>
|
2022-08-02 19:15:17 -07:00
|
|
|
<p className="text-sm font-bold text-th-fgd-1">
|
2022-07-14 20:38:02 -07:00
|
|
|
$
|
|
|
|
{mangoAccount
|
|
|
|
? formatDecimal(
|
2022-08-11 12:29:07 -07:00
|
|
|
toUiDecimalsForQuote(
|
|
|
|
mangoAccount.getCollateralValue().toNumber()
|
|
|
|
),
|
2022-07-14 20:38:02 -07:00
|
|
|
2
|
|
|
|
)
|
|
|
|
: (0).toFixed(2)}
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<div className="flex items-center justify-between">
|
2022-08-03 05:13:40 -07:00
|
|
|
<p className="text-sm text-th-fgd-3">{t('health')}</p>
|
2022-08-02 19:15:17 -07:00
|
|
|
<p className="text-sm font-bold text-th-fgd-1">
|
2022-07-14 20:38:02 -07:00
|
|
|
{mangoAccount
|
2022-08-20 11:05:00 -07:00
|
|
|
? mangoAccount.getHealthRatioUi(HealthType.maint)
|
2022-07-14 20:38:02 -07:00
|
|
|
: 100}
|
|
|
|
%
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-07-15 04:09:23 -07:00
|
|
|
<div className="flex items-center space-x-2">
|
|
|
|
<Button
|
|
|
|
className="w-1/2 pl-3 pr-3"
|
|
|
|
onClick={() => setShowDepositModal(true)}
|
|
|
|
>
|
|
|
|
{t('deposit')}
|
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
className="w-1/2 pl-3 pr-3"
|
|
|
|
onClick={() => setShowWithdrawModal(true)}
|
|
|
|
secondary
|
|
|
|
>
|
|
|
|
{t('withdraw')}
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
{showDepositModal ? (
|
|
|
|
<DepositModal
|
|
|
|
isOpen={showDepositModal}
|
|
|
|
onClose={() => setShowDepositModal(false)}
|
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
{showWithdrawModal ? (
|
|
|
|
<WithdrawModal
|
|
|
|
isOpen={showWithdrawModal}
|
|
|
|
onClose={() => setShowWithdrawModal(false)}
|
|
|
|
/>
|
|
|
|
) : null}
|
2022-07-14 20:38:02 -07:00
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default MangoAccountSummary
|