2018-07-31 07:03:20 +02:00
|
|
|
import React, { PureComponent } from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import Button from '../button'
|
|
|
|
import Identicon from '../identicon'
|
|
|
|
import TokenBalance from '../token-balance'
|
2018-08-16 04:18:01 +02:00
|
|
|
import CurrencyDisplay from '../currency-display'
|
2018-07-31 07:03:20 +02:00
|
|
|
import { SEND_ROUTE } from '../../routes'
|
2018-08-16 04:18:01 +02:00
|
|
|
import { ETH } from '../../constants/common'
|
2018-07-31 07:03:20 +02:00
|
|
|
|
2018-08-24 01:44:38 +02:00
|
|
|
export default class TransactionViewBalance extends PureComponent {
|
2018-07-31 07:03:20 +02:00
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func,
|
|
|
|
}
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
showDepositModal: PropTypes.func,
|
|
|
|
selectedToken: PropTypes.object,
|
|
|
|
history: PropTypes.object,
|
|
|
|
network: PropTypes.string,
|
2018-08-16 04:18:01 +02:00
|
|
|
balance: PropTypes.string,
|
2018-08-30 04:13:25 +02:00
|
|
|
assetImage: PropTypes.string,
|
2018-07-31 07:03:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
renderBalance () {
|
2018-08-16 04:18:01 +02:00
|
|
|
const { selectedToken, balance } = this.props
|
2018-07-31 07:03:20 +02:00
|
|
|
|
|
|
|
return selectedToken
|
|
|
|
? (
|
|
|
|
<TokenBalance
|
|
|
|
token={selectedToken}
|
|
|
|
withSymbol
|
2018-08-24 01:44:38 +02:00
|
|
|
className="transaction-view-balance__token-balance"
|
2018-07-31 07:03:20 +02:00
|
|
|
/>
|
|
|
|
) : (
|
2018-08-24 01:44:38 +02:00
|
|
|
<div className="transaction-view-balance__balance">
|
2018-08-16 04:18:01 +02:00
|
|
|
<CurrencyDisplay
|
2018-08-24 01:44:38 +02:00
|
|
|
className="transaction-view-balance__primary-balance"
|
2018-08-16 04:18:01 +02:00
|
|
|
value={balance}
|
|
|
|
currency={ETH}
|
|
|
|
numberOfDecimals={3}
|
|
|
|
/>
|
|
|
|
<CurrencyDisplay
|
2018-08-24 01:44:38 +02:00
|
|
|
className="transaction-view-balance__secondary-balance"
|
2018-08-16 04:18:01 +02:00
|
|
|
value={balance}
|
|
|
|
/>
|
2018-07-31 07:03:20 +02:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
renderButtons () {
|
|
|
|
const { t } = this.context
|
|
|
|
const { selectedToken, showDepositModal, history } = this.props
|
|
|
|
|
|
|
|
return (
|
2018-08-24 01:44:38 +02:00
|
|
|
<div className="transaction-view-balance__buttons">
|
2018-07-31 07:03:20 +02:00
|
|
|
{
|
|
|
|
!selectedToken && (
|
|
|
|
<Button
|
|
|
|
type="primary"
|
2018-08-24 01:44:38 +02:00
|
|
|
className="transaction-view-balance__button"
|
2018-07-31 07:03:20 +02:00
|
|
|
onClick={() => showDepositModal()}
|
|
|
|
>
|
|
|
|
{ t('deposit') }
|
|
|
|
</Button>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
<Button
|
|
|
|
type="primary"
|
2018-08-24 01:44:38 +02:00
|
|
|
className="transaction-view-balance__button"
|
2018-07-31 07:03:20 +02:00
|
|
|
onClick={() => history.push(SEND_ROUTE)}
|
|
|
|
>
|
|
|
|
{ t('send') }
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
2018-08-30 04:13:25 +02:00
|
|
|
const { network, selectedToken, assetImage } = this.props
|
2018-07-31 07:03:20 +02:00
|
|
|
|
|
|
|
return (
|
2018-08-24 01:44:38 +02:00
|
|
|
<div className="transaction-view-balance">
|
|
|
|
<div className="transaction-view-balance__balance-container">
|
2018-07-31 07:03:20 +02:00
|
|
|
<Identicon
|
|
|
|
diameter={50}
|
|
|
|
address={selectedToken && selectedToken.address}
|
|
|
|
network={network}
|
2018-08-30 04:13:25 +02:00
|
|
|
image={assetImage}
|
2018-07-31 07:03:20 +02:00
|
|
|
/>
|
|
|
|
{ this.renderBalance() }
|
|
|
|
</div>
|
|
|
|
{ this.renderButtons() }
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|