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

Commit

Permalink
Update forging tab to show LSK with max 2 decimal places
Browse files Browse the repository at this point in the history
  • Loading branch information
slaweet committed Aug 21, 2017
1 parent bdecf90 commit 49ba5bb
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/components/forging/forgedBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ const ForgedBlocks = props => (
<TableCell><FormattedNumber val={block.height} /></TableCell>
<TableCell>{block.id}</TableCell>
<TableCell><TooltipTime label={block.timestamp} /></TableCell>
<TableCell><LiskAmount val={block.totalFee} /></TableCell>
<TableCell><LiskAmount val={block.reward} /></TableCell>
<TableCell><LiskAmount val={block.totalFee} roundTo={2} /></TableCell>
<TableCell><LiskAmount val={block.reward} roundTo={2} /></TableCell>
</TableRow>
))}
</Table>
Expand Down
1 change: 1 addition & 0 deletions src/components/forging/forgingStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class ForgingStats extends React.Component {
<span className='title'> {cardObj.label} </span>
<span>
<LiskAmount val={this.props.statistics[cardObj.key]}
roundTo={2}
/> LSK
</span>
</div>
Expand Down
8 changes: 4 additions & 4 deletions src/components/forging/forgingStats.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ describe('ForgingStats', () => {
});

it('should render Card component for Last 24 hours', () => {
expect(wrapper.find('Card').at(0).text().trim()).to.equal('Last 24 hours 0.00321317 LSK');
expect(wrapper.find('Card').at(0).text().trim()).to.equal('Last 24 hours 0 LSK');
});

it('should render Card component for Last 7 days', () => {
expect(wrapper.find('Card').at(1).text().trim()).to.equal('Last 7 days 32.13179124 LSK');
expect(wrapper.find('Card').at(1).text().trim()).to.equal('Last 7 days 32.13 LSK');
});

it('should render Card component for Last 30 days', () => {
expect(wrapper.find('Card').at(2).text().trim()).to.equal('Last 30 days 3,213.17912423 LSK');
expect(wrapper.find('Card').at(2).text().trim()).to.equal('Last 30 days 3,213.18 LSK');
});

it('should render Card component for Last 365 days', () => {
expect(wrapper.find('Card').at(3).text().trim()).to.equal('Last 365 days 321,317.91242342 LSK');
expect(wrapper.find('Card').at(3).text().trim()).to.equal('Last 365 days 321,317.91 LSK');
});
});
2 changes: 1 addition & 1 deletion src/components/forging/forgingTitle.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ForgingTitle extends React.Component {
{this.props.account.delegate.username}
</h2>
<span>
<LiskAmount val={this.props.statistics.total} /> LSK Earned
<LiskAmount val={this.props.statistics.total} roundTo={2} /> LSK Earned
</span>
</div>
</CardText>
Expand Down
13 changes: 11 additions & 2 deletions src/components/liskAmount/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ import React from 'react';
import { fromRawLsk } from '../../utils/lsk';
import FormattedNumber from '../formattedNumber';

const LiskValue = props => (<FormattedNumber val={parseFloat(fromRawLsk(props.val))} />);
const roundTo = (value, places) => {
if (!places) {
return value;
}
const x = Math.pow(10, places);
return Math.round(value * x) / x;
};

export default LiskValue;
const LiskAmount = props => (<FormattedNumber val={
roundTo(parseFloat(fromRawLsk(props.val)), props.roundTo)} />);

export default LiskAmount;

7 changes: 7 additions & 0 deletions src/components/liskAmount/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,11 @@ describe('LiskAmount', () => {
const wrapper = mount(<LiskAmount val={inputValue} />);
expect(wrapper.text()).to.be.equal(expectedValue);
});

it('should round to props.roundTo decimal places', () => {
const inputValue = '12932689.64321' * normalizeNumber;
const expectedValue = '12,932,689.64';
const wrapper = mount(<LiskAmount val={inputValue} roundTo={2} />);
expect(wrapper.text()).to.be.equal(expectedValue);
});
});

0 comments on commit 49ba5bb

Please sign in to comment.