mango-v4-ui/components/shared/HealthImpact.tsx

66 lines
2.0 KiB
TypeScript
Raw Normal View History

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')
const group = mangoStore.getState().group
2022-11-18 09:09:39 -08:00
const { mangoAccount } = useMangoAccount()
2022-08-17 05:09:40 -07:00
const currentMaintHealth = useMemo(() => {
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-11-13 20:56:18 -08:00
<Tooltip content={t('health-tooltip')}>
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-11-13 20:56:18 -08:00
<div className="flex items-center space-x-1.5 font-mono">
2022-11-25 02:10:23 -08:00
<p className={`text-th-fgd-1 ${small ? 'text-xs' : 'text-sm'}`}>
2022-11-14 02:18:38 -08:00
{currentMaintHealth}%
</p>
2022-08-25 06:00:42 -07:00
<ArrowRightIcon className="h-4 w-4 text-th-fgd-4" />
2022-08-24 17:53:31 -07:00
<p
2022-11-14 02:18:38 -08:00
className={`${
2022-08-24 17:53:31 -07:00
maintProjectedHealth < 50 && maintProjectedHealth > 15
2022-11-30 19:32:32 -08:00
? 'text-th-warning'
2022-08-24 17:53:31 -07:00
: maintProjectedHealth <= 15
? 'text-th-red'
: 'text-th-green'
2022-11-25 02:10:23 -08:00
} ${small ? 'text-xs' : 'text-sm'}`}
2022-08-24 17:53:31 -07:00
>
2022-11-13 20:56:18 -08:00
{maintProjectedHealth}%
2022-08-24 17:53:31 -07:00
</p>
2022-11-13 20:56:18 -08:00
<span
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!}%)
</span>
</div>
2022-08-17 05:09:40 -07:00
</div>
)
}
export default HealthImpact