import PropTypes from 'prop-types' import React, { Component } from 'react' import Select from 'react-select' import getAccountLink from '../../../../lib/account-link' import Button from '../../../components/ui/button' class AccountList extends Component { state = { showCustomInput: false, customPathSelected: false, } inputRef = React.createRef() getHdPaths() { return [ { label: `Ledger Live`, value: `m/44'/60'/0'/0/0`, }, { label: `Legacy (MEW / MyCrypto)`, value: `m/44'/60'/0'`, }, { label: `Custom`, value: `custom`, }, ] } 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 { showCustomInput } = this.state const { onPathChange, selectedPath } = this.props const options = this.getHdPaths() return (

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

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

{ this.setState({ customPathSelected: false }) }} ref={this.inputRef} autoFocus /> ) } 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 { showCustomInput, customPathSelected } = this.state const { onPathChange } = this.props const showSelectButton = showCustomInput && !customPathSelected const disabled = this.props.selectedAccount === null const buttonProps = {} if (disabled) { buttonProps.disabled = true } return (
{showSelectButton ? ( ) : ( )}
) } renderForgetDevice() { return (
{this.context.t('forgetDevice')}
) } render() { const { showCustomInput, customPathSelected } = this.state return (
{this.renderHeader()} {(!showCustomInput || customPathSelected) && this.renderAccounts()} {(!showCustomInput || customPathSelected) && 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