mango-ui-v3/components/MarginInfo.tsx

119 lines
4.5 KiB
TypeScript
Raw Normal View History

2021-07-07 13:38:04 -07:00
import { ZERO_I80F48 } from '@blockworks-foundation/mango-client'
2021-07-05 08:03:57 -07:00
import { HeartIcon } from '@heroicons/react/outline'
import useMangoStore from '../stores/useMangoStore'
import FloatingElement from './FloatingElement'
import { ElementTitle } from './styles'
2021-04-16 11:16:31 -07:00
import Tooltip from './Tooltip'
2021-07-05 08:03:57 -07:00
2021-04-14 23:16:36 -07:00
export default function MarginInfo() {
2021-07-22 04:34:03 -07:00
const connected = useMangoStore((s) => s.wallet.connected)
const mangoGroup = useMangoStore((s) => s.selectedMangoGroup.current)
const mangoCache = useMangoStore((s) => s.selectedMangoGroup.cache)
2021-07-06 17:13:17 -07:00
const mangoAccount = useMangoStore((s) => s.selectedMangoAccount.current)
2021-07-06 17:13:17 -07:00
const maintHealth = mangoAccount
? mangoAccount.getHealthRatio(mangoGroup, mangoCache, 'Maint')
2021-07-22 04:34:03 -07:00
: 100
2021-07-05 08:03:57 -07:00
2021-07-07 13:38:04 -07:00
const equity = mangoAccount
? mangoAccount.computeValue(mangoGroup, mangoCache)
: ZERO_I80F48
const leverage =
mangoAccount && equity.gt(ZERO_I80F48)
? mangoAccount.getLiabsVal(mangoGroup, mangoCache).div(equity)
: 0.0
2021-07-06 21:34:21 -07:00
2021-07-05 08:03:57 -07:00
return (
2021-07-22 04:34:03 -07:00
<FloatingElement showConnect>
<div className={!connected && 'filter blur-sm'}>
<ElementTitle>Account</ElementTitle>
<div>
2021-07-05 08:03:57 -07:00
<div>
2021-07-06 21:34:21 -07:00
<div className={`flex justify-between pt-2 pb-2`}>
<Tooltip content="Account value">
<div
className={`cursor-help font-normal text-th-fgd-3 border-b border-th-fgd-3 border-dashed border-opacity-20 leading-4 default-transition hover:border-th-bkg-2 hover:text-th-fgd-3`}
2021-07-06 21:34:21 -07:00
>
Equity
</div>
</Tooltip>
2021-07-07 13:38:04 -07:00
<div className={`text-th-fgd-1`}>${equity.toFixed(2)}</div>
2021-07-06 21:34:21 -07:00
</div>
<div className={`flex justify-between pt-2 pb-2`}>
<div className="font-normal text-th-fgd-3 leading-4">
Leverage
</div>
2021-07-06 21:34:21 -07:00
<div className={`text-th-fgd-1`}>{leverage.toFixed(2)}x</div>
</div>
<div className={`flex justify-between pt-2 pb-2`}>
<Tooltip content="Leverage">
<div className="font-normal text-th-fgd-3 leading-4">
Total Assets Value
2021-07-06 21:34:21 -07:00
</div>
</Tooltip>
<div className={`text-th-fgd-1`}>
2021-07-22 04:34:03 -07:00
$
{mangoAccount
? mangoAccount.getAssetsVal(mangoGroup, mangoCache).toFixed(2)
: 0}
2021-07-06 21:34:21 -07:00
</div>
</div>
<div className={`flex justify-between pt-2 pb-2`}>
<Tooltip content="Leverage">
<div className="font-normal text-th-fgd-3 leading-4">
Total Liabilities Value
2021-07-06 21:34:21 -07:00
</div>
</Tooltip>
<div className={`text-th-fgd-1`}>
2021-07-22 04:34:03 -07:00
$
{mangoAccount
? mangoAccount.getLiabsVal(mangoGroup, mangoCache).toFixed(2)
: 0}
2021-07-06 21:34:21 -07:00
</div>
</div>
2021-07-01 07:12:42 -07:00
<div className={`flex justify-between pt-2 pb-2`}>
<Tooltip content="Must be above 0% to borrow funds">
2021-07-01 07:12:42 -07:00
<div
className={`cursor-help font-normal text-th-fgd-3 border-b border-th-fgd-3 border-dashed border-opacity-20 leading-4 default-transition hover:border-th-bkg-2 hover:text-th-fgd-3`}
2021-07-01 07:12:42 -07:00
>
2021-07-05 08:03:57 -07:00
Init Ratio
2021-07-01 07:12:42 -07:00
</div>
</Tooltip>
<div className={`text-th-fgd-1`}>
2021-07-06 17:13:17 -07:00
{mangoAccount
2021-07-22 04:34:03 -07:00
? mangoAccount
.getHealthRatio(mangoGroup, mangoCache, 'Init')
.toFixed(2)
: 100.0}
%
2021-07-01 07:12:42 -07:00
</div>
</div>
2021-07-05 08:03:57 -07:00
</div>
2021-07-22 05:25:18 -07:00
<div className="border border-th-bkg-3 mt-4 p-4 rounded">
2021-07-22 04:34:03 -07:00
<div className="flex flex-col">
<div className="flex justify-between">
<div className="flex items-center">
<HeartIcon className="h-5 w-5" aria-hidden="true" />
<span className="ml-2">Health Ratio</span>
</div>
<div className="text-right">{maintHealth.toFixed(2)}%</div>
2021-07-01 07:12:42 -07:00
</div>
2021-07-22 04:34:03 -07:00
<div className="mt-4">
2021-07-22 05:25:18 -07:00
<div className="h-1.5 flex rounded bg-th-bkg-3">
2021-07-22 04:34:03 -07:00
<div
style={{
width: `${maintHealth}%`,
}}
className="flex rounded bg-th-primary"
></div>
</div>
2021-07-01 07:12:42 -07:00
</div>
</div>
2021-07-05 08:03:57 -07:00
</div>
</div>
</div>
</FloatingElement>
)
}