import classnames from 'classnames'; import PropTypes from 'prop-types'; import React, { Component } from 'react'; import { Text, Box, IconName, ButtonIconSize, ButtonIcon, Button, BUTTON_SIZES, BUTTON_VARIANT, } from '../../../components/component-library'; 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'; import { isManifestV3 } from '../../../../shared/modules/mv3.utils'; import { openWindow } from '../../../helpers/utils/window'; import { AlignItems, Display, FlexDirection, FontWeight, JustifyContent, TextAlign, TextColor, TextVariant, } from '../../../helpers/constants/design-system'; export default class SelectHardware extends Component { static contextTypes = { t: PropTypes.func, trackEvent: PropTypes.func, }; static propTypes = { onCancel: PropTypes.func.isRequired, connectToHardwareWallet: PropTypes.func.isRequired, browserSupported: PropTypes.bool.isRequired, ledgerTransportType: PropTypes.oneOf(Object.values(LedgerTransportTypes)), }; state = { selectedDevice: null, }; shouldShowConnectButton() { return !isManifestV3 || process.env.HARDWARE_WALLETS_MV3; } connect = () => { if (this.state.selectedDevice) { this.props.connectToHardwareWallet(this.state.selectedDevice); } return null; }; renderConnectToTrezorButton() { return ( ); } renderConnectToLatticeButton() { return ( ); } renderConnectToLedgerButton() { return ( ); } renderConnectToQRButton() { return ( ); } renderButtons() { return ( <>
{this.shouldShowConnectButton() && this.renderConnectToLedgerButton()} {this.shouldShowConnectButton() && this.renderConnectToTrezorButton()}
{this.shouldShowConnectButton() && this.renderConnectToLatticeButton()} {this.renderConnectToQRButton()}
); } renderContinueButton() { return ( ); } renderFooter() { return ( {this.context.t('hardwareWalletsInfo')} ); } 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 HardwareDeviceNames.ledger: return this.renderLedgerTutorialSteps(); case HardwareDeviceNames.trezor: return this.renderTrezorTutorialSteps(); case HardwareDeviceNames.lattice: return this.renderLatticeTutorialSteps(); case HardwareDeviceNames.qr: return this.renderQRHardwareWalletSteps(); default: return ''; } } renderLedgerTutorialSteps() { const steps = []; if (this.props.ledgerTransportType === LedgerTransportTypes.live) { steps.push({ renderButtons: false, title: this.context.t('step1LedgerWallet'), message: this.context.t('step1LedgerWalletMsg', [ {this.context.t('ledgerLiveApp')} , ]), }); } steps.push({ renderButtons: true, 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.renderButtons ? ( ) : null}

{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 && ( )}
))}
); } renderQRHardwareWalletSteps() { const steps = []; steps.push( { title: this.context.t('QRHardwareWalletSteps1Title'), message: this.context.t('QRHardwareWalletSteps1Description'), }, { message: ( <>

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

), }, { message: ( <>

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

), }, { message: ( <>

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

), }, { message: ( <>

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

), }, { message: this.context.t('QRHardwareWalletSteps2Description'), }, { asset: 'qrcode-wallet-demo', dimensions: { width: '225px', height: '75px' }, }, ); return (
{steps.map((step, index) => (
{step.title &&

{step.title}

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