forked from pancakeswap/pancake-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBalance.tsx
45 lines (40 loc) · 933 Bytes
/
Balance.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import React, { useEffect, useRef } from 'react'
import CountUp from 'react-countup'
import { Text, TextProps } from '@pancakeswap/uikit'
interface BalanceProps extends TextProps {
value: number
decimals?: number
unit?: string
isDisabled?: boolean
prefix?: string
onClick?: (event: React.MouseEvent<HTMLElement>) => void
}
const Balance: React.FC<BalanceProps> = ({
value,
color = 'text',
decimals = 3,
isDisabled = false,
unit,
prefix,
onClick,
...props
}) => {
const previousValue = useRef(0)
useEffect(() => {
previousValue.current = value
}, [value])
return (
<Text color={isDisabled ? 'textDisabled' : color} onClick={onClick} {...props}>
<CountUp
start={previousValue.current}
end={value}
prefix={prefix}
suffix={unit}
decimals={decimals}
duration={1}
separator=","
/>
</Text>
)
}
export default Balance