From 9d4ea6346e6869a72ee208e22a5cc26e12eb5626 Mon Sep 17 00:00:00 2001 From: yasharAyari Date: Wed, 16 May 2018 11:06:11 +0200 Subject: [PATCH 1/5] Add on translation string to common.json --- i18n/locales/en/common.json | 1 + 1 file changed, 1 insertion(+) diff --git a/i18n/locales/en/common.json b/i18n/locales/en/common.json index 79a1be30c..a1dff5530 100644 --- a/i18n/locales/en/common.json +++ b/i18n/locales/en/common.json @@ -121,6 +121,7 @@ "Recipient Address": "Recipient Address", "Recipient PublicKey": "Recipient PublicKey", "Redo": "Redo", + "Reference": "Reference", "Register": "Register", "Register Second Passphrase": "Register Second Passphrase", "Register as delegate": "Register as delegate", From 6c8e038128f4ee1f41364468c97ff76db5bc1717 Mon Sep 17 00:00:00 2001 From: yasharAyari Date: Wed, 16 May 2018 11:12:20 +0200 Subject: [PATCH 2/5] Add reference filed to send component --- src/actions/account.js | 9 +++++---- src/components/send/send.js | 9 +++++++++ src/components/send/send.test.js | 3 ++- src/utils/api/account.js | 11 +++++++++-- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/actions/account.js b/src/actions/account.js index e8831c753..4dbdcdd20 100644 --- a/src/actions/account.js +++ b/src/actions/account.js @@ -106,14 +106,15 @@ export const delegateRegistered = ({ /** * */ -export const sent = ({ activePeer, account, recipientId, amount, passphrase, secondPassphrase }) => +export const sent = ({ activePeer, account, recipientId, + amount, passphrase, secondPassphrase, data }) => (dispatch) => { loadingStarted('sent'); - send(activePeer, recipientId, toRawLsk(amount), passphrase, secondPassphrase) - .then((data) => { + send(activePeer, recipientId, toRawLsk(amount), passphrase, secondPassphrase, data) + .then((res) => { loadingFinished('sent'); dispatch(transactionAdded({ - id: data.id, + id: res.id, senderPublicKey: account.publicKey, senderId: account.address, recipientId, diff --git a/src/components/send/send.js b/src/components/send/send.js index f5f2a0e39..992dea35c 100644 --- a/src/components/send/send.js +++ b/src/components/send/send.js @@ -18,6 +18,9 @@ class Send extends React.Component { amount: { value: '', }, + reference: { + value: '', + }, ...authStatePrefill(), }; this.fee = 0.1; @@ -71,6 +74,7 @@ class Send extends React.Component { amount: this.state.amount.value, passphrase: this.state.passphrase.value, secondPassphrase: this.state.secondPassphrase.value, + data: this.state.reference.value, }); this.setState({ executed: true }); } @@ -98,6 +102,11 @@ class Send extends React.Component { error={this.state.amount.error} value={this.state.amount.value} onChange={this.handleChange.bind(this, 'amount')} /> + { }); it('renders two Input components', () => { - expect(wrapper.find('Input')).to.have.length(2); + expect(wrapper.find('Input')).to.have.length(3); }); it('renders two Button components', () => { @@ -102,6 +102,7 @@ describe('Send', () => { passphrase: props.account.passphrase, recipientId: '11004588490103196952L', secondPassphrase: null, + data: '', }); }); }); diff --git a/src/utils/api/account.js b/src/utils/api/account.js index 46802253b..56a04caf4 100644 --- a/src/utils/api/account.js +++ b/src/utils/api/account.js @@ -28,10 +28,17 @@ export const setSecondPassphrase = (activePeer, secondPassphrase, publicKey, pas }); }); -export const send = (activePeer, recipientId, amount, passphrase, secondPassphrase = null) => +export const send = (activePeer, recipientId, amount, + passphrase, secondPassphrase = null, data = null) => new Promise((resolve) => { const transaction = Lisk.transaction - .transfer({ recipientId, amount, passphrase, secondPassphrase }); + .transfer({ + recipientId, + amount, + passphrase, + secondPassphrase, + data, + }); activePeer.transactions.broadcast(transaction).then(() => { resolve(transaction); }); From fe39713a39ac9e508f7f481e1a2c892213eec804 Mon Sep 17 00:00:00 2001 From: yasharAyari Date: Wed, 16 May 2018 14:48:48 +0200 Subject: [PATCH 3/5] Update a translation string --- i18n/locales/en/common.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/i18n/locales/en/common.json b/i18n/locales/en/common.json index a1dff5530..a7a473977 100644 --- a/i18n/locales/en/common.json +++ b/i18n/locales/en/common.json @@ -121,7 +121,7 @@ "Recipient Address": "Recipient Address", "Recipient PublicKey": "Recipient PublicKey", "Redo": "Redo", - "Reference": "Reference", + "Reference (If you use this field, your transaction fee will be 0.2 LSK)": "Reference (If you use this field, your transaction fee will be 0.2 LSK)", "Register": "Register", "Register Second Passphrase": "Register Second Passphrase", "Register as delegate": "Register as delegate", From 503ec225b9e5df64252e9915160f0579de01a1ce Mon Sep 17 00:00:00 2001 From: yasharAyari Date: Wed, 16 May 2018 14:49:39 +0200 Subject: [PATCH 4/5] Increase transaction fee when use add reference to a transaction --- src/components/send/send.js | 15 ++++++++++----- src/components/send/send.test.js | 7 +++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/components/send/send.js b/src/components/send/send.js index 992dea35c..6681c3dc5 100644 --- a/src/components/send/send.js +++ b/src/components/send/send.js @@ -21,9 +21,9 @@ class Send extends React.Component { reference: { value: '', }, + fee: 0.1, ...authStatePrefill(), }; - this.fee = 0.1; this.inputValidationRegexps = { recipient: /^\d{1,21}[L|l]$/, amount: /^\d+(\.\d{1,8})?$/, @@ -44,7 +44,10 @@ class Send extends React.Component { } handleChange(name, value, error) { + const fee = (name === 'reference' && value.length > 0) ? + 0.2 : 0.1; this.setState({ + fee, [name]: { value, error: typeof error === 'string' ? error : this.validateInput(name, value), @@ -53,7 +56,7 @@ class Send extends React.Component { } validateInput(name, value) { - if (!value) { + if (!value && name !== 'reference') { return this.props.t('Required'); } else if (!value.match(this.inputValidationRegexps[name])) { return this.props.t('Invalid'); @@ -80,7 +83,7 @@ class Send extends React.Component { } getMaxAmount() { - return fromRawLsk(Math.max(0, this.props.account.balance - toRawLsk(this.fee))); + return fromRawLsk(Math.max(0, this.props.account.balance - toRawLsk(this.state.fee))); } setMaxAmount() { @@ -102,7 +105,9 @@ class Send extends React.Component { error={this.state.amount.error} value={this.state.amount.value} onChange={this.handleChange.bind(this, 'amount')} /> - -
{this.props.t('Fee: {{fee}} LSK', { fee: this.fee })}
+
{this.props.t('Fee: {{fee}} LSK', { fee: this.state.fee })}
{ expect(wrapper.find('Input.amount').text()).to.contain('Insufficient funds'); }); + + it('show filling reference field increase transaction fee to 0.2 LSK', () => { + expect(wrapper.state('fee')).to.be.equal(0.1); + wrapper.find('.reference input').simulate('change', { target: { value: 'message' } }); + expect(wrapper.state('fee')).to.be.equal(0.2); + }); + it('recognizes empty amount', () => { wrapper.find('.amount input').simulate('change', { target: { value: '12000' } }); wrapper.find('.amount input').simulate('change', { target: { value: '' } }); From 101c078f2b3fe3e18f00e02c2256f2dff2036594 Mon Sep 17 00:00:00 2001 From: yasharAyari Date: Thu, 17 May 2018 09:48:48 +0200 Subject: [PATCH 5/5] Add validation for reference field --- i18n/locales/en/common.json | 4 +++- src/components/send/send.css | 7 +++++++ src/components/send/send.js | 9 ++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/i18n/locales/en/common.json b/i18n/locales/en/common.json index a7a473977..a0c8fbaec 100644 --- a/i18n/locales/en/common.json +++ b/i18n/locales/en/common.json @@ -73,6 +73,7 @@ "Lisk Website": "Lisk Website", "Login": "Login", "Mainnet": "Mainnet", + "Maximum length of 64 characters is exceeded.": "Maximum length of 64 characters is exceeded.", "Maximum of {{n}} votes exceeded.": "Maximum of {{n}} votes exceeded.", "Maximum of {{n}} votes in one transaction exceeded.": "Maximum of {{n}} votes in one transaction exceeded.", "Message": "Message", @@ -121,7 +122,7 @@ "Recipient Address": "Recipient Address", "Recipient PublicKey": "Recipient PublicKey", "Redo": "Redo", - "Reference (If you use this field, your transaction fee will be 0.2 LSK)": "Reference (If you use this field, your transaction fee will be 0.2 LSK)", + "Reference": "Reference", "Register": "Register", "Register Second Passphrase": "Register Second Passphrase", "Register as delegate": "Register as delegate", @@ -189,6 +190,7 @@ "Uptime": "Uptime", "Upvotes:": "Upvotes:", "Username": "Username", + "Using a reference will cost an additional fee of 0.1 LSK. Your total transaction fee will be 0.2 LSK if you choose to use a reference.": "Using a reference will cost an additional fee of 0.1 LSK. Your total transaction fee will be 0.2 LSK if you choose to use a reference.", "Verify message": "Verify message", "Version": "Version", "View": "View", diff --git a/src/components/send/send.css b/src/components/send/send.css index 4bf82e741..f9039cd6e 100644 --- a/src/components/send/send.css +++ b/src/components/send/send.css @@ -16,3 +16,10 @@ line-height: 14px; color: grey; } + +.notice { + float: left; + margin-right: 10px; + display: inline-block; + margin-top: -3px; +} diff --git a/src/components/send/send.js b/src/components/send/send.js index 6681c3dc5..7f9d35ab4 100644 --- a/src/components/send/send.js +++ b/src/components/send/send.js @@ -1,6 +1,7 @@ import React from 'react'; import Input from 'react-toolbox/lib/input'; import { IconMenu, MenuItem } from 'react-toolbox/lib/menu'; +import FontIcon from 'react-toolbox/lib/font_icon'; import { fromRawLsk, toRawLsk } from '../../utils/lsk'; import AuthInputs from '../authInputs'; import ActionBar from '../actionBar'; @@ -64,6 +65,8 @@ class Send extends React.Component { return this.props.t('Insufficient funds'); } else if (name === 'amount' && value === '0') { return this.props.t('Zero not allowed'); + } else if (name === 'reference' && value.length > 64) { + return this.props.t('Maximum length of 64 characters is exceeded.'); } return undefined; } @@ -106,12 +109,16 @@ class Send extends React.Component { value={this.state.amount.value} onChange={this.handleChange.bind(this, 'amount')} /> + {this.state.reference.value.length > 0 ?
+ + {this.props.t('Using a reference will cost an additional fee of 0.1 LSK. Your total transaction fee will be 0.2 LSK if you choose to use a reference.')} +
: null }