1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00
metamask-extension/ui/pages/create-account/connect-hardware/index.js

480 lines
14 KiB
JavaScript
Raw Normal View History

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import * as actions from '../../../store/actions';
import {
getCurrentChainId,
getMetaMaskAccounts,
getRpcPrefsForCurrentProvider,
getMetaMaskAccountsConnected,
} from '../../../selectors';
import { formatBalance } from '../../../helpers/utils/util';
import { getMostRecentOverviewPage } from '../../../ducks/history/history';
import {
MetaMetricsEventAccountType,
MetaMetricsEventCategory,
MetaMetricsEventName,
} from '../../../../shared/constants/metametrics';
import { SECOND } from '../../../../shared/constants/time';
import {
HardwareDeviceNames,
LedgerTransportTypes,
} from '../../../../shared/constants/hardware-wallets';
import {
BUTTON_VARIANT,
BUTTON_SIZES,
Button,
Text,
} from '../../../components/component-library';
import ZENDESK_URLS from '../../../helpers/constants/zendesk-url';
import { TextColor } from '../../../helpers/constants/design-system';
import SelectHardware from './select-hardware';
import AccountList from './account-list';
2018-07-05 23:45:28 +02:00
const U2F_ERROR = 'U2F';
const LEDGER_LIVE_PATH = `m/44'/60'/0'/0/0`;
const MEW_PATH = `m/44'/60'/0'`;
const BIP44_PATH = `m/44'/60'/0'/0`;
export const LEDGER_HD_PATHS = [
{ name: 'Ledger Live', value: LEDGER_LIVE_PATH },
{ name: 'Legacy (MEW / MyCrypto)', value: MEW_PATH },
{ name: `BIP44 Standard (e.g. MetaMask, Trezor)`, value: BIP44_PATH },
];
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`;
export 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 },
];
const TREZOR_TESTNET_PATH = `m/44'/1'/0'/0`;
export const TREZOR_HD_PATHS = [
{ name: `BIP44 Standard (e.g. MetaMask, Trezor)`, value: BIP44_PATH },
{ name: `Trezor Testnets`, value: TREZOR_TESTNET_PATH },
];
const HD_PATHS = {
ledger: LEDGER_HD_PATHS,
lattice: LATTICE_HD_PATHS,
trezor: TREZOR_HD_PATHS,
};
2018-07-05 23:45:28 +02:00
class ConnectHardwareForm extends Component {
Connect Ledger via WebHID (#12411) * Connect ledger via webhid if that option is available * Explicitly setting preference for webhid * Use ledgerTransportType enum instead of booleans for ledger live and webhid preferences * Use single setLEdgerTransport preference methods and property * Temp * Lint fix * Unit test fix * Remove async keyword from setLedgerTransportPreference function definition in preferences controller * Fix ledgelive setting toggle logic * Migrate useLedgerLive preference property to ledgerTransportType * Use shared constants for ledger transport type enums * Use constant for ledger usb vendor id * Use correct property to check if ledgerLive preference is set when deciding whether to ask for webhid connection * Update eth-ledger-bridge-keyring to v0.9.0 * Only show ledger live transaction helper messages if using ledger live * Only show ledger live part of tutorial if ledger live setting is on * Fix ledger related prop type errors * Explicitly use u2f enum instead of empty string as a transport type; default transport type to webhid if available; use constants for u2f and webhid * Cleanup * Wrap ledger webhid device request in try/catch * Clean up * Lint fix * Ensure user can easily connect their ledger wallet when they need to. * Fix locales * Fix/improve locales changes * Remove unused isFirefox property from confirm-transaction-base.container.js * Disable transaction and message signing confirmation if ledger webhid requires connection * Ensure translation keys for ledger connection options in settings dropdown can be properly detected by verify-locales * Drop .component from ledger-instruction-field file name * Move renderLedgerLiveStep to module scope * Remove ledgerLive from function and message names in ledger-instruction-field * Wrap ledger connection logic in ledger-instruction-field in try catch * Clean up signature-request.component.js * Check whether the signing address, and not the selected address, is a ledger account in singature-request.container * Ensure ledger instructions and webhid connection button are shown on signature-request-original signatures * Improve webhid selection handling in select-ledger-transport-type onChange handler * Move metamask redux focused ledger selectors to metamask duck * Lint fix * Use async await in checkWebHidStatusRef.current * Remove unnecessary use of ref in ledger-instruction-field.js * Lint fix * Remove unnecessary try/catch in ledger-instruction-field.js * Check if from address, not selected address, is from a ledger account in confirm-approve * Move findKeyringForAddress to metamask duck * Fix typo in function name * Ensure isEqualCaseInsensitive handles possible differences in address casing * Fix Learn More link size in advanced settings tab * Update app/scripts/migrations/066.js Co-authored-by: Mark Stacey <markjstacey@gmail.com> * Update ui/pages/settings/advanced-tab/advanced-tab.component.test.js Co-authored-by: Mark Stacey <markjstacey@gmail.com> * Add jsdoc comments for new selectors * Use jest.spyOn for mocking navigator in ledger webhid migration tests * Use LEDGER_TRANSPORT_TYPES values to set proptype of ledgerTransportType * Use LEDGER_TRANSPORT_TYPES values to set proptype of ledgerTransportType * Fix font size of link in ledger connection description in advanced settings * Fix return type in setLedgerTransportPreference comment * Clean up connectHardware code for webhid connection in actions.js * Update app/scripts/migrations/066.test.js Co-authored-by: Mark Stacey <markjstacey@gmail.com> * Update ui/ducks/metamask/metamask.js Co-authored-by: Mark Stacey <markjstacey@gmail.com> * Add migration test for when useLedgerLive is true in a browser that supports webhid * Lint fix * Fix inline-link size Co-authored-by: Mark Stacey <markjstacey@gmail.com>
2021-10-21 21:17:03 +02:00
static contextTypes = {
t: PropTypes.func,
};
state = {
error: null,
selectedAccounts: [],
accounts: [],
browserSupported: true,
unlocked: false,
device: null,
isFirefox: false,
};
2018-07-05 23:45:28 +02:00
2020-11-03 00:41:28 +01:00
UNSAFE_componentWillReceiveProps(nextProps) {
const { accounts } = nextProps;
2020-02-15 21:34:12 +01:00
const newAccounts = this.state.accounts.map((a) => {
const normalizedAddress = a.address.toLowerCase();
const balanceValue = accounts[normalizedAddress]?.balance || null;
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() {
this.checkIfUnlocked();
const useAgent = window.navigator.userAgent;
if (/Firefox/u.test(useAgent)) {
this.setState({ isFirefox: true });
}
}
2020-11-03 00:41:28 +01:00
async checkIfUnlocked() {
for (const device of [
HardwareDeviceNames.trezor,
HardwareDeviceNames.ledger,
HardwareDeviceNames.lattice,
]) {
const path = this.props.defaultHdPaths[device];
const unlocked = await this.props.checkHardwareStatus(device, path);
if (unlocked) {
this.setState({ unlocked: true });
this.getPage(device, 0, path);
}
}
}
connectToHardwareWallet = (device) => {
this.setState({ device });
2018-07-05 23:45:28 +02:00
if (this.state.accounts.length) {
return;
2018-07-05 23:45:28 +02:00
}
2018-08-14 01:29:43 +02:00
// Default values
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,
});
this.setState({
selectedAccounts: [],
});
this.getPage(this.state.device, 0, path);
};
2018-07-05 23:45:28 +02:00
onAccountChange = (account) => {
let { selectedAccounts } = this.state;
if (selectedAccounts.includes(account)) {
selectedAccounts = selectedAccounts.filter((acc) => account !== acc);
} else {
selectedAccounts.push(account);
}
this.setState({ selectedAccounts, error: null });
};
2018-07-05 23:45:28 +02:00
2018-08-14 07:26:18 +02:00
onAccountRestriction = () => {
this.setState({ error: this.context.t('ledgerAccountRestriction') });
};
2018-08-14 07:26:18 +02:00
2020-11-03 00:41:28 +01:00
showTemporaryAlert() {
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((_) => {
this.props.hideAlert();
}, 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
Connect Ledger via WebHID (#12411) * Connect ledger via webhid if that option is available * Explicitly setting preference for webhid * Use ledgerTransportType enum instead of booleans for ledger live and webhid preferences * Use single setLEdgerTransport preference methods and property * Temp * Lint fix * Unit test fix * Remove async keyword from setLedgerTransportPreference function definition in preferences controller * Fix ledgelive setting toggle logic * Migrate useLedgerLive preference property to ledgerTransportType * Use shared constants for ledger transport type enums * Use constant for ledger usb vendor id * Use correct property to check if ledgerLive preference is set when deciding whether to ask for webhid connection * Update eth-ledger-bridge-keyring to v0.9.0 * Only show ledger live transaction helper messages if using ledger live * Only show ledger live part of tutorial if ledger live setting is on * Fix ledger related prop type errors * Explicitly use u2f enum instead of empty string as a transport type; default transport type to webhid if available; use constants for u2f and webhid * Cleanup * Wrap ledger webhid device request in try/catch * Clean up * Lint fix * Ensure user can easily connect their ledger wallet when they need to. * Fix locales * Fix/improve locales changes * Remove unused isFirefox property from confirm-transaction-base.container.js * Disable transaction and message signing confirmation if ledger webhid requires connection * Ensure translation keys for ledger connection options in settings dropdown can be properly detected by verify-locales * Drop .component from ledger-instruction-field file name * Move renderLedgerLiveStep to module scope * Remove ledgerLive from function and message names in ledger-instruction-field * Wrap ledger connection logic in ledger-instruction-field in try catch * Clean up signature-request.component.js * Check whether the signing address, and not the selected address, is a ledger account in singature-request.container * Ensure ledger instructions and webhid connection button are shown on signature-request-original signatures * Improve webhid selection handling in select-ledger-transport-type onChange handler * Move metamask redux focused ledger selectors to metamask duck * Lint fix * Use async await in checkWebHidStatusRef.current * Remove unnecessary use of ref in ledger-instruction-field.js * Lint fix * Remove unnecessary try/catch in ledger-instruction-field.js * Check if from address, not selected address, is from a ledger account in confirm-approve * Move findKeyringForAddress to metamask duck * Fix typo in function name * Ensure isEqualCaseInsensitive handles possible differences in address casing * Fix Learn More link size in advanced settings tab * Update app/scripts/migrations/066.js Co-authored-by: Mark Stacey <markjstacey@gmail.com> * Update ui/pages/settings/advanced-tab/advanced-tab.component.test.js Co-authored-by: Mark Stacey <markjstacey@gmail.com> * Add jsdoc comments for new selectors * Use jest.spyOn for mocking navigator in ledger webhid migration tests * Use LEDGER_TRANSPORT_TYPES values to set proptype of ledgerTransportType * Use LEDGER_TRANSPORT_TYPES values to set proptype of ledgerTransportType * Fix font size of link in ledger connection description in advanced settings * Fix return type in setLedgerTransportPreference comment * Clean up connectHardware code for webhid connection in actions.js * Update app/scripts/migrations/066.test.js Co-authored-by: Mark Stacey <markjstacey@gmail.com> * Update ui/ducks/metamask/metamask.js Co-authored-by: Mark Stacey <markjstacey@gmail.com> * Add migration test for when useLedgerLive is true in a browser that supports webhid * Lint fix * Fix inline-link size Co-authored-by: Mark Stacey <markjstacey@gmail.com>
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
// (device previously locked) show the global alert
if (this.state.accounts.length === 0 && !this.state.unlocked) {
this.showTemporaryAlert();
2018-07-19 08:31:13 +02:00
}
2018-07-09 23:24:52 +02:00
// Map accounts with balances
const newAccounts = accounts.map((account) => {
const normalizedAddress = account.address.toLowerCase();
2020-11-03 00:41:28 +01:00
const balanceValue =
this.props.accounts[normalizedAddress]?.balance || null;
2020-11-03 00:41:28 +01:00
account.balance = balanceValue
? formatBalance(balanceValue, 6)
: '...';
return account;
});
2018-07-09 23:24:52 +02: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) => {
const errorMessage = typeof e === 'string' ? e : e.message;
if (errorMessage === 'Window blocked') {
this.setState({ browserSupported: false, error: null });
} else if (errorMessage.includes(U2F_ERROR)) {
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'),
});
} 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' &&
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-05 23:45:28 +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((_) => {
this.setState({
error: null,
selectedAccounts: [],
accounts: [],
unlocked: false,
});
2020-11-03 00:41:28 +01:00
})
.catch((e) => {
this.setState({ error: e.message });
});
};
onUnlockAccounts = (device, path) => {
2022-07-31 20:26:40 +02:00
const { history, mostRecentOverviewPage, unlockHardwareWalletAccounts } =
this.props;
const { selectedAccounts } = this.state;
2018-07-06 02:59:31 +02:00
if (selectedAccounts.length === 0) {
this.setState({ error: this.context.t('accountSelectionRequired') });
2018-07-05 23:45:28 +02:00
}
2018-07-06 02:59:31 +02: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((_) => {
2022-03-29 15:46:24 +02:00
this.context.trackEvent({
category: MetaMetricsEventCategory.Accounts,
event: MetaMetricsEventName.AccountAdded,
2022-03-29 15:46:24 +02:00
properties: {
account_type: MetaMetricsEventAccountType.Hardware,
account_hardware_type: device,
},
});
history.push(mostRecentOverviewPage);
2020-11-03 00:41:28 +01:00
})
.catch((e) => {
2022-03-29 15:46:24 +02:00
this.context.trackEvent({
category: MetaMetricsEventCategory.Accounts,
event: MetaMetricsEventName.AccountAddFailed,
2022-03-29 15:46:24 +02:00
properties: {
account_type: MetaMetricsEventAccountType.Hardware,
account_hardware_type: device,
error: e.message,
},
});
this.setState({ error: e.message });
});
};
2018-07-05 23:45:28 +02:00
2018-07-06 02:59:31 +02:00
onCancel = () => {
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() {
if (this.state.error === U2F_ERROR) {
if (this.state.device === 'ledger' && this.state.isFirefox) {
return (
<>
<Text color={TextColor.warningDefault} margin={[5, 5, 2]}>
{this.context.t('troubleConnectingToLedgerU2FOnFirefox', [
// eslint-disable-next-line react/jsx-key
<Button
variant={BUTTON_VARIANT.LINK}
href={ZENDESK_URLS.HARDWARE_CONNECTION}
size={BUTTON_SIZES.INHERIT}
key="u2f-error-1"
as="a"
block={false}
target="_blank"
rel="noopener noreferrer"
>
{this.context.t('troubleConnectingToLedgerU2FOnFirefox2')}
</Button>,
])}
</Text>
<Text color={TextColor.warningDefault} margin={[5, 5, 2]}>
{this.context.t(
'troubleConnectingToLedgerU2FOnFirefoxLedgerSolution',
[
// eslint-disable-next-line react/jsx-key
<Button
variant={BUTTON_VARIANT.LINK}
href={ZENDESK_URLS.LEDGER_FIREFOX_U2F_GUIDE}
size={BUTTON_SIZES.INHERIT}
key="u2f-error-1"
as="a"
target="_blank"
rel="noopener noreferrer"
>
{this.context.t(
'troubleConnectingToLedgerU2FOnFirefoxLedgerSolution2',
)}
</Button>,
],
)}
</Text>
</>
);
}
return (
<Text color={TextColor.warningDefault} margin={[5, 5, 2]}>
2020-11-03 00:41:28 +01:00
{this.context.t('troubleConnectingToWallet', [
this.state.device,
// eslint-disable-next-line react/jsx-key
<Button
variant={BUTTON_VARIANT.LINK}
href={ZENDESK_URLS.HARDWARE_CONNECTION}
key="u2f-error-1"
>
{this.context.t('walletConnectionGuide')}
</Button>,
2020-11-03 00:41:28 +01:00
])}
</Text>
);
}
2020-11-03 00:41:28 +01:00
return this.state.error ? (
<span className="hw-connect__error">{this.state.error}</span>
) : 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) {
return (
<SelectHardware
connectToHardwareWallet={this.connectToHardwareWallet}
browserSupported={this.state.browserSupported}
Connect Ledger via WebHID (#12411) * Connect ledger via webhid if that option is available * Explicitly setting preference for webhid * Use ledgerTransportType enum instead of booleans for ledger live and webhid preferences * Use single setLEdgerTransport preference methods and property * Temp * Lint fix * Unit test fix * Remove async keyword from setLedgerTransportPreference function definition in preferences controller * Fix ledgelive setting toggle logic * Migrate useLedgerLive preference property to ledgerTransportType * Use shared constants for ledger transport type enums * Use constant for ledger usb vendor id * Use correct property to check if ledgerLive preference is set when deciding whether to ask for webhid connection * Update eth-ledger-bridge-keyring to v0.9.0 * Only show ledger live transaction helper messages if using ledger live * Only show ledger live part of tutorial if ledger live setting is on * Fix ledger related prop type errors * Explicitly use u2f enum instead of empty string as a transport type; default transport type to webhid if available; use constants for u2f and webhid * Cleanup * Wrap ledger webhid device request in try/catch * Clean up * Lint fix * Ensure user can easily connect their ledger wallet when they need to. * Fix locales * Fix/improve locales changes * Remove unused isFirefox property from confirm-transaction-base.container.js * Disable transaction and message signing confirmation if ledger webhid requires connection * Ensure translation keys for ledger connection options in settings dropdown can be properly detected by verify-locales * Drop .component from ledger-instruction-field file name * Move renderLedgerLiveStep to module scope * Remove ledgerLive from function and message names in ledger-instruction-field * Wrap ledger connection logic in ledger-instruction-field in try catch * Clean up signature-request.component.js * Check whether the signing address, and not the selected address, is a ledger account in singature-request.container * Ensure ledger instructions and webhid connection button are shown on signature-request-original signatures * Improve webhid selection handling in select-ledger-transport-type onChange handler * Move metamask redux focused ledger selectors to metamask duck * Lint fix * Use async await in checkWebHidStatusRef.current * Remove unnecessary use of ref in ledger-instruction-field.js * Lint fix * Remove unnecessary try/catch in ledger-instruction-field.js * Check if from address, not selected address, is from a ledger account in confirm-approve * Move findKeyringForAddress to metamask duck * Fix typo in function name * Ensure isEqualCaseInsensitive handles possible differences in address casing * Fix Learn More link size in advanced settings tab * Update app/scripts/migrations/066.js Co-authored-by: Mark Stacey <markjstacey@gmail.com> * Update ui/pages/settings/advanced-tab/advanced-tab.component.test.js Co-authored-by: Mark Stacey <markjstacey@gmail.com> * Add jsdoc comments for new selectors * Use jest.spyOn for mocking navigator in ledger webhid migration tests * Use LEDGER_TRANSPORT_TYPES values to set proptype of ledgerTransportType * Use LEDGER_TRANSPORT_TYPES values to set proptype of ledgerTransportType * Fix font size of link in ledger connection description in advanced settings * Fix return type in setLedgerTransportPreference comment * Clean up connectHardware code for webhid connection in actions.js * Update app/scripts/migrations/066.test.js Co-authored-by: Mark Stacey <markjstacey@gmail.com> * Update ui/ducks/metamask/metamask.js Co-authored-by: Mark Stacey <markjstacey@gmail.com> * Add migration test for when useLedgerLive is true in a browser that supports webhid * Lint fix * Fix inline-link size Co-authored-by: Mark Stacey <markjstacey@gmail.com>
2021-10-21 21:17:03 +02:00
ledgerTransportType={this.props.ledgerTransportType}
/>
);
2018-07-05 23:45:28 +02:00
}
return (
<AccountList
onPathChange={this.onPathChange}
selectedPath={this.props.defaultHdPaths[this.state.device]}
device={this.state.device}
accounts={this.state.accounts}
connectedAccounts={this.props.connectedAccounts}
selectedAccounts={this.state.selectedAccounts}
onAccountChange={this.onAccountChange}
chainId={this.props.chainId}
rpcPrefs={this.props.rpcPrefs}
getPage={this.getPage}
onUnlockAccounts={this.onUnlockAccounts}
onForgetDevice={this.onForgetDevice}
onCancel={this.onCancel}
onAccountRestriction={this.onAccountRestriction}
hdPaths={HD_PATHS}
/>
);
2018-07-05 23:45:28 +02:00
}
2020-11-03 00:41:28 +01:00
render() {
return (
<>
{this.renderError()}
{this.renderContent()}
</>
);
2018-07-05 23:45:28 +02:00
}
}
ConnectHardwareForm.propTypes = {
connectHardware: PropTypes.func,
checkHardwareStatus: PropTypes.func,
forgetDevice: PropTypes.func,
2018-07-19 08:31:13 +02:00
showAlert: PropTypes.func,
hideAlert: PropTypes.func,
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,
chainId: PropTypes.string,
rpcPrefs: PropTypes.object,
2018-07-05 23:45:28 +02:00
accounts: PropTypes.object,
connectedAccounts: PropTypes.array.isRequired,
2018-08-14 01:29:43 +02:00
defaultHdPaths: PropTypes.object,
mostRecentOverviewPage: PropTypes.string.isRequired,
ledgerTransportType: PropTypes.oneOf(Object.values(LedgerTransportTypes)),
};
2018-07-05 23:45:28 +02:00
const mapStateToProps = (state) => ({
chainId: getCurrentChainId(state),
rpcPrefs: getRpcPrefsForCurrentProvider(state),
accounts: getMetaMaskAccounts(state),
connectedAccounts: getMetaMaskAccountsConnected(state),
defaultHdPaths: state.appState.defaultHdPaths,
mostRecentOverviewPage: getMostRecentOverviewPage(state),
Connect Ledger via WebHID (#12411) * Connect ledger via webhid if that option is available * Explicitly setting preference for webhid * Use ledgerTransportType enum instead of booleans for ledger live and webhid preferences * Use single setLEdgerTransport preference methods and property * Temp * Lint fix * Unit test fix * Remove async keyword from setLedgerTransportPreference function definition in preferences controller * Fix ledgelive setting toggle logic * Migrate useLedgerLive preference property to ledgerTransportType * Use shared constants for ledger transport type enums * Use constant for ledger usb vendor id * Use correct property to check if ledgerLive preference is set when deciding whether to ask for webhid connection * Update eth-ledger-bridge-keyring to v0.9.0 * Only show ledger live transaction helper messages if using ledger live * Only show ledger live part of tutorial if ledger live setting is on * Fix ledger related prop type errors * Explicitly use u2f enum instead of empty string as a transport type; default transport type to webhid if available; use constants for u2f and webhid * Cleanup * Wrap ledger webhid device request in try/catch * Clean up * Lint fix * Ensure user can easily connect their ledger wallet when they need to. * Fix locales * Fix/improve locales changes * Remove unused isFirefox property from confirm-transaction-base.container.js * Disable transaction and message signing confirmation if ledger webhid requires connection * Ensure translation keys for ledger connection options in settings dropdown can be properly detected by verify-locales * Drop .component from ledger-instruction-field file name * Move renderLedgerLiveStep to module scope * Remove ledgerLive from function and message names in ledger-instruction-field * Wrap ledger connection logic in ledger-instruction-field in try catch * Clean up signature-request.component.js * Check whether the signing address, and not the selected address, is a ledger account in singature-request.container * Ensure ledger instructions and webhid connection button are shown on signature-request-original signatures * Improve webhid selection handling in select-ledger-transport-type onChange handler * Move metamask redux focused ledger selectors to metamask duck * Lint fix * Use async await in checkWebHidStatusRef.current * Remove unnecessary use of ref in ledger-instruction-field.js * Lint fix * Remove unnecessary try/catch in ledger-instruction-field.js * Check if from address, not selected address, is from a ledger account in confirm-approve * Move findKeyringForAddress to metamask duck * Fix typo in function name * Ensure isEqualCaseInsensitive handles possible differences in address casing * Fix Learn More link size in advanced settings tab * Update app/scripts/migrations/066.js Co-authored-by: Mark Stacey <markjstacey@gmail.com> * Update ui/pages/settings/advanced-tab/advanced-tab.component.test.js Co-authored-by: Mark Stacey <markjstacey@gmail.com> * Add jsdoc comments for new selectors * Use jest.spyOn for mocking navigator in ledger webhid migration tests * Use LEDGER_TRANSPORT_TYPES values to set proptype of ledgerTransportType * Use LEDGER_TRANSPORT_TYPES values to set proptype of ledgerTransportType * Fix font size of link in ledger connection description in advanced settings * Fix return type in setLedgerTransportPreference comment * Clean up connectHardware code for webhid connection in actions.js * Update app/scripts/migrations/066.test.js Co-authored-by: Mark Stacey <markjstacey@gmail.com> * Update ui/ducks/metamask/metamask.js Co-authored-by: Mark Stacey <markjstacey@gmail.com> * Add migration test for when useLedgerLive is true in a browser that supports webhid * Lint fix * Fix inline-link size Co-authored-by: Mark Stacey <markjstacey@gmail.com>
2021-10-21 21:17:03 +02:00
ledgerTransportType: state.metamask.ledgerTransportType,
});
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 }) => {
return dispatch(actions.setHardwareWalletDefaultHdPath({ device, path }));
2018-08-14 01:29:43 +02:00
},
Connect Ledger via WebHID (#12411) * Connect ledger via webhid if that option is available * Explicitly setting preference for webhid * Use ledgerTransportType enum instead of booleans for ledger live and webhid preferences * Use single setLEdgerTransport preference methods and property * Temp * Lint fix * Unit test fix * Remove async keyword from setLedgerTransportPreference function definition in preferences controller * Fix ledgelive setting toggle logic * Migrate useLedgerLive preference property to ledgerTransportType * Use shared constants for ledger transport type enums * Use constant for ledger usb vendor id * Use correct property to check if ledgerLive preference is set when deciding whether to ask for webhid connection * Update eth-ledger-bridge-keyring to v0.9.0 * Only show ledger live transaction helper messages if using ledger live * Only show ledger live part of tutorial if ledger live setting is on * Fix ledger related prop type errors * Explicitly use u2f enum instead of empty string as a transport type; default transport type to webhid if available; use constants for u2f and webhid * Cleanup * Wrap ledger webhid device request in try/catch * Clean up * Lint fix * Ensure user can easily connect their ledger wallet when they need to. * Fix locales * Fix/improve locales changes * Remove unused isFirefox property from confirm-transaction-base.container.js * Disable transaction and message signing confirmation if ledger webhid requires connection * Ensure translation keys for ledger connection options in settings dropdown can be properly detected by verify-locales * Drop .component from ledger-instruction-field file name * Move renderLedgerLiveStep to module scope * Remove ledgerLive from function and message names in ledger-instruction-field * Wrap ledger connection logic in ledger-instruction-field in try catch * Clean up signature-request.component.js * Check whether the signing address, and not the selected address, is a ledger account in singature-request.container * Ensure ledger instructions and webhid connection button are shown on signature-request-original signatures * Improve webhid selection handling in select-ledger-transport-type onChange handler * Move metamask redux focused ledger selectors to metamask duck * Lint fix * Use async await in checkWebHidStatusRef.current * Remove unnecessary use of ref in ledger-instruction-field.js * Lint fix * Remove unnecessary try/catch in ledger-instruction-field.js * Check if from address, not selected address, is from a ledger account in confirm-approve * Move findKeyringForAddress to metamask duck * Fix typo in function name * Ensure isEqualCaseInsensitive handles possible differences in address casing * Fix Learn More link size in advanced settings tab * Update app/scripts/migrations/066.js Co-authored-by: Mark Stacey <markjstacey@gmail.com> * Update ui/pages/settings/advanced-tab/advanced-tab.component.test.js Co-authored-by: Mark Stacey <markjstacey@gmail.com> * Add jsdoc comments for new selectors * Use jest.spyOn for mocking navigator in ledger webhid migration tests * Use LEDGER_TRANSPORT_TYPES values to set proptype of ledgerTransportType * Use LEDGER_TRANSPORT_TYPES values to set proptype of ledgerTransportType * Fix font size of link in ledger connection description in advanced settings * Fix return type in setLedgerTransportPreference comment * Clean up connectHardware code for webhid connection in actions.js * Update app/scripts/migrations/066.test.js Co-authored-by: Mark Stacey <markjstacey@gmail.com> * Update ui/ducks/metamask/metamask.js Co-authored-by: Mark Stacey <markjstacey@gmail.com> * Add migration test for when useLedgerLive is true in a browser that supports webhid * Lint fix * Fix inline-link size Co-authored-by: Mark Stacey <markjstacey@gmail.com>
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) => {
return dispatch(actions.checkHardwareStatus(deviceName, hdPath));
},
forgetDevice: (deviceName) => {
return dispatch(actions.forgetDevice(deviceName));
},
unlockHardwareWalletAccounts: (
indexes,
deviceName,
hdPath,
hdPathDescription,
) => {
2020-11-03 00:41:28 +01:00
return dispatch(
actions.unlockHardwareWalletAccounts(
indexes,
deviceName,
hdPath,
hdPathDescription,
),
);
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()),
};
};
2018-07-05 23:45:28 +02:00
ConnectHardwareForm.contextTypes = {
t: PropTypes.func,
2022-03-29 15:46:24 +02:00
trackEvent: PropTypes.func,
};
2018-07-05 23:45:28 +02:00
export default connect(
mapStateToProps,
mapDispatchToProps,
)(ConnectHardwareForm);