2018-07-18 15:48:30 -04:00
|
|
|
// @flow
|
|
|
|
import React from 'react';
|
2019-02-13 12:27:20 -04:00
|
|
|
import { Form, FormField } from 'component/common/form';
|
2018-07-18 15:48:30 -04:00
|
|
|
import { Modal } from 'modal/modal';
|
|
|
|
import Button from 'component/button';
|
2019-08-27 22:35:07 -04:00
|
|
|
import { getSavedPassword, setSavedPassword } from 'util/saved-passwords';
|
2018-07-18 15:48:30 -04:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
quit: () => void,
|
2019-01-19 13:54:06 -05:00
|
|
|
closeModal: () => void,
|
|
|
|
unlockWallet: (?string) => void,
|
2018-07-18 15:48:30 -04:00
|
|
|
walletUnlockSucceded: boolean,
|
2019-10-21 20:12:43 -04:00
|
|
|
shouldTryWithBlankPassword: boolean,
|
2018-07-18 15:48:30 -04:00
|
|
|
};
|
|
|
|
|
2019-03-18 01:09:50 -04:00
|
|
|
type State = {
|
|
|
|
password: string,
|
2019-08-20 08:29:59 -04:00
|
|
|
rememberPassword: boolean,
|
2019-03-18 01:09:50 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
class ModalWalletUnlock extends React.PureComponent<Props, State> {
|
2018-07-18 15:48:30 -04:00
|
|
|
state = {
|
2019-03-18 01:09:50 -04:00
|
|
|
password: '',
|
2019-08-20 08:29:59 -04:00
|
|
|
rememberPassword: false,
|
2018-07-18 15:48:30 -04:00
|
|
|
};
|
|
|
|
|
2019-08-27 22:35:07 -04:00
|
|
|
componentDidMount() {
|
2019-10-21 20:12:43 -04:00
|
|
|
const { unlockWallet, shouldTryWithBlankPassword } = this.props;
|
2019-10-04 12:56:09 -04:00
|
|
|
|
2019-10-21 20:12:43 -04:00
|
|
|
getSavedPassword().then(p => {
|
|
|
|
if (p !== null) {
|
|
|
|
this.setState({ password: p, rememberPassword: true });
|
|
|
|
unlockWallet(p);
|
|
|
|
} else if (shouldTryWithBlankPassword) {
|
|
|
|
unlockWallet('');
|
|
|
|
}
|
|
|
|
});
|
2019-08-27 22:35:07 -04:00
|
|
|
}
|
2018-07-18 15:48:30 -04:00
|
|
|
componentDidUpdate() {
|
|
|
|
const { props } = this;
|
|
|
|
|
|
|
|
if (props.walletUnlockSucceded === true) {
|
2019-10-17 11:27:41 -04:00
|
|
|
setSavedPassword(this.state.password, this.state.rememberPassword);
|
2018-07-18 15:48:30 -04:00
|
|
|
props.closeModal();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-18 01:09:50 -04:00
|
|
|
onChangePassword(event: SyntheticInputEvent<*>) {
|
2018-07-18 15:48:30 -04:00
|
|
|
this.setState({ password: event.target.value });
|
|
|
|
}
|
|
|
|
|
2019-08-20 08:29:59 -04:00
|
|
|
onChangeRememberPassword(event: SyntheticInputEvent<>) {
|
|
|
|
this.setState({ rememberPassword: event.target.checked });
|
|
|
|
}
|
|
|
|
|
2018-07-18 15:48:30 -04:00
|
|
|
render() {
|
2019-01-14 13:40:06 -05:00
|
|
|
const { quit, unlockWallet, walletUnlockSucceded } = this.props;
|
2018-07-18 15:48:30 -04:00
|
|
|
|
2019-08-20 08:29:59 -04:00
|
|
|
const { password, rememberPassword } = this.state;
|
2018-07-18 15:48:30 -04:00
|
|
|
return (
|
|
|
|
<Modal
|
|
|
|
isOpen
|
2018-09-26 13:48:07 -04:00
|
|
|
title={__('Unlock Wallet')}
|
2018-07-18 15:48:30 -04:00
|
|
|
contentLabel={__('Unlock Wallet')}
|
2019-03-20 17:43:00 -04:00
|
|
|
type="confirm"
|
2018-08-15 15:56:42 -04:00
|
|
|
shouldCloseOnOverlayClick={false}
|
2018-07-18 15:48:30 -04:00
|
|
|
confirmButtonLabel={__('Unlock')}
|
|
|
|
abortButtonLabel={__('Exit')}
|
|
|
|
onConfirmed={() => unlockWallet(password)}
|
|
|
|
onAborted={quit}
|
|
|
|
>
|
2019-09-26 12:28:08 -04:00
|
|
|
<p>
|
|
|
|
{__('Your wallet has been encrypted with a local password. Please enter your wallet password to proceed.')}{' '}
|
|
|
|
<Button button="link" label={__('Learn more')} href="https://lbry.com/faq/wallet-encryption" />.
|
|
|
|
</p>
|
|
|
|
<Form className="section" onSubmit={() => unlockWallet(password)}>
|
2019-07-21 17:31:22 -04:00
|
|
|
<FormField
|
|
|
|
autoFocus
|
|
|
|
error={walletUnlockSucceded === false ? 'Incorrect Password' : false}
|
|
|
|
label={__('Wallet Password')}
|
|
|
|
type="password"
|
|
|
|
name="wallet-password"
|
|
|
|
onChange={event => this.onChangePassword(event)}
|
2019-08-20 08:29:59 -04:00
|
|
|
value={password || ''}
|
2019-07-21 17:31:22 -04:00
|
|
|
/>
|
2019-08-20 08:29:59 -04:00
|
|
|
<fieldset-section>
|
|
|
|
<FormField
|
|
|
|
label={__('Remember Password')}
|
|
|
|
type="checkbox"
|
|
|
|
name="wallet-remember-password"
|
|
|
|
onChange={event => this.onChangeRememberPassword(event)}
|
|
|
|
checked={rememberPassword}
|
|
|
|
/>
|
|
|
|
</fieldset-section>
|
2019-07-21 17:31:22 -04:00
|
|
|
</Form>
|
2018-07-18 15:48:30 -04:00
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ModalWalletUnlock;
|