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-08-17 05:09:40 -07:00
const HealthImpact = ( {
2022-11-04 11:55:21 -07:00
maintProjectedHealth ,
2022-08-17 05:09:40 -07:00
} : {
2022-11-04 11:55:21 -07:00
maintProjectedHealth : number
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-08-17 05:09:40 -07:00
const mangoAccount = mangoStore ( ( s ) = > s . mangoAccount . current )
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" >
< Tooltip content = "Projects the health of your account before you make a trade. The first value is your current account health and the second, your projected account health." >
< p className = "tooltip-underline mr-4 mb-1 text-sm" >
{ t ( 'health-impact' ) }
< / p >
< / Tooltip >
2022-10-05 16:14:11 -07:00
< div className = "flex items-center space-x-2 font-mono" >
2022-08-24 17:53:31 -07:00
< p className = "text-th-fgd-1" > { 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
className = {
maintProjectedHealth < 50 && maintProjectedHealth > 15
? 'text-th-orange'
: maintProjectedHealth <= 15
? 'text-th-red'
: 'text-th-green'
}
>
2022-08-28 04:03:15 -07:00
{ maintProjectedHealth } % { ' ' }
2022-08-24 17:53:31 -07:00
< span
className = { ` text-xs ${
2022-08-31 13:17:17 -07:00
maintProjectedHealth >= currentMaintHealth !
2022-08-24 17:53:31 -07:00
? 'text-th-green'
: 'text-th-red'
} ` }
2022-08-23 12:32:51 -07:00
>
2022-08-31 13:17:17 -07:00
( { maintProjectedHealth >= currentMaintHealth ! ? '+' : '' }
{ maintProjectedHealth - currentMaintHealth ! } % )
2022-08-24 17:53:31 -07:00
< / span >
< / p >
2022-08-23 12:32:51 -07:00
< / div >
2022-08-17 05:09:40 -07:00
< / div >
)
}
export default HealthImpact