1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-01 21:57:06 +01:00
metamask-extension/ui/pages/create-account/connect-hardware/select-hardware.js

606 lines
18 KiB
JavaScript
Raw Normal View History

import classnames from 'classnames';
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import Button from '../../../components/ui/button';
import LogoLedger from '../../../components/ui/logo/logo-ledger';
import LogoQRBased from '../../../components/ui/logo/logo-qr-based';
import LogoTrezor from '../../../components/ui/logo/logo-trezor';
import LogoLattice from '../../../components/ui/logo/logo-lattice';
import {
HardwareDeviceNames,
LedgerTransportTypes,
HardwareAffiliateLinks,
HardwareAffiliateTutorialLinks,
} from '../../../../shared/constants/hardware-wallets';
import ZENDESK_URLS from '../../../helpers/constants/zendesk-url';
import { MetaMetricsEventCategory } from '../../../../shared/constants/metametrics';
Put hardware wallets behind an HARDWARE_WALLETS_MV3 flag (#17354) * Put hardware wallets behind an HARDWARE_WALLETS_MV3 flag Disable Hardware connect buttons if the flag is set. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> update to metamask/eth-keyring-controller Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> revert to eth-keyring-controller v8 Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> LAvamost after rebase Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> lock file. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> Added toaster for removed NFTs (#17297) * added notification for remove nfts * reverted names for tabs * updated default key * updated snapshot * updated remove nft toast to danger Setup network controller mocks per-test (#17250) The network controller unit test network mocks are now setup for each test. This makes modifying network behavior on a per-test basis easier, and makes it more clear which test relies upon which mocks. Security provider check (OpenSea) (#16584) chore: copy update for metamask fee on swaps (#17133) * linter fix Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * setLedgerTransportPreference in the metamask-controller should not be called, or should return immediately, if canUseHardwareWallets() is false Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> Co-authored-by: Jyoti Puri <jyotipuri@gmail.com>
2023-01-25 22:12:08 +01:00
import { isManifestV3 } from '../../../../shared/modules/mv3.utils';
import { openWindow } from '../../../helpers/utils/window';
2018-07-05 23:45:28 +02:00
export default class SelectHardware extends Component {
static contextTypes = {
t: PropTypes.func,
trackEvent: PropTypes.func,
};
2018-08-17 01:39:52 +02:00
static propTypes = {
connectToHardwareWallet: PropTypes.func.isRequired,
browserSupported: PropTypes.bool.isRequired,
ledgerTransportType: PropTypes.oneOf(Object.values(LedgerTransportTypes)),
};
2018-08-17 01:39:52 +02:00
state = {
selectedDevice: null,
};
2018-08-17 01:39:52 +02:00
Put hardware wallets behind an HARDWARE_WALLETS_MV3 flag (#17354) * Put hardware wallets behind an HARDWARE_WALLETS_MV3 flag Disable Hardware connect buttons if the flag is set. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> update to metamask/eth-keyring-controller Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> revert to eth-keyring-controller v8 Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> LAvamost after rebase Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> lock file. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> Added toaster for removed NFTs (#17297) * added notification for remove nfts * reverted names for tabs * updated default key * updated snapshot * updated remove nft toast to danger Setup network controller mocks per-test (#17250) The network controller unit test network mocks are now setup for each test. This makes modifying network behavior on a per-test basis easier, and makes it more clear which test relies upon which mocks. Security provider check (OpenSea) (#16584) chore: copy update for metamask fee on swaps (#17133) * linter fix Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * setLedgerTransportPreference in the metamask-controller should not be called, or should return immediately, if canUseHardwareWallets() is false Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> Co-authored-by: Jyoti Puri <jyotipuri@gmail.com>
2023-01-25 22:12:08 +01:00
shouldShowConnectButton() {
return !isManifestV3 || process.env.CONF?.HARDWARE_WALLETS_MV3;
}
connect = () => {
if (this.state.selectedDevice) {
this.props.connectToHardwareWallet(this.state.selectedDevice);
2018-08-17 01:39:52 +02:00
}
return null;
};
2018-08-17 01:39:52 +02:00
2020-11-03 00:41:28 +01:00
renderConnectToTrezorButton() {
return (
<button
className={classnames('hw-connect__btn', {
selected: this.state.selectedDevice === HardwareDeviceNames.trezor,
})}
onClick={(_) =>
this.setState({ selectedDevice: HardwareDeviceNames.trezor })
}
>
<LogoTrezor className="hw-connect__btn__img" ariaLabel="Trezor" />
</button>
);
}
2018-07-05 23:45:28 +02:00
renderConnectToLatticeButton() {
return (
<button
className={classnames('hw-connect__btn', {
selected: this.state.selectedDevice === HardwareDeviceNames.lattice,
})}
onClick={(_) =>
this.setState({ selectedDevice: HardwareDeviceNames.lattice })
}
>
<LogoLattice className="hw-connect__btn__img" ariaLabel="Lattice" />
</button>
);
}
2020-11-03 00:41:28 +01:00
renderConnectToLedgerButton() {
return (
<button
className={classnames('hw-connect__btn', {
selected: this.state.selectedDevice === HardwareDeviceNames.ledger,
})}
onClick={(_) =>
this.setState({ selectedDevice: HardwareDeviceNames.ledger })
}
>
<LogoLedger className="hw-connect__btn__img" ariaLabel="Ledger" />
</button>
);
}
2018-07-05 23:45:28 +02:00
renderConnectToQRButton() {
return (
<button
className={classnames('hw-connect__btn', {
selected: this.state.selectedDevice === HardwareDeviceNames.qr,
})}
onClick={(_) =>
this.setState({ selectedDevice: HardwareDeviceNames.qr })
}
>
<LogoQRBased className="hw-connect__btn__img" ariaLabel="QRCode" />
</button>
);
}
2020-11-03 00:41:28 +01:00
renderButtons() {
return (
<>
<div className="hw-connect__btn-wrapper">
Put hardware wallets behind an HARDWARE_WALLETS_MV3 flag (#17354) * Put hardware wallets behind an HARDWARE_WALLETS_MV3 flag Disable Hardware connect buttons if the flag is set. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> update to metamask/eth-keyring-controller Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> revert to eth-keyring-controller v8 Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> LAvamost after rebase Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> lock file. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> Added toaster for removed NFTs (#17297) * added notification for remove nfts * reverted names for tabs * updated default key * updated snapshot * updated remove nft toast to danger Setup network controller mocks per-test (#17250) The network controller unit test network mocks are now setup for each test. This makes modifying network behavior on a per-test basis easier, and makes it more clear which test relies upon which mocks. Security provider check (OpenSea) (#16584) chore: copy update for metamask fee on swaps (#17133) * linter fix Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * setLedgerTransportPreference in the metamask-controller should not be called, or should return immediately, if canUseHardwareWallets() is false Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> Co-authored-by: Jyoti Puri <jyotipuri@gmail.com>
2023-01-25 22:12:08 +01:00
{this.shouldShowConnectButton() && this.renderConnectToLedgerButton()}
{this.shouldShowConnectButton() && this.renderConnectToTrezorButton()}
</div>
<div
className="hw-connect__btn-wrapper"
style={{ margin: '10px 0 0 0' }}
>
Put hardware wallets behind an HARDWARE_WALLETS_MV3 flag (#17354) * Put hardware wallets behind an HARDWARE_WALLETS_MV3 flag Disable Hardware connect buttons if the flag is set. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> update to metamask/eth-keyring-controller Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> revert to eth-keyring-controller v8 Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> LAvamost after rebase Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> lock file. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> Added toaster for removed NFTs (#17297) * added notification for remove nfts * reverted names for tabs * updated default key * updated snapshot * updated remove nft toast to danger Setup network controller mocks per-test (#17250) The network controller unit test network mocks are now setup for each test. This makes modifying network behavior on a per-test basis easier, and makes it more clear which test relies upon which mocks. Security provider check (OpenSea) (#16584) chore: copy update for metamask fee on swaps (#17133) * linter fix Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * setLedgerTransportPreference in the metamask-controller should not be called, or should return immediately, if canUseHardwareWallets() is false Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> Co-authored-by: Jyoti Puri <jyotipuri@gmail.com>
2023-01-25 22:12:08 +01:00
{this.shouldShowConnectButton() &&
this.renderConnectToLatticeButton()}
{this.renderConnectToQRButton()}
</div>
</>
);
}
2018-07-19 04:57:47 +02:00
2021-04-26 20:05:48 +02:00
renderContinueButton() {
return (
<Button
type="primary"
large
className="hw-connect__connect-btn"
onClick={this.connect}
disabled={!this.state.selectedDevice}
>
{this.context.t('continue')}
</Button>
);
}
2020-11-03 00:41:28 +01:00
renderUnsupportedBrowser() {
return (
<div className="new-external-account-form unsupported-browser">
<div className="hw-connect">
2020-11-03 00:41:28 +01:00
<h3 className="hw-connect__title">
{this.context.t('browserNotSupported')}
</h3>
<p className="hw-connect__msg">
{this.context.t('chromeRequiredForHardwareWallets')}
</p>
</div>
<Button
type="primary"
large
2020-11-03 00:41:28 +01:00
onClick={() =>
global.platform.openTab({
url: 'https://google.com/chrome',
})
}
>
{this.context.t('downloadGoogleChrome')}
</Button>
</div>
);
}
2018-07-19 04:57:47 +02:00
2020-11-03 00:41:28 +01:00
renderHeader() {
return (
<div className="hw-connect__header">
2020-11-03 00:41:28 +01:00
<h3 className="hw-connect__header__title">
{this.context.t('hardwareWallets')}
</h3>
<p className="hw-connect__header__msg">
{this.context.t('hardwareWalletsMsg')}
</p>
</div>
);
}
2018-08-17 01:39:52 +02:00
2021-04-26 20:05:48 +02:00
renderTutorialsteps() {
switch (this.state.selectedDevice) {
case HardwareDeviceNames.ledger:
2021-04-26 20:05:48 +02:00
return this.renderLedgerTutorialSteps();
case HardwareDeviceNames.trezor:
2021-04-26 20:05:48 +02:00
return this.renderTrezorTutorialSteps();
case HardwareDeviceNames.lattice:
return this.renderLatticeTutorialSteps();
case HardwareDeviceNames.qr:
return this.renderQRHardwareWalletSteps();
2021-04-26 20:05:48 +02:00
default:
return '';
}
}
2018-07-19 05:12:49 +02:00
2021-04-26 20:05:48 +02:00
renderLedgerTutorialSteps() {
const steps = [];
if (this.props.ledgerTransportType === LedgerTransportTypes.live) {
2021-04-26 20:05:48 +02:00
steps.push({
renderButtons: false,
2021-04-26 20:05:48 +02:00
title: this.context.t('step1LedgerWallet'),
message: this.context.t('step1LedgerWalletMsg', [
<a
className="hw-connect__msg-link"
href="https://www.ledger.com/ledger-live"
rel="noopener noreferrer"
target="_blank"
key="ledger-live-app-link"
>
{this.context.t('ledgerLiveApp')}
</a>,
]),
});
2018-07-19 04:57:47 +02:00
}
2021-04-26 20:05:48 +02:00
steps.push({
renderButtons: true,
2021-04-26 20:05:48 +02:00
asset: 'plug-in-wallet',
dimensions: { width: '225px', height: '75px' },
title: this.context.t('step2LedgerWallet'),
message: this.context.t('step2LedgerWalletMsg', [
<a
className="hw-connect__msg-link"
href={ZENDESK_URLS.HARDWARE_CONNECTION}
2021-04-26 20:05:48 +02:00
rel="noopener noreferrer"
target="_blank"
key="ledger-support-link"
>
{this.context.t('hardwareWalletSupportLinkConversion')}
</a>,
]),
});
return (
<div className="hw-tutorial">
{steps.map((step, index) => (
<div className="hw-connect" key={index}>
<h3 className="hw-connect__title">{step.title}</h3>
{step.renderButtons ? (
<>
<Button
className="hw-connect__external-btn-first"
type="secondary"
onClick={() => {
this.context.trackEvent({
category: MetaMetricsEventCategory.Navigation,
event: 'Clicked Ledger Buy Now',
});
openWindow(HardwareAffiliateLinks.ledger);
}}
>
{this.context.t('buyNow')}
</Button>
<Button
className="hw-connect__external-btn"
type="secondary"
onClick={() => {
this.context.trackEvent({
category: MetaMetricsEventCategory.Navigation,
event: 'Clicked Ledger Tutorial',
});
openWindow(HardwareAffiliateTutorialLinks.ledger);
}}
>
{this.context.t('tutorial')}
</Button>
</>
) : null}
<p className="hw-connect__msg">{step.message}</p>
{step.asset && (
<img
className="hw-connect__step-asset"
src={`images/${step.asset}.svg`}
{...step.dimensions}
alt=""
/>
)}
</div>
))}
</div>
);
}
renderLatticeTutorialSteps() {
const steps = [
{
asset: 'connect-lattice',
dimensions: { width: '225px', height: '75px' },
title: this.context.t('step1LatticeWallet'),
message: this.context.t('step1LatticeWalletMsg', [
<a
className="hw-connect__msg-link"
href={ZENDESK_URLS.HARDWARE_CONNECTION}
rel="noopener noreferrer"
target="_blank"
key="lattice-setup-link"
>
{this.context.t('hardwareWalletSupportLinkConversion')}
</a>,
]),
},
];
return (
2021-04-26 20:05:48 +02:00
<div className="hw-tutorial">
{steps.map((step, index) => (
<div className="hw-connect" key={index}>
<h3 className="hw-connect__title">{step.title}</h3>
<Button
className="hw-connect__external-btn-first"
type="secondary"
onClick={() => {
this.context.trackEvent({
category: MetaMetricsEventCategory.Navigation,
event: 'Clicked GridPlus Buy Now',
});
openWindow(HardwareAffiliateLinks.gridplus);
}}
>
{this.context.t('buyNow')}
</Button>
<Button
className="hw-connect__external-btn"
type="secondary"
onClick={() => {
this.context.trackEvent({
category: MetaMetricsEventCategory.Navigation,
event: 'Clicked GidPlus Tutorial',
});
openWindow(HardwareAffiliateTutorialLinks.gridplus);
}}
>
{this.context.t('tutorial')}
</Button>
2021-04-26 20:05:48 +02:00
<p className="hw-connect__msg">{step.message}</p>
{step.asset && (
<img
className="hw-connect__step-asset"
src={`images/${step.asset}.svg`}
{...step.dimensions}
alt=""
/>
)}
</div>
))}
</div>
);
}
2018-07-19 04:57:47 +02:00
2021-04-26 20:05:48 +02:00
renderTrezorTutorialSteps() {
const steps = [
{
2021-04-26 20:05:48 +02:00
asset: 'plug-in-wallet',
2019-12-03 21:50:55 +01:00
dimensions: { width: '225px', height: '75px' },
2021-04-26 20:05:48 +02:00
title: this.context.t('step1TrezorWallet'),
message: this.context.t('step1TrezorWalletMsg', [
<a
className="hw-connect__msg-link"
href={ZENDESK_URLS.HARDWARE_CONNECTION}
2021-04-26 20:05:48 +02:00
rel="noopener noreferrer"
target="_blank"
key="trezor-support-link"
>
{this.context.t('hardwareWalletSupportLinkConversion')}
</a>,
]),
},
];
2018-07-05 23:45:28 +02:00
return (
2021-04-26 20:05:48 +02:00
<div className="hw-tutorial">
{steps.map((step, index) => (
<div className="hw-connect" key={index}>
<h3 className="hw-connect__title">{step.title}</h3>
<Button
className="hw-connect__external-btn-first"
type="secondary"
onClick={() => {
this.context.trackEvent({
category: MetaMetricsEventCategory.Navigation,
event: 'Clicked Trezor Buy Now',
});
openWindow(HardwareAffiliateLinks.trezor);
}}
>
{this.context.t('buyNow')}
</Button>
<Button
className="hw-connect__external-btn"
type="secondary"
onClick={() => {
this.context.trackEvent({
category: MetaMetricsEventCategory.Navigation,
event: 'Clicked Trezor Tutorial',
});
openWindow(HardwareAffiliateTutorialLinks.trezor);
}}
>
{this.context.t('tutorial')}
</Button>
<p className="hw-connect__msg">{step.message}</p>
2021-04-26 20:05:48 +02:00
{step.asset && (
<img
className="hw-connect__step-asset"
src={`images/${step.asset}.svg`}
{...step.dimensions}
alt=""
/>
)}
</div>
))}
</div>
);
}
2018-07-05 23:45:28 +02:00
renderQRHardwareWalletSteps() {
const steps = [];
steps.push(
{
title: this.context.t('QRHardwareWalletSteps1Title'),
message: this.context.t('QRHardwareWalletSteps1Description'),
},
{
message: (
<>
<p className="hw-connect__QR-subtitle">
{this.context.t('keystone')}
</p>
<Button
className="hw-connect__external-btn-first"
type="secondary"
onClick={() => {
this.context.trackEvent({
category: MetaMetricsEventCategory.Navigation,
event: 'Clicked Keystone Buy Now',
});
openWindow(HardwareAffiliateLinks.keystone);
}}
>
{this.context.t('buyNow')}
</Button>
<Button
className="hw-connect__external-btn"
type="secondary"
onClick={() => {
this.context.trackEvent({
category: MetaMetricsEventCategory.Navigation,
event: 'Clicked Keystone Tutorial',
});
openWindow(HardwareAffiliateTutorialLinks.keystone);
}}
>
{this.context.t('tutorial')}
</Button>
</>
),
},
2022-02-22 20:00:51 +01:00
{
message: (
<>
<p className="hw-connect__QR-subtitle">
2022-02-22 20:00:51 +01:00
{this.context.t('airgapVault')}
</p>
<Button
className="hw-connect__external-btn-first"
type="secondary"
onClick={() => {
this.context.trackEvent({
category: MetaMetricsEventCategory.Navigation,
event: 'Clicked AirGap Vault Buy Now',
});
openWindow(HardwareAffiliateLinks.airgap);
}}
>
{this.context.t('downloadNow')}
</Button>
<Button
className="hw-connect__external-btn"
type="secondary"
onClick={() => {
this.context.trackEvent({
category: MetaMetricsEventCategory.Navigation,
event: 'Clicked AirGap Vault Tutorial',
});
openWindow(HardwareAffiliateTutorialLinks.airgap);
}}
>
{this.context.t('tutorial')}
</Button>
</>
),
},
{
message: (
<>
<p className="hw-connect__QR-subtitle">
{this.context.t('coolWallet')}
</p>
<Button
className="hw-connect__external-btn-first"
type="secondary"
onClick={() => {
this.context.trackEvent({
category: MetaMetricsEventCategory.Navigation,
event: 'Clicked CoolWallet Buy Now',
});
openWindow(HardwareAffiliateLinks.coolwallet);
}}
>
{this.context.t('buyNow')}
</Button>
<Button
className="hw-connect__external-btn"
type="secondary"
onClick={() => {
this.context.trackEvent({
category: MetaMetricsEventCategory.Navigation,
event: 'Clicked CoolWallet Tutorial',
});
openWindow(HardwareAffiliateTutorialLinks.coolwallet);
}}
>
{this.context.t('tutorial')}
</Button>
</>
),
},
{
message: (
<>
<p className="hw-connect__QR-subtitle">{this.context.t('dcent')}</p>
<Button
className="hw-connect__external-btn-first"
type="secondary"
onClick={() => {
this.context.trackEvent({
category: MetaMetricsEventCategory.Navigation,
event: 'Clicked DCent Buy Now',
});
openWindow(HardwareAffiliateLinks.dcent);
}}
>
{this.context.t('buyNow')}
</Button>
<Button
className="hw-connect__external-btn"
type="secondary"
onClick={() => {
this.context.trackEvent({
category: MetaMetricsEventCategory.Navigation,
event: 'Clicked DCent Tutorial',
});
openWindow(HardwareAffiliateTutorialLinks.dcent);
}}
2022-02-22 20:00:51 +01:00
>
{this.context.t('tutorial')}
</Button>
2022-02-22 20:00:51 +01:00
</>
),
},
{
message: this.context.t('QRHardwareWalletSteps2Description'),
},
{
asset: 'qrcode-wallet-demo',
dimensions: { width: '225px', height: '75px' },
},
);
return (
<div className="hw-tutorial">
{steps.map((step, index) => (
<div className="hw-connect" key={index}>
{step.title && <h3 className="hw-connect__title">{step.title}</h3>}
<div className="hw-connect__msg">{step.message}</div>
{step.asset && (
<img
className="hw-connect__step-asset"
src={`images/${step.asset}.svg`}
{...step.dimensions}
alt=""
/>
)}
</div>
))}
</div>
);
}
2020-11-03 00:41:28 +01:00
renderConnectScreen() {
return (
<div className="new-external-account-form">
{this.renderHeader()}
{this.renderButtons()}
{this.state.selectedDevice ? this.renderTutorialsteps() : null}
2021-04-26 20:05:48 +02:00
{this.renderContinueButton()}
</div>
);
}
2020-11-03 00:41:28 +01:00
render() {
if (this.props.browserSupported) {
return this.renderConnectScreen();
}
return this.renderUnsupportedBrowser();
}
2018-07-05 23:45:28 +02:00
}