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-10-17 01:03:29 +02:00
|
|
|
import UserPreferencedCurrencyDisplay from '../user-preferenced-currency-display'
|
2018-07-31 07:03:20 +02:00
|
|
|
import { SEND_ROUTE } from '../../routes'
|
2018-10-17 01:03:29 +02:00
|
|
|
import { PRIMARY, SECONDARY } 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-10-17 01:03:29 +02:00
|
|
|
<UserPreferencedCurrencyDisplay
|
2018-08-24 01:44:38 +02:00
|
|
|
className="transaction-view-balance__primary-balance"
|
2018-08-16 04:18:01 +02:00
|
|
|
value={balance}
|
2018-10-17 01:03:29 +02:00
|
|
|
type={PRIMARY}
|
2018-11-09 19:17:42 +01:00
|
|
|
ethNumberOfDecimals={4}
|
2018-08-16 04:18:01 +02:00
|
|
|
/>
|
2018-10-17 01:03:29 +02:00
|
|
|
<UserPreferencedCurrencyDisplay
|
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-10-17 01:03:29 +02:00
|
|
|
type={SECONDARY}
|
2018-11-09 19:17:42 +01:00
|
|
|
ethNumberOfDecimals={4}
|
2018-08-16 04:18:01 +02:00
|
|
|
/>
|
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>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|