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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'
import Button from '../button'
import Identicon from '../identicon'
import TokenBalance from '../token-balance'
import { SEND_ROUTE } from '../../routes'
import { formatCurrency } from '../../helpers/confirm-transaction/util'
export default class TokenViewBalance extends PureComponent {
static contextTypes = {
t: PropTypes.func,
}
static propTypes = {
showDepositModal: PropTypes.func,
selectedToken: PropTypes.object,
history: PropTypes.object,
network: PropTypes.string,
ethBalance: PropTypes.string,
fiatBalance: PropTypes.string,
currentCurrency: PropTypes.string,
}
renderBalance () {
const { selectedToken, ethBalance, fiatBalance, currentCurrency } = this.props
const formattedFiatBalance = formatCurrency(fiatBalance, currentCurrency)
return selectedToken
? (
<TokenBalance
token={selectedToken}
withSymbol
className="token-view-balance__primary-balance"
/>
) : (
<div className="token-view-balance__balance">
<div className="token-view-balance__primary-balance">
{ `${ethBalance} ETH` }
</div>
<div className="token-view-balance__secondary-balance">
{ formattedFiatBalance }
</div>
</div>
)
}
renderButtons () {
const { t } = this.context
const { selectedToken, showDepositModal, history } = this.props
return (
<div className="token-view-balance__buttons">
{
!selectedToken && (
<Button
type="primary"
className="token-view-balance__button"
onClick={() => showDepositModal()}
>
{ t('deposit') }
</Button>
)
}
<Button
type="primary"
className="token-view-balance__button"
onClick={() => history.push(SEND_ROUTE)}
>
{ t('send') }
</Button>
</div>
)
}
render () {
const { network, selectedToken } = this.props
return (
<div className="token-view-balance">
<div className="token-view-balance__balance-container">
<Identicon
diameter={50}
address={selectedToken && selectedToken.address}
network={network}
/>
{ this.renderBalance() }
</div>
{ this.renderButtons() }
</div>
)
}
}
|