// @flow import React from 'react'; import { Form, FormField, Submit } from 'component/common/form'; import { Modal } from 'modal/modal'; import Button from 'component/button'; type Props = { closeModal: () => void, walletEncryptSucceded: boolean, updateWalletStatus: boolean, encryptWallet: (?string) => void, updateWalletStatus: () => void, }; type State = { newPassword: ?string, newPasswordConfirm: ?string, passwordMismatch: boolean, understandConfirmed: boolean, understandError: boolean, submitted: boolean, failMessage: ?string, }; class ModalWalletEncrypt extends React.PureComponent { state = { newPassword: null, newPasswordConfirm: null, passwordMismatch: false, understandConfirmed: false, understandError: false, submitted: false, // Prior actions could be marked complete failMessage: undefined, }; componentDidUpdate() { const { props, state } = this; if (state.submitted) { if (props.walletEncryptSucceded === true) { props.closeModal(); props.updateWalletStatus(); } else if (props.walletEncryptSucceded === false) { // See https://github.com/lbryio/lbry/issues/1307 this.setState({ failMessage: 'Unable to encrypt wallet.' }); } } } onChangeNewPassword(event: SyntheticInputEvent<>) { this.setState({ newPassword: event.target.value }); } onChangeNewPasswordConfirm(event: SyntheticInputEvent<>) { this.setState({ newPasswordConfirm: event.target.value }); } onChangeUnderstandConfirm(event: SyntheticInputEvent<>) { this.setState({ understandConfirmed: /^.?i understand.?$/i.test(event.target.value), }); } submitEncryptForm() { const { state } = this; let invalidEntries = false; if (state.newPassword !== state.newPasswordConfirm) { this.setState({ passwordMismatch: true }); invalidEntries = true; } if (state.understandConfirmed === false) { this.setState({ understandError: true }); invalidEntries = true; } if (invalidEntries === true) { return; } this.setState({ submitted: true }); this.props.encryptWallet(state.newPassword); } render() { const { closeModal } = this.props; const { passwordMismatch, understandError, failMessage } = this.state; return ( this.submitEncryptForm()} onAborted={closeModal} >
this.submitEncryptForm()}>

{__( 'Encrypting your wallet will require a password to access your local wallet data when LBRY starts. Please enter a new password for your wallet.' )}{' '}