import './LedgerNano.scss'; import React, { PureComponent } from 'react'; import translate, { translateRaw } from 'translations'; import DeterministicWalletsModal from './DeterministicWalletsModal'; import { LedgerWallet } from 'libs/wallet'; import ledger from 'ledgerco'; import { Spinner } from 'components/ui'; import { connect } from 'react-redux'; import { AppState } from 'reducers'; import { getNetworkConfig } from 'selectors/config'; import { SecureWalletName } from 'config'; import { DPath } from 'config/dpaths'; import { getPaths, getSingleDPath } from 'utils/network'; interface OwnProps { onUnlock(param: any): void; } interface StateProps { dPath: DPath; } interface State { publicKey: string; chainCode: string; dPath: string; error: string | null; isLoading: boolean; showTip: boolean; } type Props = OwnProps & StateProps; class LedgerNanoSDecryptClass extends PureComponent { public state: State = { publicKey: '', chainCode: '', dPath: this.props.dPath.value, error: null, isLoading: false, showTip: false }; public showTip = () => { this.setState({ showTip: true }); }; public render() { const { dPath, publicKey, chainCode, error, isLoading, showTip } = this.state; const showErr = error ? 'is-showing' : ''; if (window.location.protocol !== 'https:') { return (
Unlocking a Ledger hardware wallet is only possible on pages served over HTTPS. You can unlock your wallet at MyEtherWallet.com
); } return (
{showTip && (

Tip: Make sure you're logged into the ethereum app on your hardware wallet

)} {translate('Don’t have a Ledger? Order one now!')}
{error || '-'}
Guides:
How to use MyEtherWallet with your Nano S
How to secure your tokens with your Nano S
); } private handlePathChange = (dPath: string) => { this.handleConnect(dPath); }; private handleConnect = (dPath: string = this.state.dPath) => { this.setState({ isLoading: true, error: null, showTip: false }); ledger.comm_u2f.create_async().then(comm => { new ledger.eth(comm) .getAddress_async(dPath, false, true) .then(res => { this.setState({ publicKey: res.publicKey, chainCode: res.chainCode, isLoading: false }); }) .catch(err => { if (err && err.metaData && err.metaData.code === 5) { this.showTip(); } this.setState({ error: err && err.metaData ? err.metaData.type : err.toString(), isLoading: false }); }); }); }; private handleCancel = () => { this.reset(); }; private handleUnlock = (address: string, index: number) => { this.props.onUnlock(new LedgerWallet(address, this.state.dPath, index)); this.reset(); }; private handleNullConnect = (): void => { return this.handleConnect(); }; private reset() { this.setState({ publicKey: '', chainCode: '', dPath: this.props.dPath.value }); } } function mapStateToProps(state: AppState): StateProps { const network = getNetworkConfig(state); return { dPath: getSingleDPath(SecureWalletName.LEDGER_NANO_S, network) }; } export const LedgerNanoSDecrypt = connect(mapStateToProps)(LedgerNanoSDecryptClass);