mirror of
https://github.com/status-im/MyCrypto.git
synced 2025-01-31 21:34:58 +00:00
ab5fa1a799
* Make UnlockHeader a PureComponent * MVP * actually disable wallet format if not determined to be valid format for wallet * default to correct derivation in mnemonic modal * cleanup * fix tslint * use enums for HD wallet getPath * Add stricter typing * Fix labels not updating on selector * Ban hardware wallet support for custom network unsupported chainIds * Fix type error * Fix custom node dPath not being saved * Fix mnemonic modal * default path bugfixes * add react-select * misc fixes; rabbit holing hard. * fix tslint * revert identicon changes * reload on network change :/ * actually reload on network change * really really reload on network change * tslint fixes * Update styles * set table width * fix package versioning * push broken sagas * Fix saga test * fix tslint * address round of review * move non-selectors out to utilty; adjust reload timer * cleanup network util comments * manage wallet disable at WalletDecrypt instead of in both WalletDecrypt and WalletButton * Separate WalletDecrypt props into ownProps / StateProps * disable payment requests on non-eth networks * specialize connect; separate props * remove unused state prop * remove bad import * create tests for networks * Clarify Lite-Send error on non-ethereum networkS * remove string option for network config name * Create concept of always-on 'EXTRA_PATHS'; include SINGULAR_DTV legacy dPath in 'EXTRA_PATHS' * fix multiple imports * address PR comments
102 lines
3.1 KiB
TypeScript
102 lines
3.1 KiB
TypeScript
import { IFullWallet, IV3Wallet } from 'ethereumjs-wallet';
|
|
import { toChecksumAddress } from 'ethereumjs-util';
|
|
import React, { Component } from 'react';
|
|
import translate from 'translations';
|
|
import { makeBlob } from 'utils/blob';
|
|
import './DownloadWallet.scss';
|
|
import Template from '../Template';
|
|
import { N_FACTOR } from 'config';
|
|
|
|
interface Props {
|
|
wallet: IFullWallet;
|
|
password: string;
|
|
continue(): void;
|
|
}
|
|
|
|
interface State {
|
|
hasDownloadedWallet: boolean;
|
|
keystore: IV3Wallet | null;
|
|
}
|
|
|
|
export default class DownloadWallet extends Component<Props, State> {
|
|
public state: State = {
|
|
hasDownloadedWallet: false,
|
|
keystore: null
|
|
};
|
|
|
|
public componentWillMount() {
|
|
this.setWallet(this.props.wallet, this.props.password);
|
|
}
|
|
|
|
public componentWillUpdate(nextProps: Props) {
|
|
if (this.props.wallet !== nextProps.wallet) {
|
|
this.setWallet(nextProps.wallet, nextProps.password);
|
|
}
|
|
}
|
|
|
|
public render() {
|
|
const { hasDownloadedWallet } = this.state;
|
|
const filename = this.props.wallet.getV3Filename();
|
|
|
|
return (
|
|
<Template>
|
|
<div className="DlWallet">
|
|
<h1 className="DlWallet-title">{translate('GEN_Label_2')}</h1>
|
|
|
|
<a
|
|
role="button"
|
|
className="DlWallet-download btn btn-primary btn-lg"
|
|
aria-label="Download Keystore File (UTC / JSON · Recommended · Encrypted)"
|
|
aria-describedby={translate('x_KeystoreDesc')}
|
|
download={filename}
|
|
href={this.getBlob()}
|
|
onClick={this.handleDownloadKeystore}
|
|
>
|
|
{translate('x_Download')} {translate('x_Keystore2')}
|
|
</a>
|
|
|
|
<div className="DlWallet-warning">
|
|
<p>
|
|
<strong>Do not lose it!</strong> It cannot be recovered if you lose it.
|
|
</p>
|
|
<p>
|
|
<strong>Do not share it!</strong> Your funds will be stolen if you use this file on a
|
|
malicious/phishing site.
|
|
</p>
|
|
<p>
|
|
<strong>Make a backup!</strong> Secure it like the millions of dollars it may one day
|
|
be worth.
|
|
</p>
|
|
</div>
|
|
|
|
<button
|
|
className="DlWallet-continue btn btn-danger"
|
|
role="button"
|
|
onClick={this.handleContinue}
|
|
disabled={!hasDownloadedWallet}
|
|
>
|
|
I understand. Continue.
|
|
</button>
|
|
</div>
|
|
</Template>
|
|
);
|
|
}
|
|
|
|
public getBlob = () =>
|
|
(this.state.keystore && makeBlob('text/json;charset=UTF-8', this.state.keystore)) || undefined;
|
|
|
|
private markDownloaded = () =>
|
|
this.state.keystore && this.setState({ hasDownloadedWallet: true });
|
|
|
|
private handleContinue = () => this.state.hasDownloadedWallet && this.props.continue();
|
|
|
|
private setWallet(wallet: IFullWallet, password: string) {
|
|
const keystore = wallet.toV3(password, { n: N_FACTOR });
|
|
keystore.address = toChecksumAddress(keystore.address);
|
|
this.setState({ keystore });
|
|
}
|
|
|
|
private handleDownloadKeystore = (e: React.FormEvent<HTMLAnchorElement>) =>
|
|
this.state.keystore ? this.markDownloaded() : e.preventDefault();
|
|
}
|