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 {
getHdPaths() {
return [
{
label: `Ledger Live`,
value: `m/44'/60'/0'/0/0`,
},
{
label: `Legacy (MEW / MyCrypto)`,
value: `m/44'/60'/0'`,
},
]
}
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')}
)
}
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) => (
))}
)
}
renderPagination() {
return (
)
}
renderButtons() {
const disabled = this.props.selectedAccount === null
const buttonProps = {}
if (disabled) {
buttonProps.disabled = true
}
return (
)
}
renderForgetDevice() {
return (
)
}
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