import classNames from 'classnames' import { useMemo } from 'react' import { Heart } from 'components/Icons' import { Tooltip } from 'components/Tooltip' import { DEFAULT_SETTINGS } from 'constants/defaultSettings' import { REDUCE_MOTION_KEY } from 'constants/localStore' import useHealthColorAndLabel from 'hooks/useHealthColorAndLabel' import useLocalStorage from 'hooks/useLocalStorage' import { computeHealthGaugePercentage } from 'utils/accounts' import { getHealthIndicatorColors } from 'utils/healthIndicator' interface Props { diameter?: number health: number updatedHealth?: number } const RADIUS = 350 const ROTATION = { rotate: '-126deg', transformOrigin: 'center', } export const HealthGauge = ({ diameter = 40, health = 0, updatedHealth = 0 }: Props) => { const [color, label] = useHealthColorAndLabel(health, 'text') const [updatedColor, updatedLabel] = useHealthColorAndLabel(updatedHealth ?? 0, 'text') const [reduceMotion] = useLocalStorage(REDUCE_MOTION_KEY, DEFAULT_SETTINGS.reduceMotion) const percentage = useMemo(() => computeHealthGaugePercentage(health), [health]) const updatedPercentage = useMemo( () => computeHealthGaugePercentage(updatedHealth), [updatedHealth], ) const isUpdated = updatedHealth !== 0 && updatedPercentage !== percentage const isIncrease = isUpdated && updatedPercentage < percentage const [backgroundColor, foreGroundColor] = useMemo( () => getHealthIndicatorColors(color, updatedColor, 'text', isUpdated, isIncrease), [color, updatedColor, isUpdated, isIncrease], ) const tooltipContent = health === 0 ? 'loading...' : isUpdated ? updatedLabel : label return (
{isUpdated && ( )}
) }