2019-11-23 17:23:09 +01:00
|
|
|
import classnames from 'classnames'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import React, { Component } from 'react'
|
2019-03-22 00:03:30 +01:00
|
|
|
import Button from '../../../components/ui/button'
|
2018-07-05 23:45:28 +02:00
|
|
|
|
2020-05-28 20:47:48 +02:00
|
|
|
export default class SelectHardware extends Component {
|
2019-11-23 17:23:09 +01:00
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func,
|
2019-07-31 22:17:11 +02:00
|
|
|
}
|
2018-08-17 01:39:52 +02:00
|
|
|
|
2019-11-23 17:23:09 +01:00
|
|
|
static propTypes = {
|
|
|
|
connectToHardwareWallet: PropTypes.func.isRequired,
|
|
|
|
browserSupported: PropTypes.bool.isRequired,
|
|
|
|
}
|
2018-08-17 01:39:52 +02:00
|
|
|
|
2019-11-23 17:23:09 +01:00
|
|
|
state = {
|
|
|
|
selectedDevice: null,
|
|
|
|
}
|
2018-08-17 01:39:52 +02:00
|
|
|
|
2019-11-23 17:23:09 +01:00
|
|
|
connect = () => {
|
|
|
|
if (this.state.selectedDevice) {
|
|
|
|
this.props.connectToHardwareWallet(this.state.selectedDevice)
|
2018-08-17 01:39:52 +02:00
|
|
|
}
|
2019-11-23 17:23:09 +01:00
|
|
|
return null
|
|
|
|
}
|
2018-08-17 01:39:52 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderConnectToTrezorButton() {
|
2019-11-23 17:23:09 +01:00
|
|
|
return (
|
|
|
|
<button
|
|
|
|
className={classnames('hw-connect__btn', {
|
2020-11-03 00:41:28 +01:00
|
|
|
selected: this.state.selectedDevice === 'trezor',
|
2019-11-23 17:23:09 +01:00
|
|
|
})}
|
2020-02-15 21:34:12 +01:00
|
|
|
onClick={(_) => this.setState({ selectedDevice: 'trezor' })}
|
2019-11-23 17:23:09 +01:00
|
|
|
>
|
|
|
|
<img
|
|
|
|
className="hw-connect__btn__img"
|
|
|
|
src="images/trezor-logo.svg"
|
|
|
|
alt=""
|
|
|
|
/>
|
|
|
|
</button>
|
|
|
|
)
|
|
|
|
}
|
2018-07-05 23:45:28 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderConnectToLedgerButton() {
|
2019-11-23 17:23:09 +01:00
|
|
|
return (
|
|
|
|
<button
|
|
|
|
className={classnames('hw-connect__btn', {
|
2020-11-03 00:41:28 +01:00
|
|
|
selected: this.state.selectedDevice === 'ledger',
|
2019-11-23 17:23:09 +01:00
|
|
|
})}
|
2020-02-15 21:34:12 +01:00
|
|
|
onClick={(_) => this.setState({ selectedDevice: 'ledger' })}
|
2019-11-23 17:23:09 +01:00
|
|
|
>
|
|
|
|
<img
|
|
|
|
className="hw-connect__btn__img"
|
|
|
|
src="images/ledger-logo.svg"
|
|
|
|
alt=""
|
|
|
|
/>
|
|
|
|
</button>
|
|
|
|
)
|
|
|
|
}
|
2018-07-05 23:45:28 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderButtons() {
|
2019-11-23 17:23:09 +01:00
|
|
|
return (
|
2020-05-28 20:47:48 +02:00
|
|
|
<>
|
2019-11-23 17:23:09 +01:00
|
|
|
<div className="hw-connect__btn-wrapper">
|
|
|
|
{this.renderConnectToLedgerButton()}
|
|
|
|
{this.renderConnectToTrezorButton()}
|
|
|
|
</div>
|
|
|
|
<Button
|
|
|
|
type="primary"
|
|
|
|
large
|
|
|
|
className="hw-connect__connect-btn"
|
|
|
|
onClick={this.connect}
|
|
|
|
disabled={!this.state.selectedDevice}
|
|
|
|
>
|
|
|
|
{this.context.t('connect')}
|
|
|
|
</Button>
|
2020-05-28 20:47:48 +02:00
|
|
|
</>
|
2019-11-23 17:23:09 +01:00
|
|
|
)
|
|
|
|
}
|
2018-07-19 04:57:47 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderUnsupportedBrowser() {
|
2019-11-23 17:23:09 +01:00
|
|
|
return (
|
2020-05-28 20:47:48 +02:00
|
|
|
<div className="new-external-account-form unsupported-browser">
|
2019-11-23 17:23:09 +01:00
|
|
|
<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>
|
2019-11-23 17:23:09 +01:00
|
|
|
</div>
|
|
|
|
<Button
|
|
|
|
type="primary"
|
|
|
|
large
|
2020-11-03 00:41:28 +01:00
|
|
|
onClick={() =>
|
|
|
|
global.platform.openTab({
|
|
|
|
url: 'https://google.com/chrome',
|
|
|
|
})
|
|
|
|
}
|
2019-11-23 17:23:09 +01:00
|
|
|
>
|
|
|
|
{this.context.t('downloadGoogleChrome')}
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
2018-07-19 04:57:47 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderHeader() {
|
2019-11-23 17:23:09 +01:00
|
|
|
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>
|
2019-11-23 17:23:09 +01:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
2018-08-17 01:39:52 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
getAffiliateLinks() {
|
2019-11-23 17:23:09 +01:00
|
|
|
const links = {
|
|
|
|
trezor: `<a class='hw-connect__get-hw__link' href='https://shop.trezor.io/?a=metamask' target='_blank'>Trezor</a>`,
|
|
|
|
ledger: `<a class='hw-connect__get-hw__link' href='https://www.ledger.com/products/ledger-nano-s?r=17c4991a03fa&tracker=MY_TRACKER' target='_blank'>Ledger</a>`,
|
2018-07-19 04:57:47 +02:00
|
|
|
}
|
|
|
|
|
2019-11-23 17:23:09 +01:00
|
|
|
const text = this.context.t('orderOneHere')
|
2020-11-03 00:41:28 +01:00
|
|
|
const response = text
|
|
|
|
.replace('Trezor', links.trezor)
|
|
|
|
.replace('Ledger', links.ledger)
|
2018-08-11 03:54:34 +02:00
|
|
|
|
2019-11-23 17:23:09 +01:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className="hw-connect__get-hw__msg"
|
2019-12-03 21:50:55 +01:00
|
|
|
dangerouslySetInnerHTML={{ __html: response }}
|
2019-11-23 17:23:09 +01:00
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
2018-08-17 01:39:52 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderTrezorAffiliateLink() {
|
2019-11-23 17:23:09 +01:00
|
|
|
return (
|
|
|
|
<div className="hw-connect__get-hw">
|
2020-11-03 00:41:28 +01:00
|
|
|
<p className="hw-connect__get-hw__msg">
|
|
|
|
{this.context.t('dontHaveAHardwareWallet')}
|
|
|
|
</p>
|
2019-11-23 17:23:09 +01:00
|
|
|
{this.getAffiliateLinks()}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
2018-07-19 05:12:49 +02:00
|
|
|
|
2019-11-23 17:23:09 +01:00
|
|
|
scrollToTutorial = () => {
|
|
|
|
if (this.referenceNode) {
|
2019-12-03 21:50:55 +01:00
|
|
|
this.referenceNode.scrollIntoView({ behavior: 'smooth' })
|
2018-07-19 04:57:47 +02:00
|
|
|
}
|
2019-11-23 17:23:09 +01:00
|
|
|
}
|
2018-07-19 04:57:47 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderLearnMore() {
|
2019-11-23 17:23:09 +01:00
|
|
|
return (
|
|
|
|
<p className="hw-connect__learn-more" onClick={this.scrollToTutorial}>
|
|
|
|
{this.context.t('learnMore')}
|
2020-11-03 00:41:28 +01:00
|
|
|
<img
|
|
|
|
className="hw-connect__learn-more__arrow"
|
|
|
|
src="images/caret-right.svg"
|
|
|
|
alt=""
|
|
|
|
/>
|
2019-11-23 17:23:09 +01:00
|
|
|
</p>
|
|
|
|
)
|
|
|
|
}
|
2018-07-19 04:57:47 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderTutorialSteps() {
|
2019-11-23 17:23:09 +01:00
|
|
|
const steps = [
|
|
|
|
{
|
|
|
|
asset: 'hardware-wallet-step-1',
|
2019-12-03 21:50:55 +01:00
|
|
|
dimensions: { width: '225px', height: '75px' },
|
2019-11-23 17:23:09 +01:00
|
|
|
title: this.context.t('step1HardwareWallet'),
|
|
|
|
message: this.context.t('step1HardwareWalletMsg'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
asset: 'hardware-wallet-step-2',
|
2019-12-03 21:50:55 +01:00
|
|
|
dimensions: { width: '300px', height: '100px' },
|
2019-11-23 17:23:09 +01:00
|
|
|
title: this.context.t('step2HardwareWallet'),
|
|
|
|
message: this.context.t('step2HardwareWalletMsg'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
asset: 'hardware-wallet-step-3',
|
2019-12-03 21:50:55 +01:00
|
|
|
dimensions: { width: '120px', height: '90px' },
|
2019-11-23 17:23:09 +01:00
|
|
|
title: this.context.t('step3HardwareWallet'),
|
|
|
|
message: this.context.t('step3HardwareWalletMsg'),
|
|
|
|
},
|
|
|
|
]
|
2018-07-05 23:45:28 +02:00
|
|
|
|
2019-11-23 17:23:09 +01:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className="hw-tutorial"
|
2020-02-15 21:34:12 +01:00
|
|
|
ref={(node) => {
|
2019-11-23 17:23:09 +01:00
|
|
|
this.referenceNode = node
|
2019-12-03 17:35:44 +01:00
|
|
|
}}
|
|
|
|
>
|
2019-11-23 17:23:09 +01:00
|
|
|
{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>
|
2020-11-03 00:41:28 +01:00
|
|
|
<img
|
|
|
|
className="hw-connect__step-asset"
|
|
|
|
src={`images/${step.asset}.svg`}
|
|
|
|
{...step.dimensions}
|
|
|
|
alt=""
|
|
|
|
/>
|
2019-11-23 17:23:09 +01:00
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
2018-07-05 23:45:28 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderFooter() {
|
2019-11-23 17:23:09 +01:00
|
|
|
return (
|
|
|
|
<div className="hw-connect__footer">
|
2020-11-03 00:41:28 +01:00
|
|
|
<h3 className="hw-connect__footer__title">
|
|
|
|
{this.context.t('readyToConnect')}
|
|
|
|
</h3>
|
2019-11-23 17:23:09 +01:00
|
|
|
{this.renderButtons()}
|
|
|
|
<p className="hw-connect__footer__msg">
|
|
|
|
{this.context.t('havingTroubleConnecting')}
|
2020-11-03 00:41:28 +01:00
|
|
|
<a
|
|
|
|
className="hw-connect__footer__link"
|
|
|
|
href="https://support.metamask.io/"
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
>
|
2019-11-23 17:23:09 +01:00
|
|
|
{this.context.t('getHelp')}
|
|
|
|
</a>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
2018-07-05 23:45:28 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderConnectScreen() {
|
2019-11-23 17:23:09 +01:00
|
|
|
return (
|
2020-05-28 20:47:48 +02:00
|
|
|
<div className="new-external-account-form">
|
2019-11-23 17:23:09 +01:00
|
|
|
{this.renderHeader()}
|
|
|
|
{this.renderButtons()}
|
|
|
|
{this.renderTrezorAffiliateLink()}
|
|
|
|
{this.renderLearnMore()}
|
|
|
|
{this.renderTutorialSteps()}
|
|
|
|
{this.renderFooter()}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
render() {
|
2019-11-23 17:23:09 +01:00
|
|
|
if (this.props.browserSupported) {
|
|
|
|
return this.renderConnectScreen()
|
|
|
|
}
|
|
|
|
return this.renderUnsupportedBrowser()
|
|
|
|
}
|
2018-07-05 23:45:28 +02:00
|
|
|
}
|