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 { 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 ( ); } 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) => this.state.keystore ? this.markDownloaded() : e.preventDefault(); }