Skip to content

Commit

Permalink
🏠 Update files involve in PR #1377 as current version miss the update…
Browse files Browse the repository at this point in the history
… because another PR
  • Loading branch information
Osvaldo Vega committed Nov 16, 2018
1 parent f352148 commit a128585
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 11 deletions.
1 change: 1 addition & 0 deletions i18n/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@
"Sender": "Sender",
"Session timeout": "Session timeout",
"Session timeout in": "Session timeout in",
"Set max. amount": "Set max. amount",
"Set up Lisk Hub and your account.": "Set up Lisk Hub and your account.",
"Settings": "Settings",
"Show more": "Show more",
Expand Down
1 change: 0 additions & 1 deletion src/components/converter/converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,3 @@ class Converter extends React.Component {
}

export default Converter;

1 change: 0 additions & 1 deletion src/components/converter/converter.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { expect } from 'chai';
import React from 'react';
import configureMockStore from 'redux-mock-store';

import thunk from 'redux-thunk';

import { mountWithContext } from '../../../test/utils/mountHelpers';
Expand Down
16 changes: 16 additions & 0 deletions src/components/send/steps/form/form.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@
}
}

.amountWrapper {
/* display: flex;
flex-direction: row;
align-items: center; */
}

.setMaxAmount {
position: absolute;
right: 0px;
bottom: 30px;
cursor: pointer;
font-size: 14px;
color: var(--color-primary-medium);
font-weight: var(--font-weight-bold);
}

.fee {
text-align: right;
margin-bottom: 24px;
Expand Down
54 changes: 45 additions & 9 deletions src/components/send/steps/form/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,35 @@ class Form extends React.Component {
return fromRawLsk(Math.max(0, this.props.account.balance - this.fee));
}

handleSetMaxAmount() {
const amount = parseFloat(this.getMaxAmount());
this.setState({
amount: {
value: amount.toString(),
},
});
}

focusReference() {
this.referenceInput.focus();
}

handleFocus() {
this.setState({
showSetMaxAmount: true,
});
}

handleBlur() {
/* when click on set max amount link we need a small delay */
/* to process the click event before hiding */
setTimeout(() => {
this.setState({
showSetMaxAmount: false,
});
}, 200);
}

render() {
return (
<div className={`${styles.sendWrapper}`}>
Expand Down Expand Up @@ -114,15 +139,26 @@ class Form extends React.Component {
reference={this.state.reference}
handleChange={this.handleChange.bind(this, 'reference', false)}
/>
<Converter
label={this.props.t('Amount (LSK)')}
className='amount'
theme={styles}
error={this.state.amount.error}
value={this.state.amount.value}
onChange={this.handleChange.bind(this, 'amount', true)}
t={this.props.t}
/>
<div className={`amount-wrapper ${styles.amountWrapper}`}>
<Converter
label={this.props.t('Amount (LSK)')}
className='amount'
theme={styles}
error={this.state.amount.error}
value={this.state.amount.value}
onChange={this.handleChange.bind(this, 'amount', true)}
onFocus={this.handleFocus.bind(this)}
onBlur={this.handleBlur.bind(this)}
t={this.props.t}
/>
{
this.state.showSetMaxAmount &&
!this.state.amount.value &&
this.getMaxAmount() > 0 ?
<a onClick={this.handleSetMaxAmount.bind(this)} className={`set-max-amount ${styles.setMaxAmount}`}>{ this.props.t('Set max. amount') }</a>
: <div></div>
}
</div>
</form>
<footer>
<Button onClick={() => this.props.nextStep({
Expand Down
27 changes: 27 additions & 0 deletions src/components/send/steps/form/form.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { expect } from 'chai';
import { useFakeTimers } from 'sinon';
import { mount } from 'enzyme';
import thunk from 'redux-thunk';
import configureMockStore from 'redux-mock-store';
Expand All @@ -11,10 +12,15 @@ import Form from './form';
describe('Form Component', () => {
let wrapper;
let props;
let clock;

beforeEach(() => {
const account = accounts.delegate;

clock = useFakeTimers({
toFake: ['setTimeout', 'clearTimeout', 'Date', 'setInterval'],
});

const priceTicker = {
success: true,
LSK: {
Expand Down Expand Up @@ -47,6 +53,10 @@ describe('Form Component', () => {
});
});

afterEach(() => {
clock.restore();
});

it('renders three Input components', () => {
expect(wrapper.find('Input')).to.have.length(3);
});
Expand Down Expand Up @@ -117,4 +127,21 @@ describe('Form Component', () => {

expect(wrapper.find('Bookmark')).to.have.length(1);
});

it('Shows the Set max. amount link on amount focus', () => {
wrapper.find('.amount input').simulate('focus');
expect(wrapper.state('showSetMaxAmount')).to.equal(true);
});

it('Puts max amount into input field', () => {
wrapper.find('.amount input').simulate('focus');
wrapper.find('.set-max-amount').simulate('click');
expect(wrapper.state('amount').value).to.equal('999.9');
});

it('Hides the Set max. amount link on amount blur', () => {
wrapper.find('.amount input').simulate('blur');
clock.tick(1200);
expect(wrapper.state('showSetMaxAmount')).to.equal(false);
});
});

0 comments on commit a128585

Please sign in to comment.