Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
slaweet committed Nov 22, 2017
1 parent a58d012 commit 2d2b839
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 28 deletions.
3 changes: 2 additions & 1 deletion i18n/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"Downvotes:": "Downvotes:",
"Edit": "Edit",
"Encrypt message": "Encrypt message",
"Encrypted Message": "Encrypted Message",
"Enter the missing word": "Enter the missing word",
"Enter your passphrase": "Enter your passphrase",
"Entered passphrase does not belong to the active account": "Entered passphrase does not belong to the active account",
Expand Down Expand Up @@ -109,7 +110,6 @@
"Processing delegate names: ": "Processing delegate names: ",
"Proxy Authentication": "Proxy Authentication",
"Public Key": "Public Key",
"Public key : ": "Public key:",
"Quit": "Quit",
"Rank": "Rank",
"Receive LSK": "Receive LSK",
Expand Down Expand Up @@ -158,6 +158,7 @@
"The download was started. Depending on your internet speed it can take up to several minutes. You will be informed then it is finished and prompted to restart the app.": "The download was started. Depending on your internet speed it can take up to several minutes. You will be informed then it is finished and prompted to restart the app.",
"There are no transactions, yet.": "There are no transactions, yet.",
"There is a new version ({{version}}) available, do you want to update now?": "There is a new version ({{version}}) available, do you want to update now?",
"There was an error when trying to decrypt the message": "There was an error when trying to decrypt the message",
"This account is protected by a second passphrase": "This account is protected by a second passphrase",
"This passphrase is not recoverable and if you lose it, you will lose access to your account forever.": "This passphrase is not recoverable and if you lose it, you will lose access to your account forever.",
"This will save public key of your account on this device, so next time it will launch without the need to log in. However, you will be prompted to enter the passphrase once you want to do any transaction.": "This will save public key of your account on this device, so next time it will launch without the need to log in. However, you will be prompted to enter the passphrase once you want to do any transaction.",
Expand Down
27 changes: 12 additions & 15 deletions src/components/decryptMessage/decryptMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ class DecryptMessage extends React.Component {
super();
this.state = {
result: '',
nonce: {
senderPublicKey: {
value: '',
},
message: {
value: '',
},
senderPublicKey: {
nonce: {
value: '',
},
};
Expand All @@ -28,6 +28,7 @@ class DecryptMessage extends React.Component {
value,
error,
},
result: '',
});
}

Expand All @@ -41,15 +42,12 @@ class DecryptMessage extends React.Component {
this.props.account.passphrase,
this.state.senderPublicKey.value);
} catch (error) {
this.props.errorToast({ label: error.message });
this.props.errorToast({
label: this.props.t('There was an error when trying to decrypt the message'),
});
}
if (decryptedMessage) {
const result = [
'-----DECRYPTED MESSAGE-----',
decryptedMessage,
].join('\n');
this.setState({ result, resultIsShown: false });
this.setState({ resultIsShown: true });
this.setState({ result: decryptedMessage });
this.props.successToast({ label: this.props.t('Message is decrypted successfully') });
}
}
Expand All @@ -63,17 +61,16 @@ class DecryptMessage extends React.Component {
autoFocus={true}
value={this.state.senderPublicKey.value}
onChange={this.handleChange.bind(this, 'senderPublicKey')} />
<Input className='message' multiline label={this.props.t('Encrypted Message')}
autoFocus={true}
value={this.state.message.value}
onChange={this.handleChange.bind(this, 'message')} />
<Input className='nonce' label={this.props.t('Nonce')}
autoFocus={true}
value={this.state.nonce.value}
onChange={this.handleChange.bind(this, 'nonce')} />
<Input className='message' multiline label={this.props.t('Message')}
autoFocus={true}
value={this.state.message.value}
onChange={this.handleChange.bind(this, 'message')} />

</section>
{this.state.resultIsShown ?
{this.state.result ?
<SignVerifyResult result={this.state.result} title={this.props.t('Result')} /> :
<ActionBar
secondaryButton={{
Expand Down
4 changes: 2 additions & 2 deletions src/components/decryptMessage/decryptMessage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ describe('DecryptMessage', () => {
});

it('shows error toast when couldn\'t decrypt a message', () => {
decryptMessageMock.throws({ message: 'couldn\'t decrypt the message' });
decryptMessageMock.throws(new Error('couldn\'t decrypt the message'));
wrapper.find('.message textarea').simulate('change', { target: { value: message } });
wrapper.find('.senderPublicKey input').simulate('change', { target: { value: senderPublicKey } });
wrapper.find('.nonce input').simulate('change', { target: { value: nonce } });
wrapper.find('form').simulate('submit');
expect(errorSpy).to.have.been.calledWith({ label: 'couldn\'t decrypt the message' });
expect(errorSpy).to.have.been.calledWith({ label: 'There was an error when trying to decrypt the message' });
});

it('allows to decrypt a message, copies encrypted message result to clipboard and shows success toast', () => {
Expand Down
17 changes: 7 additions & 10 deletions src/components/encryptMessage/encryptMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from 'react';
import Input from 'react-toolbox/lib/input';
import Lisk from 'lisk-js';
import { translate } from 'react-i18next';
import InfoParagraph from '../infoParagraph';
import SignVerifyResult from '../signVerifyResult';
import ActionBar from '../actionBar';

Expand All @@ -27,6 +26,7 @@ class EncryptMessage extends React.Component {
value,
error,
},
result: null,
});
}

Expand All @@ -43,12 +43,16 @@ class EncryptMessage extends React.Component {
}
if (cryptoResult) {
const result = [
'-----BEGIN LISK ENCRYPTED MESSAGE-----',
'-----SENDER PUBLIC KEY-----',
this.props.account.publicKey,
'-----ENCRYPTED MESSAGE-----',
cryptoResult.encryptedMessage,
'-----NONCE-----',
cryptoResult.nonce,
'-----END LISK ENCRYPTED MESSAGE-----',
].join('\n');
this.setState({ result, resultIsShown: false });
this.setState({ result });
this.showResult();
}
}
Expand All @@ -60,20 +64,13 @@ class EncryptMessage extends React.Component {
if (copied) {
this.props.successToast({ label: this.props.t('Result copied to clipboard') });
}
this.setState({ resultIsShown: true });
}

render() {
return (
<div className='sign-message'>
<form onSubmit={this.encrypt.bind(this)}>
<section>
<InfoParagraph>
<h3>
{this.props.t('Public key : ')}
</h3>
{this.props.account.publicKey}
</InfoParagraph>
<Input className='recipientPublicKey' label={this.props.t('Recipient PublicKey')}
autoFocus={true}
value={this.state.recipientPublicKey.value}
Expand All @@ -83,7 +80,7 @@ class EncryptMessage extends React.Component {
value={this.state.message.value}
onChange={this.handleChange.bind(this, 'message')} />
</section>
{this.state.resultIsShown ?
{this.state.result ?
<SignVerifyResult id='encryptResult' result={this.state.result} title={this.props.t('Result')} /> :
<ActionBar
secondaryButton={{
Expand Down

0 comments on commit 2d2b839

Please sign in to comment.