import PropTypes from 'prop-types' import React, { Component } from 'react' import Identicon from '../../../components/ui/identicon' import { PRIMARY } from '../../../helpers/constants/common' import UserPreferencedCurrencyDisplay from '../../../components/app/user-preferenced-currency-display' export default class ChooseAccount extends Component { static propTypes = { accounts: PropTypes.arrayOf(PropTypes.shape({ address: PropTypes.string, addressLabel: PropTypes.string, lastConnectedDate: PropTypes.string, balance: PropTypes.string, })).isRequired, originName: PropTypes.string.isRequired, selectAccount: PropTypes.func.isRequired, selectNewAccountViaModal: PropTypes.func.isRequired, nativeCurrency: PropTypes.string.isRequired, addressLastConnectedMap: PropTypes.object, cancelPermissionsRequest: PropTypes.func.isRequired, permissionsRequestId: PropTypes.string.isRequired, } static defaultProps = { addressLastConnectedMap: {}, } static contextTypes = { t: PropTypes.func, }; renderAccountsList = () => { const { accounts, selectAccount, nativeCurrency, addressLastConnectedMap } = this.props return (
{ accounts.map((account, index) => { const { address, addressLabel, balance } = account return (
selectAccount(address) } className="permissions-connect-choose-account__account" >
{ addressLabel }
{ addressLastConnectedMap[address] ? (
{ this.context.t('lastConnected') } { addressLastConnectedMap[address] }
) : null }
) }) }
) } render () { const { originName, selectNewAccountViaModal, permissionsRequestId, cancelPermissionsRequest } = this.props const { t } = this.context return (
{ t('chooseAnAcount') }
{ t('toConnectWith', [originName]) }
{ this.renderAccountsList() }
cancelPermissionsRequest(permissionsRequestId) } className="permissions-connect-choose-account__cancel" > { t('cancel') }
selectNewAccountViaModal() } className="permissions-connect-choose-account__new-account" > { t('newAccount') }
) } }