-
Notifications
You must be signed in to change notification settings - Fork 414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add basic wallet encryption flows #1785
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6809ac3
Add basic wallet encryption flows
097a523
Merge branch 'master' into wallet-encryption
skhameneh a727e89
Remove debug line, add Form components
10852ac
update lbry-redux
cda83d2
Update CHANGELOG.md
skhameneh 2ccf40b
Merge branch 'master' into wallet-encryption
skhameneh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { connect } from 'react-redux'; | ||
import { | ||
doHideNotification, | ||
doWalletStatus, | ||
doWalletDecrypt, | ||
selectWalletDecryptSucceeded, | ||
} from 'lbry-redux'; | ||
import ModalWalletDecrypt from './view'; | ||
|
||
const select = state => ({ | ||
walletDecryptSucceded: selectWalletDecryptSucceeded(state), | ||
}); | ||
|
||
const perform = dispatch => ({ | ||
closeModal: () => dispatch(doHideNotification()), | ||
decryptWallet: password => dispatch(doWalletDecrypt(password)), | ||
updateWalletStatus: () => dispatch(doWalletStatus()), | ||
}); | ||
|
||
export default connect( | ||
select, | ||
perform | ||
)(ModalWalletDecrypt); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// @flow | ||
import React from 'react'; | ||
import { FormRow, FormField } from 'component/common/form'; | ||
import { Modal } from 'modal/modal'; | ||
import Button from 'component/button'; | ||
|
||
type Props = { | ||
closeModal: () => void, | ||
unlockWallet: string => void, | ||
walletDecryptSucceded: boolean, | ||
updateWalletStatus: boolean, | ||
}; | ||
|
||
class ModalWalletDecrypt extends React.PureComponent<Props> { | ||
state = { | ||
submitted: false, // Prior actions could be marked complete | ||
}; | ||
|
||
submitDecryptForm() { | ||
this.setState({ submitted: true }); | ||
this.props.decryptWallet(); | ||
} | ||
|
||
componentDidUpdate() { | ||
const { props, state } = this; | ||
|
||
if (state.submitted && props.walletDecryptSucceded === true) { | ||
props.closeModal(); | ||
props.updateWalletStatus(); | ||
} | ||
} | ||
|
||
render() { | ||
const { closeModal, walletDecryptSucceded } = this.props; | ||
|
||
return ( | ||
<Modal | ||
isOpen | ||
contentLabel={__('Decrypt Wallet')} | ||
type="confirm" | ||
confirmButtonLabel={__('Decrypt Wallet')} | ||
abortButtonLabel={__('Cancel')} | ||
onConfirmed={() => this.submitDecryptForm()} | ||
onAborted={closeModal} | ||
> | ||
{__( | ||
'Your wallet has been encrypted with a local password, performing this action will remove this password.' | ||
)} | ||
<FormRow padded> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't be a |
||
<Button | ||
button="link" | ||
label={__('Learn more')} | ||
href="https://lbry.io/faq/wallet-encryption" | ||
/> | ||
</FormRow> | ||
</Modal> | ||
); | ||
} | ||
} | ||
|
||
export default ModalWalletDecrypt; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { connect } from 'react-redux'; | ||
import { | ||
doHideNotification, | ||
doWalletStatus, | ||
doWalletEncrypt, | ||
selectWalletEncryptPending, | ||
selectWalletEncryptSucceeded, | ||
selectWalletEncryptResult, | ||
} from 'lbry-redux'; | ||
import ModalWalletEncrypt from './view'; | ||
|
||
const select = state => ({ | ||
walletEncryptSucceded: selectWalletEncryptSucceeded(state), | ||
walletEncryptResult: selectWalletEncryptResult(state), | ||
}); | ||
|
||
const perform = dispatch => ({ | ||
closeModal: () => dispatch(doHideNotification()), | ||
encryptWallet: password => dispatch(doWalletEncrypt(password)), | ||
updateWalletStatus: () => dispatch(doWalletStatus()), | ||
}); | ||
|
||
export default connect( | ||
select, | ||
perform | ||
)(ModalWalletEncrypt); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
// @flow | ||
import React from 'react'; | ||
import { FormRow, FormField } from 'component/common/form'; | ||
import { Modal } from 'modal/modal'; | ||
import Button from 'component/button'; | ||
|
||
type Props = { | ||
closeModal: () => void, | ||
unlockWallet: string => void, | ||
walletEncryptSucceded: boolean, | ||
walletEncryptResult: boolean, | ||
updateWalletStatus: boolean, | ||
}; | ||
|
||
class ModalWalletEncrypt extends React.PureComponent<Props> { | ||
state = { | ||
newPassword: null, | ||
newPasswordConfirm: null, | ||
passwordMismatch: false, | ||
understandConfirmed: false, | ||
understandError: false, | ||
submitted: false, // Prior actions could be marked complete | ||
failMessage: false, | ||
}; | ||
|
||
onChangeNewPassword(event) { | ||
this.setState({ newPassword: event.target.value }); | ||
} | ||
|
||
onChangeNewPasswordConfirm(event) { | ||
this.setState({ newPasswordConfirm: event.target.value }); | ||
} | ||
|
||
onChangeUnderstandConfirm(event) { | ||
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); | ||
} | ||
|
||
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.' }); | ||
} | ||
} | ||
} | ||
|
||
render() { | ||
const { closeModal } = this.props; | ||
|
||
const { passwordMismatch, understandError, failMessage } = this.state; | ||
|
||
return ( | ||
<Modal | ||
isOpen | ||
contentLabel={__('Encrypt Wallet')} | ||
type="confirm" | ||
confirmButtonLabel={__('Encrypt Wallet')} | ||
abortButtonLabel={__('Cancel')} | ||
onConfirmed={() => this.submitEncryptForm()} | ||
onAborted={closeModal} | ||
> | ||
{__( | ||
'Encrypting your wallet will require a password to access your local wallet data when LBRY starts. Please enter a new password for your wallet.' | ||
)} | ||
<FormRow padded> | ||
<FormField | ||
stretch | ||
error={passwordMismatch === true ? 'Passwords do not match' : false} | ||
label={__('New Password')} | ||
type="password" | ||
name="wallet-new-password" | ||
onChange={event => this.onChangeNewPassword(event)} | ||
/> | ||
</FormRow> | ||
<FormRow padded> | ||
<FormField | ||
stretch | ||
error={passwordMismatch === true ? 'Passwords do not match' : false} | ||
label={__('Confirm Password')} | ||
type="password" | ||
name="wallet-new-password-confirm" | ||
onChange={event => this.onChangeNewPasswordConfirm(event)} | ||
/> | ||
</FormRow> | ||
<br /> | ||
{__( | ||
'If your password is lost, it cannot be recovered. You will not be able to access your wallet without a password.' | ||
)} | ||
<FormRow padded> | ||
<FormField | ||
stretch | ||
error={understandError === true ? 'You must enter "I understand"' : false} | ||
label={__('Enter "I understand"')} | ||
type="text" | ||
name="wallet-understand" | ||
onChange={event => this.onChangeUnderstandConfirm(event)} | ||
/> | ||
</FormRow> | ||
<FormRow padded> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, use |
||
<Button | ||
button="link" | ||
label={__('Learn more')} | ||
href="https://lbry.io/faq/wallet-encryption" | ||
/> | ||
</FormRow> | ||
{failMessage && <div className="error-text">{__(failMessage)}</div>} | ||
</Modal> | ||
); | ||
} | ||
} | ||
|
||
export default ModalWalletEncrypt; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this do?