import classNames from 'classnames' import { useEffect, useState } from 'react' import FormattedNumber from 'components/FormattedNumber' import Text from 'components/Text' import Tooltip from 'components/Tooltip' interface Props { balance: number limit: number max: number barHeight?: string showTitle?: boolean showPercentageText?: boolean className?: string hideValues?: boolean decimals?: number } export const BorrowCapacity = ({ balance, limit, max, barHeight = '22px', showTitle = true, showPercentageText = true, className, hideValues, decimals = 2, }: Props) => { const [percentOfMaxRound, setPercentOfMaxRound] = useState(0) const [percentOfMaxRange, setPercentOfMaxRange] = useState(0) const [limitPercentOfMax, setLimitPercentOfMax] = useState(0) useEffect( () => { if (max === 0) { setPercentOfMaxRound(0) setPercentOfMaxRange(0) setLimitPercentOfMax(0) return } const pOfMax = +((balance / max) * 100) setPercentOfMaxRound(+(Math.round(pOfMax * 100) / 100)) setPercentOfMaxRange(Math.min(Math.max(pOfMax, 0), 100)) setLimitPercentOfMax((limit / max) * 100) }, // eslint-disable-next-line react-hooks/exhaustive-deps [balance, max], ) return (
{showTitle && 'Borrow Capacity'}
{!hideValues && (
)}
Borrow Capacity Tooltip}>
{showPercentageText ? ( {max !== 0 && ( )} ) : null}
{!hideValues && (
of
)}
) }