import DPATHS from 'config/dpaths'; import { TrezorWallet } from 'libs/wallet'; import React, { Component } from 'react'; import translate, { translateRaw } from 'translations'; import TrezorConnect from 'vendor/trezor-connect'; import DeterministicWalletsModal from './DeterministicWalletsModal'; import './Trezor.scss'; const DEFAULT_PATH = DPATHS.TREZOR[0].value; interface Props { onUnlock(param: any): void; } interface State { publicKey: string; chainCode: string; dPath: string; error: string | null; isLoading: boolean; } export default class TrezorDecrypt extends Component { public state: State = { publicKey: '', chainCode: '', dPath: DEFAULT_PATH, error: null, isLoading: false }; public render() { const { dPath, publicKey, chainCode, error, isLoading } = this.state; const showErr = error ? 'is-showing' : ''; return (
Guide:{' '} How to use TREZOR with MyEtherWallet
{error || '-'}
{translate('Don’t have a TREZOR? Order one now!')}
); } private handlePathChange = (dPath: string) => { this.setState({ dPath }); this.handleConnect(dPath); }; private handleConnect = (dPath: string = this.state.dPath): void => { this.setState({ isLoading: true, error: null }); // TODO: type vendor file (TrezorConnect as any).getXPubKey( dPath, res => { if (res.success) { this.setState({ dPath, publicKey: res.publicKey, chainCode: res.chainCode, isLoading: false }); } else { this.setState({ error: res.error, isLoading: false }); } }, '1.5.2' ); }; private handleCancel = () => { this.reset(); }; private handleUnlock = (address: string, index: number) => { this.props.onUnlock(new TrezorWallet(address, this.state.dPath, index)); this.reset(); }; private handleNullConnect = (): void => this.handleConnect(); private reset() { this.setState({ publicKey: '', chainCode: '', dPath: DEFAULT_PATH }); } }