2022-09-06 21:36:35 -07:00
|
|
|
|
import { HealthType } from '@blockworks-foundation/mango-v4'
|
|
|
|
|
import { ArrowRightIcon } from '@heroicons/react/20/solid'
|
2022-08-17 05:09:40 -07:00
|
|
|
|
import { useTranslation } from 'next-i18next'
|
|
|
|
|
import { useMemo } from 'react'
|
2022-09-12 08:53:57 -07:00
|
|
|
|
import mangoStore from '@store/mangoStore'
|
2022-11-04 11:55:21 -07:00
|
|
|
|
import Tooltip from './Tooltip'
|
2022-11-18 09:09:39 -08:00
|
|
|
|
import useMangoAccount from 'hooks/useMangoAccount'
|
2022-08-17 05:09:40 -07:00
|
|
|
|
|
|
|
|
|
const HealthImpact = ({
|
2022-11-04 11:55:21 -07:00
|
|
|
|
maintProjectedHealth,
|
2022-11-25 02:10:23 -08:00
|
|
|
|
small,
|
2022-08-17 05:09:40 -07:00
|
|
|
|
}: {
|
2022-11-04 11:55:21 -07:00
|
|
|
|
maintProjectedHealth: number
|
2022-11-25 02:10:23 -08:00
|
|
|
|
small?: boolean
|
2022-08-17 05:09:40 -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-08-17 05:09:40 -07:00
|
|
|
|
|
2022-08-23 12:32:51 -07:00
|
|
|
|
const currentMaintHealth = useMemo(() => {
|
2022-10-07 05:22:18 -07:00
|
|
|
|
if (!group || !mangoAccount) return 0
|
|
|
|
|
return mangoAccount.getHealthRatioUi(group, HealthType.maint)
|
2022-08-17 05:09:40 -07:00
|
|
|
|
}, [mangoAccount])
|
|
|
|
|
|
|
|
|
|
return (
|
2022-11-04 11:55:21 -07:00
|
|
|
|
<div className="flex flex-wrap items-start justify-between">
|
2022-12-08 03:15:16 -08:00
|
|
|
|
<Tooltip content={t('health-tooltip')} delay={250}>
|
2022-11-14 02:18:38 -08:00
|
|
|
|
<p
|
2022-12-01 18:16:59 -08:00
|
|
|
|
className={`tooltip-underline mr-4 ${small ? 'text-xs' : 'text-sm'}`}
|
2022-11-14 02:18:38 -08:00
|
|
|
|
>
|
2022-11-04 11:55:21 -07:00
|
|
|
|
{t('health-impact')}
|
|
|
|
|
</p>
|
|
|
|
|
</Tooltip>
|
2022-12-08 15:42:55 -08:00
|
|
|
|
{currentMaintHealth ? (
|
|
|
|
|
<div className="flex items-center space-x-1.5 font-mono">
|
|
|
|
|
<p className={`text-th-fgd-2 ${small ? 'text-xs' : 'text-sm'}`}>
|
|
|
|
|
{currentMaintHealth}%
|
|
|
|
|
</p>
|
|
|
|
|
<ArrowRightIcon className="h-4 w-4 text-th-fgd-4" />
|
|
|
|
|
<p
|
|
|
|
|
className={`${
|
|
|
|
|
maintProjectedHealth < 50 && maintProjectedHealth > 15
|
|
|
|
|
? 'text-th-warning'
|
|
|
|
|
: maintProjectedHealth <= 15
|
|
|
|
|
? 'text-th-down'
|
|
|
|
|
: 'text-th-up'
|
|
|
|
|
} ${small ? 'text-xs' : 'text-sm'}`}
|
|
|
|
|
>
|
|
|
|
|
{maintProjectedHealth}%
|
|
|
|
|
</p>
|
|
|
|
|
{/* <span
|
2022-11-13 20:56:18 -08:00
|
|
|
|
className={`text-xs ${
|
|
|
|
|
maintProjectedHealth >= currentMaintHealth!
|
2022-11-30 19:32:32 -08:00
|
|
|
|
? 'text-th-up'
|
|
|
|
|
: 'text-th-down'
|
2022-11-13 20:56:18 -08:00
|
|
|
|
}`}
|
|
|
|
|
>
|
|
|
|
|
({maintProjectedHealth >= currentMaintHealth! ? '+' : ''}
|
|
|
|
|
{maintProjectedHealth - currentMaintHealth!}%)
|
2022-12-07 19:24:14 -08:00
|
|
|
|
</span> */}
|
2022-12-08 15:42:55 -08:00
|
|
|
|
</div>
|
|
|
|
|
) : (
|
2022-12-13 18:23:01 -08:00
|
|
|
|
<span className="text-xs">–</span>
|
2022-12-08 15:42:55 -08:00
|
|
|
|
)}
|
2022-08-17 05:09:40 -07:00
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default HealthImpact
|