From efed9b4803705f13b40b493874866f9ca84ce4cd Mon Sep 17 00:00:00 2001 From: Daniel Ternyak Date: Sat, 14 Oct 2017 12:24:48 -0700 Subject: [PATCH] Fix Missing Address in Paper Wallet (#292) --- common/components/PaperWallet/index.tsx | 26 ++++---------- common/components/PrintableWallet/index.tsx | 40 ++++++++++++++++----- 2 files changed, 37 insertions(+), 29 deletions(-) diff --git a/common/components/PaperWallet/index.tsx b/common/components/PaperWallet/index.tsx index 1d34327c..a8f6baf9 100644 --- a/common/components/PaperWallet/index.tsx +++ b/common/components/PaperWallet/index.tsx @@ -1,5 +1,4 @@ import { Identicon, QRCode } from 'components/ui'; -import PrivKeyWallet from 'libs/wallet/privkey'; import React from 'react'; import ethLogo from 'assets/images/logo-ethereum-1.png'; @@ -91,26 +90,13 @@ const styles: any = { }; interface Props { - wallet: PrivKeyWallet; -} - -interface State { address: string; + privateKey: string; } -export default class PaperWallet extends React.Component { - public state = { address: '' }; - - public componentDidMount() { - if (!this.props.wallet) { - return; - } - this.props.wallet.getAddress().then(address => { - this.setState({ address }); - }); - } +export default class PaperWallet extends React.Component { public render() { - const privateKey = this.props.wallet.getPrivateKey(); + const { privateKey, address } = this.props; return (
@@ -119,7 +105,7 @@ export default class PaperWallet extends React.Component {
- +

YOUR ADDRESS

@@ -140,7 +126,7 @@ export default class PaperWallet extends React.Component {

Your Address:
- {this.state.address} + {address}

Your Private Key: @@ -151,7 +137,7 @@ export default class PaperWallet extends React.Component {

- +

Always look for this icon when sending to this wallet diff --git a/common/components/PrintableWallet/index.tsx b/common/components/PrintableWallet/index.tsx index 205d56b1..4bde0fe0 100644 --- a/common/components/PrintableWallet/index.tsx +++ b/common/components/PrintableWallet/index.tsx @@ -8,13 +8,33 @@ interface Props { wallet: PrivKeyWallet; } +interface State { + address: string | null; + privateKey: string | null; +} + +const initialState = { + address: null, + privateKey: null +}; + export default class PrintableWallet extends Component { + public state: State = initialState; + + public async componentDidMount() { + const address = await this.props.wallet.getAddress(); + const privateKey = this.props.wallet.getPrivateKey(); + this.setState({ address, privateKey }); + } + public print = () => { - printElement(, { - popupFeatures: { - scrollbars: 'no' - }, - styles: ` + const { address, privateKey } = this.state; + if (address && privateKey) { + printElement(, { + popupFeatures: { + scrollbars: 'no' + }, + styles: ` * { box-sizing: border-box; } @@ -26,13 +46,15 @@ export default class PrintableWallet extends Component { margin: 0; } ` - }); + }); + } }; public render() { - return ( + const { address, privateKey } = this.state; + return address && privateKey ? (

- ); + ) : null; } }