This repository has been archived by the owner on Apr 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
Create priced button component - Closes #583 #585
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9140892
- Create priced button. - Add unit test coverage. - Add fees to const…
reyraa 7678e16
Minor fixings
reyraa 90bfb50
Code cleanup and minor fixings
reyraa 2fd1c3d
Use calledWithExactly instead of calledWith
reyraa 49f2878
Fix the test title and remove binding
reyraa 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React from 'react'; | ||
import Button from 'react-toolbox/lib/button'; | ||
import { fromRawLsk } from '../../utils/lsk'; | ||
import styles from './pricedButton.css'; | ||
|
||
const PricedButton = ({ | ||
balance, fee, label, customClassName, onClick, disabled, | ||
}) => { | ||
const hasFunds = balance >= fee; | ||
return ( | ||
<div className='primary-button'> | ||
{ | ||
fee && | ||
(<span className={`${styles.fee} ${hasFunds ? '' : styles.error}`}> | ||
{ | ||
hasFunds ? `Fee: ${fromRawLsk(fee)} LSK` : | ||
`Insufficient funds for ${fromRawLsk(fee)} LSK fee` | ||
} | ||
</span>) | ||
} | ||
<Button | ||
label={label} | ||
primary={true} | ||
raised={true} | ||
className={`next-button ${customClassName}`} | ||
disabled={disabled || (fee && !hasFunds)} | ||
onClick={onClick} /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default PricedButton; |
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,56 @@ | ||
import React from 'react'; | ||
import chai, { expect } from 'chai'; | ||
import sinonChai from 'sinon-chai'; | ||
import sinon from 'sinon'; | ||
import { shallow } from 'enzyme'; | ||
import chaiEnzyme from 'chai-enzyme'; | ||
import Button from 'react-toolbox/lib/button'; | ||
import PricedButton from './index'; | ||
|
||
chai.use(sinonChai); | ||
chai.use(chaiEnzyme()); | ||
|
||
describe('PricedButton', () => { | ||
let wrapper; | ||
const props = { | ||
fee: 5e8, | ||
onClick: sinon.spy(), | ||
}; | ||
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 funds', () => { | ||
beforeEach(() => { | ||
wrapper = shallow(<PricedButton {...props} balance={sufficientBalance} />); | ||
}); | ||
|
||
it('renders a span saying "Fee: 5 LSK"', () => { | ||
expect(wrapper.find('span').text()).to.be.equal('Fee: 5 LSK'); | ||
}); | ||
|
||
it('allows to click on Button', () => { | ||
wrapper.find(Button).simulate('click'); | ||
expect(props.onClick).to.have.been.calledWithExactly(); | ||
}); | ||
}); | ||
|
||
describe('Insufficient funds', () => { | ||
beforeEach(() => { | ||
wrapper = shallow(<PricedButton {...props} balance={insufficientBalance} />); | ||
}); | ||
|
||
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', () => { | ||
const buttonProps = wrapper.find(Button).props(); | ||
expect(buttonProps.disabled).to.be.equal(true); | ||
}); | ||
}); | ||
}); |
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,12 @@ | ||
.fee { | ||
font-size: 12px; | ||
line-height: 14px; | ||
color: grey; | ||
text-align: right; | ||
margin: 0 16px; | ||
transition: all 0.3s cubic-bezier(0.55, 0, 0.55, 0.2); | ||
} | ||
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. Space between selectors. 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. done |
||
|
||
.error { | ||
color: #dd2c00 !important; | ||
} |
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,6 @@ | ||
export default { | ||
setSecondPassphrase: 5e8, | ||
send: 0.1e8, | ||
registerDelegate: 25e8, | ||
vote: 1e8, | ||
}; |
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.
Do you guys do this in every file?
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.
#589