// @flow import './Trezor.scss'; import React, { Component } from 'react'; import translate from 'translations'; import TrezorConnect from 'vendor/trezor-connect'; import DeterministicWalletsModal from './DeterministicWalletsModal'; import TrezorWallet from 'libs/wallet/trezor'; import DPATHS from 'config/dpaths.js'; const DEFAULT_PATH = DPATHS.TREZOR[0].value; type State = { publicKey: string, chainCode: string, dPath: string, error: ?string, isLoading: boolean }; export default class TrezorDecrypt extends Component { props: { onUnlock: any => void }; state: State = { publicKey: '', chainCode: '', dPath: DEFAULT_PATH, error: null, isLoading: false }; _handlePathChange = (dPath: string) => { this._handleConnect(dPath); }; _handleConnect = (dPath: string = this.state.dPath) => { this.setState({ isLoading: true, error: null }); TrezorConnect.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' ); }; _handleCancel = () => { this.setState({ publicKey: '', chainCode: '', dPath: DEFAULT_PATH }); }; _handleUnlock = (address: string, index: number) => { this.props.onUnlock(new TrezorWallet(address, this.state.dPath, index)); }; 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!')}
); } }