forked from 1Hive/gardens-ui
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathBalanceToken.js
More file actions
52 lines (46 loc) · 1.27 KB
/
BalanceToken.js
File metadata and controls
52 lines (46 loc) · 1.27 KB
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
46
47
48
49
50
51
52
import React from 'react'
import styled from 'styled-components'
import { GU, tokenIconUrl } from '@tecommons/ui'
import { formatTokenAmount } from '../lib/token-utils'
import { ETHER_TOKEN_VERIFIED_BY_SYMBOL } from '../lib/verified-tokens'
import { getNetwork } from '../networks'
const splitAmount = amount => {
const [integer, fractional] = formatTokenAmount(amount).split('.')
return (
<span
css={`
margin-right: ${0.5 * GU}px;
`}
>
<span>{integer}</span>
{fractional && <span className="fractional">.{fractional}</span>}
</span>
)
}
const BalanceToken = ({ amount, symbol, color, size, icon }) => {
const network = getNetwork()
const tokenAddress =
symbol && ETHER_TOKEN_VERIFIED_BY_SYMBOL.get(symbol.toUpperCase())
return (
<div
css={`
display: flex;
align-items: center;
color: ${color};
${size}
`}
>
<TokenIcon
src={
icon || tokenIconUrl(tokenAddress, symbol, network && network.type)
}
/>
{amount !== undefined ? splitAmount(amount.toFixed(3)) : ' - '}
{symbol || ''}
</div>
)
}
const TokenIcon = styled.img.attrs({ alt: '', width: '20', height: '20' })`
margin-right: ${1 * GU}px;
`
export default BalanceToken