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

92 lines
2.7 KiB
TypeScript
Raw Normal View History

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-09-07 17:47:59 -07:00
import { ArrowDownTrayIcon } from '@heroicons/react/20/solid'
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-09-07 05:00:21 -07:00
<div className="mb-4 space-y-2">
<div>
<p className="text-sm text-th-fgd-3">{t('health')}</p>
<p className="text-sm font-bold text-th-fgd-1">
{mangoAccount
? mangoAccount.getHealthRatioUi(HealthType.maint)
: 100}
%
</p>
</div>
<div>
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(
toUiDecimalsForQuote(mangoAccount.getEquity()!.toNumber()),
2022-07-14 20:38:02 -07:00
2
)
: (0).toFixed(2)}
</p>
</div>
2022-09-07 05:00:21 -07:00
<div>
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-08-11 12:29:07 -07:00
),
2022-07-14 20:38:02 -07:00
2
)
: (0).toFixed(2)}
</p>
</div>
</div>
2022-09-07 05:00:21 -07:00
<div className="space-y-2">
2022-09-07 17:47:59 -07:00
<Button
className="flex w-full items-center justify-center"
onClick={() => setShowDepositModal(true)}
>
<ArrowDownTrayIcon className="mr-2 h-5 w-5" />
2022-07-15 04:09:23 -07:00
{t('deposit')}
</Button>
2022-09-07 05:00:21 -07:00
{/* <Button
className="w-full"
2022-07-15 04:09:23 -07:00
onClick={() => setShowWithdrawModal(true)}
secondary
>
{t('withdraw')}
2022-09-07 05:00:21 -07:00
</Button> */}
2022-07-15 04:09:23 -07:00
</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