1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-25 11:28:51 +01:00
metamask-extension/ui/pages/create-account/connect-hardware/select-hardware.js

251 lines
6.5 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';
2018-07-05 23:45:28 +02:00
export default class SelectHardware extends Component {
static contextTypes = {
t: PropTypes.func,
};
2018-08-17 01:39:52 +02:00
static propTypes = {
connectToHardwareWallet: PropTypes.func.isRequired,
browserSupported: PropTypes.bool.isRequired,
2021-04-26 20:05:48 +02:00
useLedgerLive: PropTypes.bool.isRequired,
};
2018-08-17 01:39:52 +02:00
state = {
selectedDevice: null,
};
2018-08-17 01:39:52 +02:00
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', {
2020-11-03 00:41:28 +01:00
selected: this.state.selectedDevice === 'trezor',
})}
2020-02-15 21:34:12 +01:00
onClick={(_) => this.setState({ selectedDevice: 'trezor' })}
>
<img
className="hw-connect__btn__img"
src="images/trezor-logo.svg"
alt="Trezor"
/>
</button>
);
}
2018-07-05 23:45:28 +02:00
2020-11-03 00:41:28 +01:00
renderConnectToLedgerButton() {
return (
<button
className={classnames('hw-connect__btn', {
2020-11-03 00:41:28 +01:00
selected: this.state.selectedDevice === 'ledger',
})}
2020-02-15 21:34:12 +01:00
onClick={(_) => this.setState({ selectedDevice: 'ledger' })}
>
<img
className="hw-connect__btn__img"
src="images/ledger-logo.svg"
alt="Ledger"
/>
</button>
);
}
2018-07-05 23:45:28 +02:00
2020-11-03 00:41:28 +01:00
renderButtons() {
return (
<>
<div className="hw-connect__btn-wrapper">
{this.renderConnectToLedgerButton()}
{this.renderConnectToTrezorButton()}
</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 'ledger':
return this.renderLedgerTutorialSteps();
case 'trezor':
return this.renderTrezorTutorialSteps();
default:
return '';
}
}
2018-07-19 05:12:49 +02:00
2021-04-26 20:05:48 +02:00
renderLedgerTutorialSteps() {
const steps = [];
if (this.props.useLedgerLive) {
steps.push({
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({
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="https://metamask.zendesk.com/hc/en-us/articles/360020394612-How-to-connect-a-Trezor-or-Ledger-Hardware-Wallet"
rel="noopener noreferrer"
target="_blank"
key="ledger-support-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>
<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="https://metamask.zendesk.com/hc/en-us/articles/360020394612-How-to-connect-a-Trezor-or-Ledger-Hardware-Wallet"
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>
<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
2020-11-03 00:41:28 +01:00
renderConnectScreen() {
return (
<div className="new-external-account-form">
{this.renderHeader()}
{this.renderButtons()}
2021-04-26 20:05:48 +02:00
{this.state.selectedDevice && this.renderTutorialsteps()}
{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
}