import React from 'react'; import { toChecksumAddress } from 'ethereumjs-util'; import translate, { translateRaw } from 'translations'; import { IWallet } from 'libs/wallet'; import { print } from 'components/PrintableWallet'; import { Identicon, QRCode, Input } 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.setStateFromWallet(this.props.wallet); } public componentWillReceiveProps(nextProps: Props) { if (this.props.wallet !== nextProps.wallet) { this.setStateFromWallet(nextProps.wallet); } } public render() { const { address, privateKey, isPrivateKeyVisible, isKeystoreModalOpen } = this.state; return (
{privateKey && (
)}
{privateKey && (
{!isPrivateKeyVisible && (
)}
)}
); } private setStateFromWallet(wallet: IWallet) { const address = toChecksumAddress(wallet.getAddressString()); const privateKey = wallet.getPrivateKeyString ? wallet.getPrivateKeyString() : ''; this.setState({ address, privateKey }); } private togglePrivateKey = () => { this.setState({ isPrivateKeyVisible: !this.state.isPrivateKeyVisible }); }; private toggleKeystoreModal = () => { this.setState({ isKeystoreModalOpen: !this.state.isKeystoreModalOpen }); }; }