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">
|
2023-03-10 10:01:47 -08:00
|
|
|
|
<Tooltip content={t('health-tooltip')} delay={100}>
|
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">
|
2023-07-03 06:17:17 -07:00
|
|
|
|
<p
|
|
|
|
|
className={`font-mono text-th-fgd-2 ${
|
|
|
|
|
small ? 'text-xs' : 'text-sm'
|
|
|
|
|
}`}
|
|
|
|
|
>
|
2022-12-08 15:42:55 -08:00
|
|
|
|
{currentMaintHealth}%
|
|
|
|
|
</p>
|
|
|
|
|
<ArrowRightIcon className="h-4 w-4 text-th-fgd-4" />
|
|
|
|
|
<p
|
2023-07-03 06:17:17 -07:00
|
|
|
|
className={`font-mono ${
|
2022-12-08 15:42:55 -08:00
|
|
|
|
maintProjectedHealth < 50 && maintProjectedHealth > 15
|
|
|
|
|
? 'text-th-warning'
|
|
|
|
|
: maintProjectedHealth <= 15
|
|
|
|
|
? 'text-th-down'
|
|
|
|
|
: 'text-th-up'
|
|
|
|
|
} ${small ? 'text-xs' : 'text-sm'}`}
|
|
|
|
|
>
|
|
|
|
|
{maintProjectedHealth}%
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
2023-06-07 19:30:56 -07:00
|
|
|
|
<span className="text-xs text-th-fgd-2">–</span>
|
2022-12-08 15:42:55 -08:00
|
|
|
|
)}
|
2022-08-17 05:09:40 -07:00
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default HealthImpact
|