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

Commit

Permalink
Code cleanup and minor fixings
Browse files Browse the repository at this point in the history
  • Loading branch information
reyraa committed Aug 9, 2017
1 parent 7678e16 commit 90bfb50
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
28 changes: 16 additions & 12 deletions src/components/pricedButton/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,28 @@ import Button from 'react-toolbox/lib/button';
import { fromRawLsk } from '../../utils/lsk';
import styles from './pricedButton.css';

const PricedButton = (props) => {
const hasFunds = props.balance >= props.fee;
const PricedButton = ({
balance, fee, label, customClassName, onClick, disabled,
}) => {
const hasFunds = balance >= fee;
return (
<div className='primary-button'>
{
props.fee &&
<span className={`${styles.fee} ${hasFunds ? '' : styles.error}`}>
fee &&
(<span className={`${styles.fee} ${hasFunds ? '' : styles.error}`}>
{
hasFunds ? `Fee: ${fromRawLsk(props.fee)} LSK` :
`Not enough credit to pay ${fromRawLsk(props.fee)} LSK fee`
hasFunds ? `Fee: ${fromRawLsk(fee)} LSK` :
`Insufficient funds for ${fromRawLsk(fee)} LSK fee`
}
</span>
</span>)
}
<Button label={props.label}
primary={true} raised={true}
className={`next-button ${props.customClassName}`}
disabled={props.disabled || (props.fee && !hasFunds)}
onClick={props.onClick.bind(this)}/>
<Button
label={label}
primary={true}
raised={true}
className={`next-button ${customClassName}`}
disabled={disabled || (fee && !hasFunds)}
onClick={onClick.bind(this)} />
</div>
);
};
Expand Down
10 changes: 5 additions & 5 deletions src/components/pricedButton/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ describe('DialogElement', () => {
fee: 5e8,
onClick: sinon.spy(),
};
const insufficientBalance = 0;
const insufficientBalance = 4.9999e8;
const sufficientBalance = 6e8;

it('renders <Button /> component from react-toolbox', () => {
wrapper = shallow(<PricedButton {...props} balance={sufficientBalance} />);
expect(wrapper.find(Button)).to.have.length(1);
});

describe('Sufficient credit', () => {
describe('Sufficient funds', () => {
beforeEach(() => {
wrapper = shallow(<PricedButton {...props} balance={sufficientBalance} />);
});
Expand All @@ -39,13 +39,13 @@ describe('DialogElement', () => {
});
});

describe('Insufficient credit', () => {
describe('Insufficient funds', () => {
beforeEach(() => {
wrapper = shallow(<PricedButton {...props} balance={insufficientBalance} />);
});

it('renders a span saying "Not enough credit to pay 5 LSK fee"', () => {
expect(wrapper.find('span').text()).to.be.equal('Not enough credit to pay 5 LSK fee');
it('renders a span saying "Insufficient funds for 5 LSK fee"', () => {
expect(wrapper.find('span').text()).to.be.equal('Insufficient funds for 5 LSK fee');
});

it('sets the disabled attribute of the button', () => {
Expand Down
1 change: 1 addition & 0 deletions src/components/pricedButton/pricedButton.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
margin: 0 16px;
transition: all 0.3s cubic-bezier(0.55, 0, 0.55, 0.2);
}

.error {
color: #dd2c00 !important;
}

0 comments on commit 90bfb50

Please sign in to comment.