2017-09-25 02:06:28 +00:00
|
|
|
|
import DPATHS from 'config/dpaths';
|
2017-11-08 18:16:43 +00:00
|
|
|
|
import { TrezorWallet } from 'libs/wallet';
|
2017-07-04 03:21:19 +00:00
|
|
|
|
import React, { Component } from 'react';
|
2017-09-25 02:06:28 +00:00
|
|
|
|
import translate, { translateRaw } from 'translations';
|
2017-08-28 17:43:57 +00:00
|
|
|
|
import TrezorConnect from 'vendor/trezor-connect';
|
|
|
|
|
import DeterministicWalletsModal from './DeterministicWalletsModal';
|
2017-09-25 02:06:28 +00:00
|
|
|
|
import './Trezor.scss';
|
2017-08-28 17:43:57 +00:00
|
|
|
|
const DEFAULT_PATH = DPATHS.TREZOR[0].value;
|
|
|
|
|
|
2017-09-25 02:06:28 +00:00
|
|
|
|
interface Props {
|
|
|
|
|
onUnlock(param: any): void;
|
|
|
|
|
}
|
|
|
|
|
interface State {
|
|
|
|
|
publicKey: string;
|
|
|
|
|
chainCode: string;
|
|
|
|
|
dPath: string;
|
|
|
|
|
error: string | null;
|
|
|
|
|
isLoading: boolean;
|
|
|
|
|
}
|
2017-06-07 01:44:02 +00:00
|
|
|
|
|
2017-09-25 02:06:28 +00:00
|
|
|
|
export default class TrezorDecrypt extends Component<Props, State> {
|
|
|
|
|
public state: State = {
|
2017-08-28 17:43:57 +00:00
|
|
|
|
publicKey: '',
|
|
|
|
|
chainCode: '',
|
|
|
|
|
dPath: DEFAULT_PATH,
|
|
|
|
|
error: null,
|
|
|
|
|
isLoading: false
|
|
|
|
|
};
|
|
|
|
|
|
2017-09-25 02:06:28 +00:00
|
|
|
|
public render() {
|
2017-08-28 17:43:57 +00:00
|
|
|
|
const { dPath, publicKey, chainCode, error, isLoading } = this.state;
|
|
|
|
|
const showErr = error ? 'is-showing' : '';
|
|
|
|
|
|
2017-07-04 03:21:19 +00:00
|
|
|
|
return (
|
2017-08-28 17:43:57 +00:00
|
|
|
|
<section className="TrezorDecrypt col-md-4 col-sm-6">
|
|
|
|
|
<button
|
|
|
|
|
className="TrezorDecrypt-decrypt btn btn-primary btn-lg"
|
2017-09-25 02:06:28 +00:00
|
|
|
|
onClick={this.handleNullConnect}
|
2017-08-28 17:43:57 +00:00
|
|
|
|
disabled={isLoading}
|
|
|
|
|
>
|
|
|
|
|
{isLoading ? 'Unlocking...' : translate('ADD_Trezor_scan')}
|
|
|
|
|
</button>
|
|
|
|
|
|
|
|
|
|
<div className="TrezorDecrypt-help">
|
|
|
|
|
Guide:{' '}
|
|
|
|
|
<a
|
|
|
|
|
href="https://blog.trezor.io/trezor-integration-with-myetherwallet-3e217a652e08"
|
|
|
|
|
target="_blank"
|
|
|
|
|
rel="noopener"
|
|
|
|
|
>
|
|
|
|
|
How to use TREZOR with MyEtherWallet
|
|
|
|
|
</a>
|
2017-07-04 03:21:19 +00:00
|
|
|
|
</div>
|
2017-08-28 17:43:57 +00:00
|
|
|
|
|
|
|
|
|
<div className={`TrezorDecrypt-error alert alert-danger ${showErr}`}>
|
|
|
|
|
{error || '-'}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<a
|
|
|
|
|
className="TrezorDecrypt-buy btn btn-sm btn-default"
|
|
|
|
|
href="https://trezor.io/?a=myetherwallet.com"
|
|
|
|
|
target="_blank"
|
|
|
|
|
rel="noopener"
|
|
|
|
|
>
|
|
|
|
|
{translate('Don’t have a TREZOR? Order one now!')}
|
|
|
|
|
</a>
|
|
|
|
|
|
|
|
|
|
<DeterministicWalletsModal
|
|
|
|
|
isOpen={!!publicKey && !!chainCode}
|
|
|
|
|
publicKey={publicKey}
|
|
|
|
|
chainCode={chainCode}
|
|
|
|
|
dPath={dPath}
|
|
|
|
|
dPaths={DPATHS.TREZOR}
|
2017-09-25 02:06:28 +00:00
|
|
|
|
onCancel={this.handleCancel}
|
|
|
|
|
onConfirmAddress={this.handleUnlock}
|
|
|
|
|
onPathChange={this.handlePathChange}
|
|
|
|
|
walletType={translateRaw('x_Trezor')}
|
2017-08-28 17:43:57 +00:00
|
|
|
|
/>
|
2017-07-04 03:21:19 +00:00
|
|
|
|
</section>
|
|
|
|
|
);
|
|
|
|
|
}
|
2017-09-25 02:06:28 +00:00
|
|
|
|
|
|
|
|
|
private handlePathChange = (dPath: string) => {
|
2017-10-05 23:29:14 +00:00
|
|
|
|
this.setState({ dPath });
|
2017-09-25 02:06:28 +00:00
|
|
|
|
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.setState({
|
|
|
|
|
publicKey: '',
|
|
|
|
|
chainCode: '',
|
|
|
|
|
dPath: DEFAULT_PATH
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private handleUnlock = (address: string, index: number) => {
|
|
|
|
|
this.props.onUnlock(new TrezorWallet(address, this.state.dPath, index));
|
|
|
|
|
};
|
|
|
|
|
|
2017-10-30 19:10:25 +00:00
|
|
|
|
private handleNullConnect = (): void => this.handleConnect();
|
2017-07-04 03:21:19 +00:00
|
|
|
|
}
|