2018-04-26 18:38:38 +02:00
|
|
|
import React, { Component } from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
2019-01-30 13:16:12 +01:00
|
|
|
import classnames from 'classnames'
|
2019-04-17 21:15:13 +02:00
|
|
|
import { checksumAddress } from '../../../helpers/utils/util'
|
|
|
|
import Identicon from '../../../components/ui/identicon'
|
|
|
|
import UserPreferencedCurrencyDisplay from '../../../components/app/user-preferenced-currency-display'
|
|
|
|
import { PRIMARY, SECONDARY } from '../../../helpers/constants/common'
|
|
|
|
import Tooltip from '../../../components/ui/tooltip-v2'
|
2018-04-26 18:38:38 +02:00
|
|
|
|
|
|
|
export default class AccountListItem extends Component {
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
account: PropTypes.object,
|
|
|
|
className: PropTypes.string,
|
|
|
|
displayAddress: PropTypes.bool,
|
|
|
|
displayBalance: PropTypes.bool,
|
|
|
|
handleClick: PropTypes.func,
|
|
|
|
icon: PropTypes.node,
|
2019-01-30 13:16:12 +01:00
|
|
|
balanceIsCached: PropTypes.bool,
|
2019-02-26 19:30:41 +01:00
|
|
|
showFiat: PropTypes.bool,
|
2020-01-07 21:10:44 +01:00
|
|
|
}
|
2018-04-26 18:38:38 +02:00
|
|
|
|
2019-02-26 19:30:41 +01:00
|
|
|
static defaultProps = {
|
|
|
|
showFiat: true,
|
|
|
|
}
|
|
|
|
|
2018-07-02 04:09:28 +02:00
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func,
|
2020-01-07 21:10:44 +01:00
|
|
|
}
|
2018-07-02 04:09:28 +02:00
|
|
|
|
2018-04-26 18:38:38 +02:00
|
|
|
render () {
|
|
|
|
const {
|
|
|
|
account,
|
2018-04-27 02:38:14 +02:00
|
|
|
className,
|
2018-04-26 18:38:38 +02:00
|
|
|
displayAddress = false,
|
2018-04-27 02:38:14 +02:00
|
|
|
displayBalance = true,
|
|
|
|
handleClick,
|
|
|
|
icon = null,
|
2019-01-30 13:16:12 +01:00
|
|
|
balanceIsCached,
|
2019-02-26 19:30:41 +01:00
|
|
|
showFiat,
|
2018-04-26 18:38:38 +02:00
|
|
|
} = this.props
|
|
|
|
|
|
|
|
const { name, address, balance } = account || {}
|
|
|
|
|
2019-12-03 17:35:44 +01:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={`account-list-item ${className}`}
|
|
|
|
onClick={() => handleClick && handleClick({ name, address, balance })}
|
|
|
|
>
|
2018-04-26 18:38:38 +02:00
|
|
|
|
2019-12-03 17:35:44 +01:00
|
|
|
<div className="account-list-item__top-row">
|
|
|
|
<Identicon
|
|
|
|
address={address}
|
|
|
|
className="account-list-item__identicon"
|
|
|
|
diameter={18}
|
|
|
|
/>
|
2018-04-26 18:38:38 +02:00
|
|
|
|
2019-12-03 17:35:44 +01:00
|
|
|
<div className="account-list-item__account-name">{ name || address }</div>
|
2018-04-26 18:38:38 +02:00
|
|
|
|
2019-12-03 17:35:44 +01:00
|
|
|
{icon && <div className="account-list-item__icon">{ icon }</div>}
|
2018-04-26 18:38:38 +02:00
|
|
|
|
2019-12-03 17:35:44 +01:00
|
|
|
</div>
|
2018-04-26 18:38:38 +02:00
|
|
|
|
2019-12-03 17:35:44 +01:00
|
|
|
{displayAddress && name && (
|
|
|
|
<div className="account-list-item__account-address">
|
|
|
|
{ checksumAddress(address) }
|
|
|
|
</div>
|
|
|
|
)}
|
2018-04-26 18:38:38 +02:00
|
|
|
|
2019-12-03 17:35:44 +01:00
|
|
|
{displayBalance && (
|
2019-01-30 13:16:12 +01:00
|
|
|
<Tooltip
|
|
|
|
position="left"
|
|
|
|
title={this.context.t('balanceOutdated')}
|
|
|
|
disabled={!balanceIsCached}
|
|
|
|
style={{
|
|
|
|
left: '-20px !important',
|
|
|
|
}}
|
|
|
|
>
|
2019-12-03 17:35:44 +01:00
|
|
|
<div
|
|
|
|
className={classnames('account-list-item__account-balances', {
|
|
|
|
'account-list-item__cached-balances': balanceIsCached,
|
|
|
|
})}
|
|
|
|
>
|
2019-01-30 13:16:12 +01:00
|
|
|
<div className="account-list-item__primary-cached-container">
|
|
|
|
<UserPreferencedCurrencyDisplay
|
|
|
|
type={PRIMARY}
|
|
|
|
value={balance}
|
2019-11-19 00:23:41 +01:00
|
|
|
hideTitle
|
2019-01-30 13:16:12 +01:00
|
|
|
/>
|
|
|
|
{
|
2019-12-03 17:35:44 +01:00
|
|
|
balanceIsCached
|
|
|
|
? <span className="account-list-item__cached-star">*</span>
|
|
|
|
: null
|
2019-01-30 13:16:12 +01:00
|
|
|
}
|
|
|
|
</div>
|
2019-12-03 17:35:44 +01:00
|
|
|
{showFiat && (
|
|
|
|
<UserPreferencedCurrencyDisplay
|
|
|
|
type={SECONDARY}
|
|
|
|
value={balance}
|
|
|
|
hideTitle
|
|
|
|
/>
|
|
|
|
)}
|
2019-01-30 13:16:12 +01:00
|
|
|
</div>
|
|
|
|
</Tooltip>
|
2019-12-03 17:35:44 +01:00
|
|
|
)}
|
2018-04-26 18:38:38 +02:00
|
|
|
|
2019-12-03 17:35:44 +01:00
|
|
|
</div>
|
|
|
|
)
|
2018-04-26 18:38:38 +02:00
|
|
|
}
|
|
|
|
}
|