2021-02-04 19:15:23 +01:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import * as actions from '../../../store/actions';
|
2021-03-09 21:39:16 +01:00
|
|
|
import {
|
2021-03-10 18:21:52 +01:00
|
|
|
getCurrentChainId,
|
2021-03-09 21:39:16 +01:00
|
|
|
getMetaMaskAccounts,
|
2021-03-10 18:21:52 +01:00
|
|
|
getRpcPrefsForCurrentProvider,
|
2021-03-09 21:39:16 +01:00
|
|
|
getMetaMaskAccountsConnected,
|
|
|
|
} from '../../../selectors';
|
2021-02-04 19:15:23 +01:00
|
|
|
import { formatBalance } from '../../../helpers/utils/util';
|
|
|
|
import { getMostRecentOverviewPage } from '../../../ducks/history/history';
|
2021-06-10 21:27:03 +02:00
|
|
|
import { SECOND } from '../../../../shared/constants/time';
|
2021-11-23 18:28:39 +01:00
|
|
|
import {
|
|
|
|
DEVICE_NAMES,
|
|
|
|
LEDGER_TRANSPORT_TYPES,
|
|
|
|
} from '../../../../shared/constants/hardware-wallets';
|
2021-02-04 19:15:23 +01:00
|
|
|
import SelectHardware from './select-hardware';
|
|
|
|
import AccountList from './account-list';
|
2018-07-05 23:45:28 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const U2F_ERROR = 'U2F';
|
2020-11-13 19:34:03 +01:00
|
|
|
|
2021-03-09 21:39:16 +01:00
|
|
|
const LEDGER_LIVE_PATH = `m/44'/60'/0'/0/0`;
|
|
|
|
const MEW_PATH = `m/44'/60'/0'`;
|
2021-03-10 19:26:48 +01:00
|
|
|
const BIP44_PATH = `m/44'/60'/0'/0`;
|
2021-11-08 15:48:41 +01:00
|
|
|
const LEDGER_HD_PATHS = [
|
2021-03-09 21:39:16 +01:00
|
|
|
{ name: 'Ledger Live', value: LEDGER_LIVE_PATH },
|
|
|
|
{ name: 'Legacy (MEW / MyCrypto)', value: MEW_PATH },
|
2021-03-24 16:15:28 +01:00
|
|
|
{ name: `BIP44 Standard (e.g. MetaMask, Trezor)`, value: BIP44_PATH },
|
2021-03-09 21:39:16 +01:00
|
|
|
];
|
|
|
|
|
2021-11-08 15:48:41 +01:00
|
|
|
const LATTICE_STANDARD_BIP44_PATH = `m/44'/60'/0'/0/x`;
|
|
|
|
const LATTICE_LEDGER_LIVE_PATH = `m/44'/60'/x'/0/0`;
|
|
|
|
const LATTICE_MEW_PATH = `m/44'/60'/0'/x`;
|
|
|
|
const LATTICE_HD_PATHS = [
|
|
|
|
{
|
|
|
|
name: `Standard (${LATTICE_STANDARD_BIP44_PATH})`,
|
|
|
|
value: LATTICE_STANDARD_BIP44_PATH,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: `Ledger Live (${LATTICE_LEDGER_LIVE_PATH})`,
|
|
|
|
value: LATTICE_LEDGER_LIVE_PATH,
|
|
|
|
},
|
|
|
|
{ name: `Ledger Legacy (${LATTICE_MEW_PATH})`, value: LATTICE_MEW_PATH },
|
|
|
|
];
|
|
|
|
|
2021-11-30 15:28:28 +01:00
|
|
|
const TREZOR_TESTNET_PATH = `m/44'/1'/0'/0`;
|
|
|
|
const TREZOR_HD_PATHS = [
|
|
|
|
{ name: `BIP44 Standard (e.g. MetaMask, Trezor)`, value: BIP44_PATH },
|
|
|
|
{ name: `Trezor Testnets`, value: TREZOR_TESTNET_PATH },
|
|
|
|
];
|
|
|
|
|
2021-11-08 15:48:41 +01:00
|
|
|
const HD_PATHS = {
|
|
|
|
ledger: LEDGER_HD_PATHS,
|
|
|
|
lattice: LATTICE_HD_PATHS,
|
2021-11-30 15:28:28 +01:00
|
|
|
trezor: TREZOR_HD_PATHS,
|
2021-11-08 15:48:41 +01:00
|
|
|
};
|
|
|
|
|
2018-07-05 23:45:28 +02:00
|
|
|
class ConnectHardwareForm extends Component {
|
2021-10-21 21:17:03 +02:00
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func,
|
|
|
|
};
|
|
|
|
|
2019-12-19 23:00:22 +01:00
|
|
|
state = {
|
|
|
|
error: null,
|
2021-03-09 21:39:16 +01:00
|
|
|
selectedAccounts: [],
|
2019-12-19 23:00:22 +01:00
|
|
|
accounts: [],
|
|
|
|
browserSupported: true,
|
|
|
|
unlocked: false,
|
|
|
|
device: null,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-07-05 23:45:28 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
UNSAFE_componentWillReceiveProps(nextProps) {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { accounts } = nextProps;
|
2020-02-15 21:34:12 +01:00
|
|
|
const newAccounts = this.state.accounts.map((a) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const normalizedAddress = a.address.toLowerCase();
|
2021-03-09 21:39:16 +01:00
|
|
|
const balanceValue = accounts[normalizedAddress]?.balance || null;
|
2021-02-04 19:15:23 +01:00
|
|
|
a.balance = balanceValue ? formatBalance(balanceValue, 6) : '...';
|
|
|
|
return a;
|
|
|
|
});
|
|
|
|
this.setState({ accounts: newAccounts });
|
2018-07-13 06:09:42 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
componentDidMount() {
|
2021-02-04 19:15:23 +01:00
|
|
|
this.checkIfUnlocked();
|
2018-07-23 07:18:39 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
async checkIfUnlocked() {
|
2021-11-23 18:28:39 +01:00
|
|
|
for (const device of [
|
|
|
|
DEVICE_NAMES.TREZOR,
|
|
|
|
DEVICE_NAMES.LEDGER,
|
|
|
|
DEVICE_NAMES.LATTICE,
|
|
|
|
]) {
|
2021-03-09 21:39:16 +01:00
|
|
|
const path = this.props.defaultHdPaths[device];
|
|
|
|
const unlocked = await this.props.checkHardwareStatus(device, path);
|
2018-08-11 03:54:34 +02:00
|
|
|
if (unlocked) {
|
2021-02-04 19:15:23 +01:00
|
|
|
this.setState({ unlocked: true });
|
2021-03-09 21:39:16 +01:00
|
|
|
this.getPage(device, 0, path);
|
2018-08-11 03:54:34 +02:00
|
|
|
}
|
2020-08-14 16:27:42 +02:00
|
|
|
}
|
2018-07-12 03:21:36 +02:00
|
|
|
}
|
|
|
|
|
2018-08-11 03:54:34 +02:00
|
|
|
connectToHardwareWallet = (device) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
this.setState({ device });
|
2018-07-05 23:45:28 +02:00
|
|
|
if (this.state.accounts.length) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return;
|
2018-07-05 23:45:28 +02:00
|
|
|
}
|
2018-08-14 01:29:43 +02:00
|
|
|
|
|
|
|
// Default values
|
2021-02-04 19:15:23 +01:00
|
|
|
this.getPage(device, 0, this.props.defaultHdPaths[device]);
|
|
|
|
};
|
2018-08-14 01:29:43 +02:00
|
|
|
|
|
|
|
onPathChange = (path) => {
|
2020-11-03 00:41:28 +01:00
|
|
|
this.props.setHardwareWalletDefaultHdPath({
|
|
|
|
device: this.state.device,
|
|
|
|
path,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2021-03-09 21:39:16 +01:00
|
|
|
this.setState({
|
|
|
|
selectedAccounts: [],
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
this.getPage(this.state.device, 0, path);
|
|
|
|
};
|
2018-07-05 23:45:28 +02:00
|
|
|
|
|
|
|
onAccountChange = (account) => {
|
2021-03-09 21:39:16 +01:00
|
|
|
let { selectedAccounts } = this.state;
|
|
|
|
if (selectedAccounts.includes(account)) {
|
|
|
|
selectedAccounts = selectedAccounts.filter((acc) => account !== acc);
|
|
|
|
} else {
|
|
|
|
selectedAccounts.push(account);
|
|
|
|
}
|
|
|
|
this.setState({ selectedAccounts, error: null });
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-07-05 23:45:28 +02:00
|
|
|
|
2018-08-14 07:26:18 +02:00
|
|
|
onAccountRestriction = () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
this.setState({ error: this.context.t('ledgerAccountRestriction') });
|
|
|
|
};
|
2018-08-14 07:26:18 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
showTemporaryAlert() {
|
2021-02-04 19:15:23 +01:00
|
|
|
this.props.showAlert(this.context.t('hardwareWalletConnected'));
|
2018-07-19 08:31:13 +02:00
|
|
|
// Autohide the alert after 5 seconds
|
2020-02-15 21:34:12 +01:00
|
|
|
setTimeout((_) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
this.props.hideAlert();
|
2021-06-10 21:27:03 +02:00
|
|
|
}, SECOND * 5);
|
2018-07-19 08:31:13 +02:00
|
|
|
}
|
|
|
|
|
2018-08-14 07:26:18 +02:00
|
|
|
getPage = (device, page, hdPath) => {
|
2018-07-05 23:45:28 +02:00
|
|
|
this.props
|
2021-10-21 21:17:03 +02:00
|
|
|
.connectHardware(device, page, hdPath, this.context.t)
|
2020-02-15 21:34:12 +01:00
|
|
|
.then((accounts) => {
|
2018-07-05 23:45:28 +02:00
|
|
|
if (accounts.length) {
|
2018-07-19 08:31:13 +02:00
|
|
|
// If we just loaded the accounts for the first time
|
2018-07-23 07:18:39 +02:00
|
|
|
// (device previously locked) show the global alert
|
|
|
|
if (this.state.accounts.length === 0 && !this.state.unlocked) {
|
2021-02-04 19:15:23 +01:00
|
|
|
this.showTemporaryAlert();
|
2018-07-19 08:31:13 +02:00
|
|
|
}
|
|
|
|
|
2018-07-09 23:24:52 +02:00
|
|
|
// Map accounts with balances
|
2021-03-09 21:39:16 +01:00
|
|
|
const newAccounts = accounts.map((account) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const normalizedAddress = account.address.toLowerCase();
|
2020-11-03 00:41:28 +01:00
|
|
|
const balanceValue =
|
2021-03-09 21:39:16 +01:00
|
|
|
this.props.accounts[normalizedAddress]?.balance || null;
|
2020-11-03 00:41:28 +01:00
|
|
|
account.balance = balanceValue
|
|
|
|
? formatBalance(balanceValue, 6)
|
2021-02-04 19:15:23 +01:00
|
|
|
: '...';
|
|
|
|
return account;
|
|
|
|
});
|
2018-07-09 23:24:52 +02:00
|
|
|
|
2021-03-09 21:39:16 +01:00
|
|
|
this.setState({
|
|
|
|
accounts: newAccounts,
|
|
|
|
unlocked: true,
|
|
|
|
device,
|
|
|
|
error: null,
|
|
|
|
});
|
2018-07-05 23:45:28 +02:00
|
|
|
}
|
|
|
|
})
|
2020-02-15 21:34:12 +01:00
|
|
|
.catch((e) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const errorMessage = typeof e === 'string' ? e : e.message;
|
2019-11-23 02:54:59 +01:00
|
|
|
if (errorMessage === 'Window blocked') {
|
2021-02-04 19:15:23 +01:00
|
|
|
this.setState({ browserSupported: false, error: null });
|
2020-11-13 19:34:03 +01:00
|
|
|
} else if (errorMessage.includes(U2F_ERROR)) {
|
2021-02-04 19:15:23 +01:00
|
|
|
this.setState({ error: U2F_ERROR });
|
2021-04-26 20:05:48 +02:00
|
|
|
} else if (
|
|
|
|
errorMessage === 'LEDGER_LOCKED' ||
|
|
|
|
errorMessage === 'LEDGER_WRONG_APP'
|
|
|
|
) {
|
|
|
|
this.setState({
|
|
|
|
error: this.context.t('ledgerLocked'),
|
|
|
|
});
|
|
|
|
} else if (errorMessage.includes('timeout')) {
|
|
|
|
this.setState({
|
|
|
|
error: this.context.t('ledgerTimeout'),
|
|
|
|
});
|
2021-11-23 18:28:39 +01:00
|
|
|
} else if (
|
|
|
|
errorMessage
|
|
|
|
.toLowerCase()
|
|
|
|
.includes(
|
|
|
|
'KeystoneError#pubkey_account.no_expected_account'.toLowerCase(),
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
this.setState({
|
|
|
|
error: this.context.t('QRHardwarePubkeyAccountOutOfRange'),
|
|
|
|
});
|
2020-11-03 00:41:28 +01:00
|
|
|
} else if (
|
|
|
|
errorMessage !== 'Window closed' &&
|
2021-11-23 18:28:39 +01:00
|
|
|
errorMessage !== 'Popup closed' &&
|
|
|
|
errorMessage
|
|
|
|
.toLowerCase()
|
|
|
|
.includes('KeystoneError#sync_cancel'.toLowerCase()) === false
|
2020-11-03 00:41:28 +01:00
|
|
|
) {
|
2021-04-26 20:05:48 +02:00
|
|
|
this.setState({
|
|
|
|
error: errorMessage,
|
|
|
|
});
|
2018-07-13 08:03:54 +02:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
};
|
2018-07-05 23:45:28 +02:00
|
|
|
|
2018-08-11 03:54:34 +02:00
|
|
|
onForgetDevice = (device) => {
|
2020-11-03 00:41:28 +01:00
|
|
|
this.props
|
|
|
|
.forgetDevice(device)
|
2020-02-15 21:34:12 +01:00
|
|
|
.then((_) => {
|
2019-07-31 22:17:11 +02:00
|
|
|
this.setState({
|
|
|
|
error: null,
|
2021-03-09 21:39:16 +01:00
|
|
|
selectedAccounts: [],
|
2019-07-31 22:17:11 +02:00
|
|
|
accounts: [],
|
|
|
|
unlocked: false,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-11-03 00:41:28 +01:00
|
|
|
})
|
|
|
|
.catch((e) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
this.setState({ error: e.message });
|
|
|
|
});
|
|
|
|
};
|
2018-07-12 03:21:36 +02:00
|
|
|
|
2021-03-09 21:39:16 +01:00
|
|
|
onUnlockAccounts = (device, path) => {
|
2020-11-03 00:41:28 +01:00
|
|
|
const {
|
|
|
|
history,
|
|
|
|
mostRecentOverviewPage,
|
2021-03-09 21:39:16 +01:00
|
|
|
unlockHardwareWalletAccounts,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
2021-03-09 21:39:16 +01:00
|
|
|
const { selectedAccounts } = this.state;
|
2018-07-06 02:59:31 +02:00
|
|
|
|
2021-03-09 21:39:16 +01:00
|
|
|
if (selectedAccounts.length === 0) {
|
2021-02-04 19:15:23 +01:00
|
|
|
this.setState({ error: this.context.t('accountSelectionRequired') });
|
2018-07-05 23:45:28 +02:00
|
|
|
}
|
2018-07-06 02:59:31 +02:00
|
|
|
|
2021-03-09 21:39:16 +01:00
|
|
|
const description =
|
|
|
|
MEW_PATH === path
|
|
|
|
? this.context.t('hardwareWalletLegacyDescription')
|
|
|
|
: '';
|
|
|
|
return unlockHardwareWalletAccounts(
|
|
|
|
selectedAccounts,
|
|
|
|
device,
|
|
|
|
path || null,
|
|
|
|
description,
|
|
|
|
)
|
2020-02-15 21:34:12 +01:00
|
|
|
.then((_) => {
|
2019-07-31 22:17:11 +02:00
|
|
|
this.context.metricsEvent({
|
|
|
|
eventOpts: {
|
|
|
|
category: 'Accounts',
|
|
|
|
action: 'Connected Hardware Wallet',
|
2020-08-19 18:27:05 +02:00
|
|
|
name: `Connected Account with: ${device}`,
|
2019-07-31 22:17:11 +02:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
history.push(mostRecentOverviewPage);
|
2020-11-03 00:41:28 +01:00
|
|
|
})
|
|
|
|
.catch((e) => {
|
2019-07-31 22:17:11 +02:00
|
|
|
this.context.metricsEvent({
|
|
|
|
eventOpts: {
|
|
|
|
category: 'Accounts',
|
|
|
|
action: 'Connected Hardware Wallet',
|
|
|
|
name: 'Error connecting hardware wallet',
|
|
|
|
},
|
|
|
|
customVariables: {
|
2019-11-23 02:54:59 +01:00
|
|
|
error: e.message,
|
2019-07-31 22:17:11 +02:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
this.setState({ error: e.message });
|
|
|
|
});
|
|
|
|
};
|
2018-07-05 23:45:28 +02:00
|
|
|
|
2018-07-06 02:59:31 +02:00
|
|
|
onCancel = () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { history, mostRecentOverviewPage } = this.props;
|
|
|
|
history.push(mostRecentOverviewPage);
|
|
|
|
};
|
2018-07-05 23:45:28 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderError() {
|
2020-11-13 19:34:03 +01:00
|
|
|
if (this.state.error === U2F_ERROR) {
|
2020-09-02 18:28:14 +02:00
|
|
|
return (
|
2020-11-03 00:41:28 +01:00
|
|
|
<p className="hw-connect__error">
|
|
|
|
{this.context.t('troubleConnectingToWallet', [
|
|
|
|
this.state.device,
|
2020-09-02 18:28:14 +02:00
|
|
|
// eslint-disable-next-line react/jsx-key
|
|
|
|
<a
|
|
|
|
href="https://metamask.zendesk.com/hc/en-us/articles/360020394612-How-to-connect-a-Trezor-or-Ledger-Hardware-Wallet"
|
2020-11-19 16:35:20 +01:00
|
|
|
key="hardware-connection-guide"
|
2020-09-02 18:28:14 +02:00
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
className="hw-connect__link"
|
|
|
|
style={{ marginLeft: '5px', marginRight: '5px' }}
|
|
|
|
>
|
|
|
|
{this.context.t('walletConnectionGuide')}
|
2020-11-03 00:41:28 +01:00
|
|
|
</a>,
|
|
|
|
])}
|
2020-09-02 18:28:14 +02:00
|
|
|
</p>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-09-02 18:28:14 +02:00
|
|
|
}
|
2020-11-03 00:41:28 +01:00
|
|
|
return this.state.error ? (
|
|
|
|
<span className="hw-connect__error">{this.state.error}</span>
|
2021-02-04 19:15:23 +01:00
|
|
|
) : null;
|
2018-07-05 23:45:28 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderContent() {
|
2018-07-05 23:45:28 +02:00
|
|
|
if (!this.state.accounts.length) {
|
2019-11-23 19:14:09 +01:00
|
|
|
return (
|
2020-05-28 20:47:48 +02:00
|
|
|
<SelectHardware
|
2019-11-23 19:14:09 +01:00
|
|
|
connectToHardwareWallet={this.connectToHardwareWallet}
|
|
|
|
browserSupported={this.state.browserSupported}
|
2021-10-21 21:17:03 +02:00
|
|
|
ledgerTransportType={this.props.ledgerTransportType}
|
2019-11-23 19:14:09 +01:00
|
|
|
/>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-07-05 23:45:28 +02:00
|
|
|
}
|
|
|
|
|
2019-11-23 19:14:09 +01:00
|
|
|
return (
|
|
|
|
<AccountList
|
|
|
|
onPathChange={this.onPathChange}
|
|
|
|
selectedPath={this.props.defaultHdPaths[this.state.device]}
|
|
|
|
device={this.state.device}
|
|
|
|
accounts={this.state.accounts}
|
2021-03-09 21:39:16 +01:00
|
|
|
connectedAccounts={this.props.connectedAccounts}
|
|
|
|
selectedAccounts={this.state.selectedAccounts}
|
2019-11-23 19:14:09 +01:00
|
|
|
onAccountChange={this.onAccountChange}
|
2021-03-10 18:21:52 +01:00
|
|
|
chainId={this.props.chainId}
|
|
|
|
rpcPrefs={this.props.rpcPrefs}
|
2019-11-23 19:14:09 +01:00
|
|
|
getPage={this.getPage}
|
2021-03-09 21:39:16 +01:00
|
|
|
onUnlockAccounts={this.onUnlockAccounts}
|
2019-11-23 19:14:09 +01:00
|
|
|
onForgetDevice={this.onForgetDevice}
|
|
|
|
onCancel={this.onCancel}
|
|
|
|
onAccountRestriction={this.onAccountRestriction}
|
2021-03-09 21:39:16 +01:00
|
|
|
hdPaths={HD_PATHS}
|
2019-11-23 19:14:09 +01:00
|
|
|
/>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-07-05 23:45:28 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
render() {
|
2019-11-23 19:14:09 +01:00
|
|
|
return (
|
2020-05-28 20:47:48 +02:00
|
|
|
<>
|
2019-11-23 19:14:09 +01:00
|
|
|
{this.renderError()}
|
|
|
|
{this.renderContent()}
|
2020-05-28 20:47:48 +02:00
|
|
|
</>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-07-05 23:45:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ConnectHardwareForm.propTypes = {
|
|
|
|
connectHardware: PropTypes.func,
|
2018-07-12 03:21:36 +02:00
|
|
|
checkHardwareStatus: PropTypes.func,
|
|
|
|
forgetDevice: PropTypes.func,
|
2018-07-19 08:31:13 +02:00
|
|
|
showAlert: PropTypes.func,
|
|
|
|
hideAlert: PropTypes.func,
|
2021-03-09 21:39:16 +01:00
|
|
|
unlockHardwareWalletAccounts: PropTypes.func,
|
2018-08-14 01:29:43 +02:00
|
|
|
setHardwareWalletDefaultHdPath: PropTypes.func,
|
2018-07-05 23:45:28 +02:00
|
|
|
history: PropTypes.object,
|
2021-03-10 18:21:52 +01:00
|
|
|
chainId: PropTypes.string,
|
|
|
|
rpcPrefs: PropTypes.object,
|
2018-07-05 23:45:28 +02:00
|
|
|
accounts: PropTypes.object,
|
2021-03-09 21:39:16 +01:00
|
|
|
connectedAccounts: PropTypes.array.isRequired,
|
2018-08-14 01:29:43 +02:00
|
|
|
defaultHdPaths: PropTypes.object,
|
2020-06-01 19:54:32 +02:00
|
|
|
mostRecentOverviewPage: PropTypes.string.isRequired,
|
2021-10-21 21:17:03 +02:00
|
|
|
ledgerTransportType: PropTypes.oneOf(Object.values(LEDGER_TRANSPORT_TYPES)),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-07-05 23:45:28 +02:00
|
|
|
|
2021-03-10 18:21:52 +01:00
|
|
|
const mapStateToProps = (state) => ({
|
|
|
|
chainId: getCurrentChainId(state),
|
|
|
|
rpcPrefs: getRpcPrefsForCurrentProvider(state),
|
|
|
|
accounts: getMetaMaskAccounts(state),
|
|
|
|
connectedAccounts: getMetaMaskAccountsConnected(state),
|
|
|
|
defaultHdPaths: state.appState.defaultHdPaths,
|
|
|
|
mostRecentOverviewPage: getMostRecentOverviewPage(state),
|
2021-10-21 21:17:03 +02:00
|
|
|
ledgerTransportType: state.metamask.ledgerTransportType,
|
2021-03-10 18:21:52 +01:00
|
|
|
});
|
2018-07-05 23:45:28 +02:00
|
|
|
|
2020-02-15 21:34:12 +01:00
|
|
|
const mapDispatchToProps = (dispatch) => {
|
2018-07-05 23:45:28 +02:00
|
|
|
return {
|
2019-12-03 21:50:55 +01:00
|
|
|
setHardwareWalletDefaultHdPath: ({ device, path }) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
return dispatch(actions.setHardwareWalletDefaultHdPath({ device, path }));
|
2018-08-14 01:29:43 +02:00
|
|
|
},
|
2021-10-21 21:17:03 +02:00
|
|
|
connectHardware: (deviceName, page, hdPath, t) => {
|
|
|
|
return dispatch(actions.connectHardware(deviceName, page, hdPath, t));
|
2018-07-05 23:45:28 +02:00
|
|
|
},
|
2018-08-14 01:29:43 +02:00
|
|
|
checkHardwareStatus: (deviceName, hdPath) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
return dispatch(actions.checkHardwareStatus(deviceName, hdPath));
|
2018-07-12 03:21:36 +02:00
|
|
|
},
|
|
|
|
forgetDevice: (deviceName) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
return dispatch(actions.forgetDevice(deviceName));
|
2018-07-12 03:21:36 +02:00
|
|
|
},
|
2021-03-09 21:39:16 +01:00
|
|
|
unlockHardwareWalletAccounts: (
|
|
|
|
indexes,
|
|
|
|
deviceName,
|
|
|
|
hdPath,
|
|
|
|
hdPathDescription,
|
|
|
|
) => {
|
2020-11-03 00:41:28 +01:00
|
|
|
return dispatch(
|
2021-03-09 21:39:16 +01:00
|
|
|
actions.unlockHardwareWalletAccounts(
|
|
|
|
indexes,
|
|
|
|
deviceName,
|
|
|
|
hdPath,
|
|
|
|
hdPathDescription,
|
|
|
|
),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-07-05 23:45:28 +02:00
|
|
|
},
|
2018-07-19 08:31:13 +02:00
|
|
|
showAlert: (msg) => dispatch(actions.showAlert(msg)),
|
|
|
|
hideAlert: () => dispatch(actions.hideAlert()),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
};
|
2018-07-05 23:45:28 +02:00
|
|
|
|
|
|
|
ConnectHardwareForm.contextTypes = {
|
|
|
|
t: PropTypes.func,
|
2019-03-05 16:45:01 +01:00
|
|
|
metricsEvent: PropTypes.func,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-07-05 23:45:28 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
export default connect(
|
|
|
|
mapStateToProps,
|
|
|
|
mapDispatchToProps,
|
|
|
|
)(ConnectHardwareForm);
|