|
1 | | -import classNames from 'classnames' |
2 | | - |
3 | 1 | import DisplayCurrency from 'components/common/DisplayCurrency' |
4 | | -import { FormattedNumber } from 'components/common/FormattedNumber' |
5 | | -import TitleAndSubCell from 'components/common/TitleAndSubCell' |
| 2 | +import { Tooltip } from 'components/common/Tooltip' |
| 3 | +import AnimatedCircularProgressBar from 'components/common/ProgressBars/AnimatedCircularProgressBar' |
| 4 | +import Text from 'components/common/Text' |
6 | 5 | import { BNCoin } from 'types/classes/BNCoin' |
| 6 | +import useAssets from 'hooks/assets/useAssets' |
| 7 | +import useDisplayCurrency from 'hooks/localStorage/useDisplayCurrency' |
| 8 | +import useDisplayCurrencyAssets from 'hooks/assets/useDisplayCurrencyAssets' |
| 9 | +import { getCoinValueWithoutFallback } from 'utils/formatters' |
| 10 | +import { BN } from 'utils/helpers' |
| 11 | +import { FormattedNumber } from './FormattedNumber' |
| 12 | +import classNames from 'classnames' |
7 | 13 |
|
8 | 14 | interface Props { |
9 | 15 | depositCap: DepositCap |
10 | 16 | } |
11 | 17 |
|
12 | 18 | export default function DepositCapCell(props: Props) { |
13 | | - const percent = props.depositCap.used.dividedBy(props.depositCap.max).multipliedBy(100) |
14 | | - const depositCapUsed = Math.min(percent.toNumber(), 100) |
| 19 | + const { data: assets } = useAssets() |
| 20 | + const displayCurrencies = useDisplayCurrencyAssets() |
| 21 | + const [displayCurrency] = useDisplayCurrency() |
| 22 | + |
| 23 | + const displayCurrencyAsset = displayCurrencies.find((asset) => asset.denom === displayCurrency) |
| 24 | + |
| 25 | + const depositedCoin = BNCoin.fromDenomAndBigNumber(props.depositCap.denom, props.depositCap.used) |
| 26 | + const depositCapCoin = BNCoin.fromDenomAndBigNumber(props.depositCap.denom, props.depositCap.max) |
| 27 | + |
| 28 | + const percent = props.depositCap.max.isZero() |
| 29 | + ? BN(0) |
| 30 | + : props.depositCap.used.dividedBy(props.depositCap.max).multipliedBy(100) |
| 31 | + |
| 32 | + const capUsedPercent = percent.toNumber() |
| 33 | + const depositCapUsed = Number.isFinite(capUsedPercent) ? Math.min(capUsedPercent, 100) : 0 |
| 34 | + const textBase = 'text-xs font-semibold whitespace-nowrap text-right' |
| 35 | + const valueClassName = `${textBase} text-white` |
| 36 | + |
| 37 | + const depositedValue = getCoinValueWithoutFallback(depositedCoin, assets) |
| 38 | + const depositCapValue = getCoinValueWithoutFallback(depositCapCoin, assets) |
| 39 | + |
| 40 | + // Get asset info for proper formatting |
| 41 | + const asset = assets?.find((a) => a.denom === props.depositCap.denom) |
| 42 | + const decimals = displayCurrencyAsset?.decimals ?? 2 |
| 43 | + const gaugeMax = depositCapValue?.shiftedBy(-decimals).toNumber() ?? 0 |
| 44 | + const gaugeValue = depositedValue?.shiftedBy(-decimals).toNumber() ?? 0 |
| 45 | + |
| 46 | + // Determine colors based on usage |
| 47 | + let gaugePrimaryColor = '#FFFFFF' |
| 48 | + if (depositCapUsed >= 100) { |
| 49 | + gaugePrimaryColor = '#F87171' |
| 50 | + } else if (depositCapUsed > 90) { |
| 51 | + gaugePrimaryColor = '#F59E0B' |
| 52 | + } |
| 53 | + |
| 54 | + let displayCurrencyColorClass = 'text-white/40' |
| 55 | + if (depositCapUsed >= 100) { |
| 56 | + displayCurrencyColorClass = 'text-loss/40' |
| 57 | + } else if (depositCapUsed > 90) { |
| 58 | + displayCurrencyColorClass = 'text-warning/40' |
| 59 | + } |
| 60 | + |
| 61 | + const tooltipContent = ( |
| 62 | + <div className='flex flex-col gap-3 p-1'> |
| 63 | + <div className='flex flex-col gap-2'> |
| 64 | + <div className='flex items-start justify-between gap-6 whitespace-nowrap'> |
| 65 | + <Text size='2xs' className='text-white/60'> |
| 66 | + Deposits |
| 67 | + </Text> |
| 68 | + <div className='flex flex-col items-end gap-0.5 text-right'> |
| 69 | + <DisplayCurrency coin={depositedCoin} className={valueClassName} /> |
| 70 | + <span className='text-[10px] text-white/40'> |
| 71 | + {asset && ( |
| 72 | + <FormattedNumber |
| 73 | + amount={depositedCoin.amount.toNumber()} |
| 74 | + className='text-xs text-white/60 whitespace-nowrap' |
| 75 | + options={{ |
| 76 | + abbreviated: true, |
| 77 | + decimals: asset?.decimals, |
| 78 | + suffix: ` ${asset?.symbol}`, |
| 79 | + minDecimals: 0, |
| 80 | + maxDecimals: Math.min(asset?.decimals, 6), |
| 81 | + }} |
| 82 | + /> |
| 83 | + )} |
| 84 | + </span> |
| 85 | + </div> |
| 86 | + </div> |
| 87 | + <div className='flex items-start justify-between gap-6 whitespace-nowrap'> |
| 88 | + <Text size='2xs' className='text-white/60'> |
| 89 | + Deposit Cap |
| 90 | + </Text> |
| 91 | + <div className='flex flex-col items-end gap-0.5 text-right'> |
| 92 | + <DisplayCurrency coin={depositCapCoin} className={valueClassName} /> |
| 93 | + <span className='text-[10px] text-white/40'> |
| 94 | + {asset && ( |
| 95 | + <FormattedNumber |
| 96 | + amount={depositCapCoin.amount.toNumber()} |
| 97 | + className='text-xs text-white/60 whitespace-nowrap' |
| 98 | + options={{ |
| 99 | + abbreviated: true, |
| 100 | + decimals: asset?.decimals, |
| 101 | + suffix: ` ${asset?.symbol}`, |
| 102 | + minDecimals: 0, |
| 103 | + maxDecimals: Math.min(asset?.decimals, 6), |
| 104 | + }} |
| 105 | + /> |
| 106 | + )} |
| 107 | + </span> |
| 108 | + </div> |
| 109 | + </div> |
| 110 | + <div className='flex items-start justify-between gap-6 whitespace-nowrap'> |
| 111 | + <Text size='2xs' className='text-white/60'> |
| 112 | + Remaining |
| 113 | + </Text> |
| 114 | + <div className='flex flex-col items-end gap-0.5 text-right'> |
| 115 | + <DisplayCurrency |
| 116 | + coin={BNCoin.fromDenomAndBigNumber( |
| 117 | + props.depositCap.denom, |
| 118 | + props.depositCap.max.minus(props.depositCap.used), |
| 119 | + )} |
| 120 | + className={valueClassName} |
| 121 | + /> |
| 122 | + <span className='text-[10px] text-white/40'> |
| 123 | + {asset && ( |
| 124 | + <FormattedNumber |
| 125 | + amount={props.depositCap.max.minus(props.depositCap.used).toNumber()} |
| 126 | + className='text-xs text-white/60 whitespace-nowrap' |
| 127 | + options={{ |
| 128 | + abbreviated: true, |
| 129 | + decimals: asset?.decimals, |
| 130 | + suffix: ` ${asset?.symbol}`, |
| 131 | + minDecimals: 0, |
| 132 | + maxDecimals: Math.min(asset?.decimals, 6), |
| 133 | + }} |
| 134 | + /> |
| 135 | + )} |
| 136 | + </span> |
| 137 | + </div> |
| 138 | + </div> |
| 139 | + </div> |
| 140 | + <AnimatedCircularProgressBar |
| 141 | + value={gaugeValue} |
| 142 | + max={gaugeMax} |
| 143 | + min={0} |
| 144 | + gaugePrimaryColor={gaugePrimaryColor} |
| 145 | + gaugeSecondaryColor='rgba(255, 255, 255, 0.1)' |
| 146 | + className='mx-auto h-24 w-24 text-sm' |
| 147 | + /> |
| 148 | + </div> |
| 149 | + ) |
15 | 150 |
|
16 | 151 | return ( |
17 | | - <TitleAndSubCell |
18 | | - title={ |
19 | | - <DisplayCurrency |
20 | | - coin={BNCoin.fromDenomAndBigNumber(props.depositCap.denom, props.depositCap.max)} |
21 | | - className='text-xs' |
22 | | - /> |
23 | | - } |
24 | | - sub={ |
25 | | - <FormattedNumber |
26 | | - amount={depositCapUsed} |
27 | | - options={{ minDecimals: 2, maxDecimals: 2, suffix: '% Filled' }} |
28 | | - className={classNames( |
29 | | - 'text-xs', |
30 | | - depositCapUsed >= 100 ? 'text-loss/60' : depositCapUsed > 90 ? 'text-info/60' : '', |
31 | | - )} |
32 | | - /> |
33 | | - } |
34 | | - /> |
| 152 | + <Tooltip type='info' content={tooltipContent}> |
| 153 | + <div className='flex items-center justify-end w-full gap-3'> |
| 154 | + {/* Deposits and Cap Info */} |
| 155 | + <div className='flex flex-col gap-0.5'> |
| 156 | + <div className='flex items-center justify-end'> |
| 157 | + <DisplayCurrency coin={depositedCoin} className={valueClassName} /> |
| 158 | + </div> |
| 159 | + <div className='flex items-center justify-end'> |
| 160 | + <DisplayCurrency |
| 161 | + coin={depositCapCoin} |
| 162 | + className={classNames(valueClassName, displayCurrencyColorClass)} |
| 163 | + /> |
| 164 | + </div> |
| 165 | + </div> |
| 166 | + </div> |
| 167 | + </Tooltip> |
35 | 168 | ) |
36 | 169 | } |
0 commit comments