import classnames from 'classnames';
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import Button from '../../../components/ui/button';
import {
DEVICE_NAMES,
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 (
);
}
renderConnectToQRButton() {
return (
);
}
renderButtons() {
return (
<>
{this.renderConnectToLedgerButton()}
{this.renderConnectToTrezorButton()}
{this.renderConnectToLatticeButton()}
{this.renderConnectToQRButton()}
>
);
}
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 DEVICE_NAMES.LEDGER:
return this.renderLedgerTutorialSteps();
case DEVICE_NAMES.TREZOR:
return this.renderTrezorTutorialSteps();
case DEVICE_NAMES.LATTICE:
return this.renderLatticeTutorialSteps();
case DEVICE_NAMES.QR:
return this.renderQRHardwareWalletSteps();
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 && (
)}
))}
);
}
renderQRHardwareWalletSteps() {
const steps = [];
steps.push(
{
title: this.context.t('QRHardwareWalletSteps1Title'),
message: this.context.t('QRHardwareWalletSteps1Description'),
},
{
message: (
<>
{this.context.t('keystone')}
{this.context.t('keystoneTutorial')}
>
),
},
{
message: (
<>
{this.context.t('airgapVault')}
{this.context.t('airgapVaultTutorial')}
>
),
},
{
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()}
);
}
render() {
if (this.props.browserSupported) {
return this.renderConnectScreen();
}
return this.renderUnsupportedBrowser();
}
}