import PropTypes from 'prop-types'; import React, { Component } from 'react'; import getAccountLink from '../../../../lib/account-link'; import Button from '../../../components/ui/button'; import Dropdown from '../../../components/ui/dropdown'; class AccountList extends Component { getHdPaths() { const ledgerLiveKey = `m/44'/60'/0'/0/0`; const mewKey = `m/44'/60'/0'`; return [ { name: `Ledger Live`, value: ledgerLiveKey, }, { name: `Legacy (MEW / MyCrypto)`, value: mewKey, }, ]; } goToNextPage = () => { // If we have < 5 accounts, it's restricted by BIP-44 if (this.props.accounts.length === 5) { this.props.getPage(this.props.device, 1, this.props.selectedPath); } else { this.props.onAccountRestriction(); } }; goToPreviousPage = () => { this.props.getPage(this.props.device, -1, this.props.selectedPath); }; renderHdPathSelector() { const { onPathChange, selectedPath } = this.props; const options = this.getHdPaths(); return (

{this.context.t('selectHdPath')}

{this.context.t('selectPathHelp')}

{ onPathChange(value); }} />
); } capitalizeDevice(device) { return device.slice(0, 1).toUpperCase() + device.slice(1); } renderHeader() { const { device } = this.props; return (

{`${this.context.t('unlock')} ${this.capitalizeDevice(device)}`}

{device.toLowerCase() === 'ledger' ? this.renderHdPathSelector() : null}

{this.context.t('selectAnAccount')}

{this.context.t('selectAnAccountHelp')}

); } renderAccounts() { return (
{this.props.accounts.map((account, idx) => (
this.props.onAccountChange(e.target.value)} checked={ this.props.selectedAccount === account.index.toString() } />
))}
); } renderPagination() { return (
); } renderButtons() { const disabled = this.props.selectedAccount === null; const buttonProps = {}; if (disabled) { buttonProps.disabled = true; } return (
); } renderForgetDevice() { return (
{this.context.t('forgetDevice')}
); } render() { return (
{this.renderHeader()} {this.renderAccounts()} {this.renderPagination()} {this.renderButtons()} {this.renderForgetDevice()}
); } } AccountList.propTypes = { onPathChange: PropTypes.func.isRequired, selectedPath: PropTypes.string.isRequired, device: PropTypes.string.isRequired, accounts: PropTypes.array.isRequired, onAccountChange: PropTypes.func.isRequired, onForgetDevice: PropTypes.func.isRequired, getPage: PropTypes.func.isRequired, network: PropTypes.string, selectedAccount: PropTypes.string, onUnlockAccount: PropTypes.func, onCancel: PropTypes.func, onAccountRestriction: PropTypes.func, }; AccountList.contextTypes = { t: PropTypes.func, }; export default AccountList;