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

34 lines
822 B
TypeScript
Raw Normal View History

2023-01-23 17:26:14 -08:00
import Decimal from 'decimal.js'
2023-08-18 09:23:25 -07:00
import useLocalStorageState from 'hooks/useLocalStorageState'
2023-11-02 17:27:20 -07:00
import { PRIVACY_MODE, PRIVATE_MODE_STRING } from 'utils/constants'
2023-01-24 16:14:51 -08:00
import { formatCurrencyValue, formatNumericValue } from 'utils/numbers'
2023-01-23 17:26:14 -08:00
const FormatNumericValue = ({
2023-06-26 19:43:15 -07:00
classNames,
2023-01-23 17:26:14 -08:00
value,
decimals,
isUsd,
2023-11-02 17:27:20 -07:00
isPrivate,
2023-01-23 17:26:14 -08:00
roundUp,
}: {
2023-06-26 19:43:15 -07:00
classNames?: string
2023-01-23 17:26:14 -08:00
value: Decimal | number | string
decimals?: number
isUsd?: boolean
2023-11-02 17:27:20 -07:00
isPrivate?: boolean
2023-01-23 17:26:14 -08:00
roundUp?: boolean
}) => {
2023-08-18 09:23:25 -07:00
const [privacyMode] = useLocalStorageState(PRIVACY_MODE)
2023-01-24 16:14:51 -08:00
return (
2023-06-26 19:43:15 -07:00
<span className={classNames}>
2023-11-02 17:27:20 -07:00
{privacyMode && isPrivate
? PRIVATE_MODE_STRING
: isUsd
? formatCurrencyValue(value, decimals)
2023-01-24 16:14:51 -08:00
: formatNumericValue(value, decimals, roundUp)}
</span>
)
2023-01-23 17:26:14 -08:00
}
export default FormatNumericValue