You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
288 lines
8.0 KiB
288 lines
8.0 KiB
4 years ago
|
import PropTypes from 'prop-types';
|
||
|
import React, { Component } from 'react';
|
||
4 years ago
|
import getAccountLink from '../../../helpers/utils/account-link';
|
||
4 years ago
|
import Button from '../../../components/ui/button';
|
||
4 years ago
|
import Checkbox from '../../../components/ui/check-box';
|
||
4 years ago
|
import Dropdown from '../../../components/ui/dropdown';
|
||
4 years ago
|
import Popover from '../../../components/ui/popover';
|
||
7 years ago
|
|
||
6 years ago
|
class AccountList extends Component {
|
||
4 years ago
|
state = {
|
||
|
showPopover: false,
|
||
|
pathValue: null,
|
||
|
};
|
||
|
|
||
4 years ago
|
goToNextPage = () => {
|
||
|
// If we have < 5 accounts, it's restricted by BIP-44
|
||
|
if (this.props.accounts.length === 5) {
|
||
4 years ago
|
this.props.getPage(this.props.device, 1, this.props.selectedPath);
|
||
4 years ago
|
} else {
|
||
4 years ago
|
this.props.onAccountRestriction();
|
||
6 years ago
|
}
|
||
4 years ago
|
};
|
||
6 years ago
|
|
||
4 years ago
|
goToPreviousPage = () => {
|
||
4 years ago
|
this.props.getPage(this.props.device, -1, this.props.selectedPath);
|
||
|
};
|
||
6 years ago
|
|
||
4 years ago
|
setPath(pathValue) {
|
||
|
this.setState({ pathValue });
|
||
|
}
|
||
|
|
||
4 years ago
|
renderHdPathSelector() {
|
||
4 years ago
|
const { selectedPath, hdPaths } = this.props;
|
||
|
const { pathValue } = this.state;
|
||
4 years ago
|
|
||
4 years ago
|
return (
|
||
|
<div>
|
||
|
<h3 className="hw-connect__hdPath__title">
|
||
|
{this.context.t('selectHdPath')}
|
||
|
</h3>
|
||
|
<p className="hw-connect__msg">{this.context.t('selectPathHelp')}</p>
|
||
|
<div className="hw-connect__hdPath">
|
||
4 years ago
|
<Dropdown
|
||
4 years ago
|
className="hw-connect__hdPath__select"
|
||
4 years ago
|
options={hdPaths}
|
||
4 years ago
|
selectedOption={pathValue || selectedPath}
|
||
4 years ago
|
onChange={(value) => {
|
||
4 years ago
|
this.setPath(value);
|
||
4 years ago
|
}}
|
||
|
/>
|
||
5 years ago
|
</div>
|
||
4 years ago
|
</div>
|
||
4 years ago
|
);
|
||
4 years ago
|
}
|
||
6 years ago
|
|
||
4 years ago
|
capitalizeDevice(device) {
|
||
4 years ago
|
return device.slice(0, 1).toUpperCase() + device.slice(1);
|
||
4 years ago
|
}
|
||
6 years ago
|
|
||
4 years ago
|
renderHeader() {
|
||
|
return (
|
||
|
<div className="hw-connect">
|
||
|
<h3 className="hw-connect__unlock-title">
|
||
4 years ago
|
{this.context.t('selectAnAccount')}
|
||
4 years ago
|
</h3>
|
||
|
<h3 className="hw-connect__hdPath__title">
|
||
|
{this.context.t('selectAnAccount')}
|
||
|
</h3>
|
||
|
<p className="hw-connect__msg">
|
||
|
{this.context.t('selectAnAccountHelp')}
|
||
4 years ago
|
{this.context.t('selectAnAccountHelpDirections', [
|
||
|
<button
|
||
|
className="hw-connect__msg-link"
|
||
|
onClick={() => this.setState({ showPopover: true })}
|
||
|
key="account-help"
|
||
|
>
|
||
|
{this.context.t('hardwareWalletSupportLinkConversion')}
|
||
|
</button>,
|
||
|
])}
|
||
4 years ago
|
</p>
|
||
|
</div>
|
||
4 years ago
|
);
|
||
4 years ago
|
}
|
||
6 years ago
|
|
||
4 years ago
|
renderAccounts() {
|
||
4 years ago
|
const { accounts, connectedAccounts } = this.props;
|
||
|
|
||
4 years ago
|
return (
|
||
|
<div className="hw-account-list">
|
||
4 years ago
|
{accounts.map((account, idx) => {
|
||
|
const accountAlreadyConnected = connectedAccounts.includes(
|
||
|
account.address.toLowerCase(),
|
||
|
);
|
||
|
const value = account.index;
|
||
|
const checked =
|
||
|
this.props.selectedAccounts.includes(account.index) ||
|
||
|
accountAlreadyConnected;
|
||
|
|
||
|
return (
|
||
|
<div
|
||
|
className="hw-account-list__item"
|
||
|
key={account.address}
|
||
|
title={
|
||
|
accountAlreadyConnected
|
||
|
? this.context.t('selectAnAccountAlreadyConnected')
|
||
|
: ''
|
||
|
}
|
||
|
>
|
||
|
<div className="hw-account-list__item__checkbox">
|
||
|
<Checkbox
|
||
|
id={`address-${idx}`}
|
||
|
checked={checked}
|
||
|
disabled={accountAlreadyConnected}
|
||
|
onClick={() => {
|
||
|
this.props.onAccountChange(value);
|
||
|
}}
|
||
|
/>
|
||
|
<label
|
||
|
className="hw-account-list__item__label"
|
||
|
htmlFor={`address-${idx}`}
|
||
|
>
|
||
|
<span className="hw-account-list__item__index">
|
||
|
{account.index + 1}
|
||
|
</span>
|
||
|
{`${account.address.slice(0, 4)}...${account.address.slice(
|
||
|
-4,
|
||
|
)}`}
|
||
|
<span className="hw-account-list__item__balance">{`${account.balance}`}</span>
|
||
|
</label>
|
||
|
</div>
|
||
|
<a
|
||
|
className="hw-account-list__item__link"
|
||
4 years ago
|
href={getAccountLink(
|
||
|
account.address,
|
||
|
this.props.chainId,
|
||
|
this.props.rpcPrefs,
|
||
|
)}
|
||
4 years ago
|
target="_blank"
|
||
|
rel="noopener noreferrer"
|
||
|
title={this.context.t('etherscanView')}
|
||
5 years ago
|
>
|
||
4 years ago
|
<img src="images/popout.svg" alt="" />
|
||
|
</a>
|
||
5 years ago
|
</div>
|
||
4 years ago
|
);
|
||
|
})}
|
||
4 years ago
|
</div>
|
||
4 years ago
|
);
|
||
4 years ago
|
}
|
||
7 years ago
|
|
||
4 years ago
|
renderPagination() {
|
||
|
return (
|
||
|
<div className="hw-list-pagination">
|
||
|
<button
|
||
|
className="hw-list-pagination__button"
|
||
|
onClick={this.goToPreviousPage}
|
||
|
>
|
||
|
{`< ${this.context.t('prev')}`}
|
||
|
</button>
|
||
|
<button
|
||
|
className="hw-list-pagination__button"
|
||
|
onClick={this.goToNextPage}
|
||
|
>
|
||
|
{`${this.context.t('next')} >`}
|
||
|
</button>
|
||
|
</div>
|
||
4 years ago
|
);
|
||
4 years ago
|
}
|
||
6 years ago
|
|
||
4 years ago
|
renderButtons() {
|
||
4 years ago
|
const disabled = this.props.selectedAccounts.length === 0;
|
||
4 years ago
|
const buttonProps = {};
|
||
4 years ago
|
if (disabled) {
|
||
4 years ago
|
buttonProps.disabled = true;
|
||
5 years ago
|
}
|
||
6 years ago
|
|
||
4 years ago
|
return (
|
||
|
<div className="new-external-account-form__buttons">
|
||
|
<Button
|
||
|
type="default"
|
||
|
large
|
||
|
className="new-external-account-form__button"
|
||
|
onClick={this.props.onCancel.bind(this)}
|
||
|
>
|
||
|
{this.context.t('cancel')}
|
||
|
</Button>
|
||
4 years ago
|
<Button
|
||
|
type="primary"
|
||
|
large
|
||
|
className="new-external-account-form__button unlock"
|
||
|
disabled={disabled}
|
||
4 years ago
|
onClick={this.props.onUnlockAccounts.bind(
|
||
|
this,
|
||
|
this.props.device,
|
||
|
this.props.selectedPath,
|
||
|
)}
|
||
4 years ago
|
>
|
||
|
{this.context.t('unlock')}
|
||
|
</Button>
|
||
4 years ago
|
</div>
|
||
4 years ago
|
);
|
||
4 years ago
|
}
|
||
5 years ago
|
|
||
4 years ago
|
renderForgetDevice() {
|
||
|
return (
|
||
|
<div className="hw-forget-device-container">
|
||
|
<a onClick={this.props.onForgetDevice.bind(this, this.props.device)}>
|
||
|
{this.context.t('forgetDevice')}
|
||
|
</a>
|
||
|
</div>
|
||
4 years ago
|
);
|
||
4 years ago
|
}
|
||
7 years ago
|
|
||
4 years ago
|
renderSelectPathPopover() {
|
||
|
const { pathValue } = this.state;
|
||
|
const { onPathChange } = this.props;
|
||
|
|
||
|
const footer = (
|
||
|
<div className="switch-ledger-path-popover__footer">
|
||
|
<Button
|
||
|
onClick={() => this.setState({ showPopover: false })}
|
||
|
type="secondary"
|
||
|
>
|
||
|
{this.context.t('cancel')}
|
||
|
</Button>
|
||
|
<Button
|
||
|
onClick={() => {
|
||
|
onPathChange(pathValue);
|
||
|
this.setState({ showPopover: false });
|
||
|
}}
|
||
|
type="primary"
|
||
|
>
|
||
|
{this.context.t('save')}
|
||
|
</Button>
|
||
|
</div>
|
||
|
);
|
||
|
|
||
|
return (
|
||
|
<Popover
|
||
|
title={this.context.t('switchLedgerPaths')}
|
||
|
subtitle={this.context.t('switchLedgerPathsText')}
|
||
|
contentClassName="switch-ledger-path-popover__content"
|
||
|
footer={footer}
|
||
|
>
|
||
|
{this.renderHdPathSelector()}
|
||
|
</Popover>
|
||
|
);
|
||
|
}
|
||
|
|
||
4 years ago
|
render() {
|
||
4 years ago
|
const { showPopover } = this.state;
|
||
4 years ago
|
return (
|
||
|
<div className="new-external-account-form account-list">
|
||
|
{this.renderHeader()}
|
||
4 years ago
|
{this.renderAccounts()}
|
||
|
{this.renderPagination()}
|
||
4 years ago
|
{this.renderButtons()}
|
||
|
{this.renderForgetDevice()}
|
||
4 years ago
|
{showPopover && this.renderSelectPathPopover()}
|
||
4 years ago
|
</div>
|
||
4 years ago
|
);
|
||
4 years ago
|
}
|
||
7 years ago
|
}
|
||
|
|
||
|
AccountList.propTypes = {
|
||
5 years ago
|
onPathChange: PropTypes.func.isRequired,
|
||
|
selectedPath: PropTypes.string.isRequired,
|
||
|
device: PropTypes.string.isRequired,
|
||
|
accounts: PropTypes.array.isRequired,
|
||
4 years ago
|
connectedAccounts: PropTypes.array.isRequired,
|
||
5 years ago
|
onAccountChange: PropTypes.func.isRequired,
|
||
|
onForgetDevice: PropTypes.func.isRequired,
|
||
|
getPage: PropTypes.func.isRequired,
|
||
4 years ago
|
chainId: PropTypes.string,
|
||
|
rpcPrefs: PropTypes.object,
|
||
4 years ago
|
selectedAccounts: PropTypes.array.isRequired,
|
||
|
onUnlockAccounts: PropTypes.func,
|
||
5 years ago
|
onCancel: PropTypes.func,
|
||
|
onAccountRestriction: PropTypes.func,
|
||
4 years ago
|
hdPaths: PropTypes.array.isRequired,
|
||
4 years ago
|
};
|
||
7 years ago
|
|
||
|
AccountList.contextTypes = {
|
||
5 years ago
|
t: PropTypes.func,
|
||
4 years ago
|
};
|
||
6 years ago
|
|
||
4 years ago
|
export default AccountList;
|