import React from 'react'; import translate, { translateRaw } from 'translations'; import { IWallet } from 'libs/wallet'; import { print } from 'components/PrintableWallet'; import { Identicon, QRCode } from 'components/ui'; import { GenerateKeystoreModal, TogglablePassword } from 'components'; import './WalletInfo.scss'; interface Props { wallet: IWallet; } interface State { address: string; privateKey: string; isPrivateKeyVisible: boolean; isKeystoreModalOpen: boolean; } export default class WalletInfo extends React.PureComponent { public state = { address: '', privateKey: '', isPrivateKeyVisible: false, isKeystoreModalOpen: false }; public componentDidMount() { this.setWalletAsyncState(this.props.wallet); } public componentWillReceiveProps(nextProps: Props) { if (this.props.wallet !== nextProps.wallet) { this.setWalletAsyncState(nextProps.wallet); } } public render() { const { address, privateKey, isPrivateKeyVisible, isKeystoreModalOpen } = this.state; return (
{privateKey && (
)}
{privateKey && (
{!isPrivateKeyVisible && (
)}
)}
); } private async setWalletAsyncState(wallet: IWallet) { const address = await wallet.getAddressString(); const privateKey = wallet.getPrivateKeyString ? await wallet.getPrivateKeyString() : ''; this.setState({ address, privateKey }); } private togglePrivateKey = () => { this.setState({ isPrivateKeyVisible: !this.state.isPrivateKeyVisible }); }; private toggleKeystoreModal = () => { this.setState({ isKeystoreModalOpen: !this.state.isKeystoreModalOpen }); }; }