import classnames from 'classnames'; import PropTypes from 'prop-types'; import React, { Component } from 'react'; import Button from '../../../components/ui/button'; import { LEDGER_TRANSPORT_TYPES } from '../../../../shared/constants/hardware-wallets'; export default class SelectHardware extends Component { static contextTypes = { t: PropTypes.func, }; static propTypes = { connectToHardwareWallet: PropTypes.func.isRequired, browserSupported: PropTypes.bool.isRequired, ledgerTransportType: PropTypes.oneOf(Object.values(LEDGER_TRANSPORT_TYPES)), }; state = { selectedDevice: null, }; connect = () => { if (this.state.selectedDevice) { this.props.connectToHardwareWallet(this.state.selectedDevice); } return null; }; renderConnectToTrezorButton() { return ( ); } renderConnectToLatticeButton() { return ( ); } renderConnectToLedgerButton() { return ( ); } renderButtons() { return ( <>
{this.renderConnectToLedgerButton()} {this.renderConnectToTrezorButton()}
{this.renderConnectToLatticeButton()}
); } renderContinueButton() { return ( ); } renderUnsupportedBrowser() { return (

{this.context.t('browserNotSupported')}

{this.context.t('chromeRequiredForHardwareWallets')}

); } renderHeader() { return (

{this.context.t('hardwareWallets')}

{this.context.t('hardwareWalletsMsg')}

); } renderTutorialsteps() { switch (this.state.selectedDevice) { case 'ledger': return this.renderLedgerTutorialSteps(); case 'trezor': return this.renderTrezorTutorialSteps(); case 'lattice': return this.renderLatticeTutorialSteps(); default: return ''; } } renderLedgerTutorialSteps() { const steps = []; if (this.props.ledgerTransportType === LEDGER_TRANSPORT_TYPES.LIVE) { steps.push({ title: this.context.t('step1LedgerWallet'), message: this.context.t('step1LedgerWalletMsg', [ {this.context.t('ledgerLiveApp')} , ]), }); } steps.push({ asset: 'plug-in-wallet', dimensions: { width: '225px', height: '75px' }, title: this.context.t('step2LedgerWallet'), message: this.context.t('step2LedgerWalletMsg', [ {this.context.t('hardwareWalletSupportLinkConversion')} , ]), }); return (
{steps.map((step, index) => (

{step.title}

{step.message}

{step.asset && ( )}
))}
); } renderLatticeTutorialSteps() { const steps = [ { asset: 'connect-lattice', dimensions: { width: '225px', height: '75px' }, title: this.context.t('step1LatticeWallet'), message: this.context.t('step1LatticeWalletMsg', [ {this.context.t('hardwareWalletSupportLinkConversion')} , ]), }, ]; return (
{steps.map((step, index) => (

{step.title}

{step.message}

{step.asset && ( )}
))}
); } renderTrezorTutorialSteps() { const steps = [ { asset: 'plug-in-wallet', dimensions: { width: '225px', height: '75px' }, title: this.context.t('step1TrezorWallet'), message: this.context.t('step1TrezorWalletMsg', [ {this.context.t('hardwareWalletSupportLinkConversion')} , ]), }, ]; return (
{steps.map((step, index) => (

{step.title}

{step.message}

{step.asset && ( )}
))}
); } renderConnectScreen() { return (
{this.renderHeader()} {this.renderButtons()} {this.state.selectedDevice ? this.renderTutorialsteps() : null} {this.renderContinueButton()}
); } render() { if (this.props.browserSupported) { return this.renderConnectScreen(); } return this.renderUnsupportedBrowser(); } }