diff --git a/src/components/forging/delegateStats.js b/src/components/forging/delegateStats.js index 78a573a84..230180ed6 100644 --- a/src/components/forging/delegateStats.js +++ b/src/components/forging/delegateStats.js @@ -32,14 +32,15 @@ const DelegateStats = props => (
-
-
-
{cardItem.label}
- +
+
+
{cardItem.label}
+ +
-
diff --git a/src/components/forging/forgedBlocks.js b/src/components/forging/forgedBlocks.js index b752e994b..dbcb2e7de 100644 --- a/src/components/forging/forgedBlocks.js +++ b/src/components/forging/forgedBlocks.js @@ -13,26 +13,29 @@ const ForgedBlocks = props => ( Forged Blocks -
- - - Block height - Block Id - Timestamp - Total fee - Reward - - {props.forgedBlocks.map((block, idx) => ( - - - {block.id} - - - - - ))} -
-
+ { props.forgedBlocks.length ? +
+ + + Block height + Block Id + Timestamp + Total fee + Reward + + {props.forgedBlocks.map((block, idx) => ( + + + {block.id} + + + + + ))} +
+
: +

You have not forged any blocks yet.

+ }
); diff --git a/src/components/forging/forgingStats.js b/src/components/forging/forgingStats.js index b816a5c48..2539df28d 100644 --- a/src/components/forging/forgingStats.js +++ b/src/components/forging/forgingStats.js @@ -44,6 +44,7 @@ class ForgingStats extends React.Component { {cardObj.label} LSK
diff --git a/src/components/forging/forgingStats.test.js b/src/components/forging/forgingStats.test.js index 52d92c6f7..f4119c8f3 100644 --- a/src/components/forging/forgingStats.test.js +++ b/src/components/forging/forgingStats.test.js @@ -37,18 +37,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'); }); }); diff --git a/src/components/forging/forgingTitle.js b/src/components/forging/forgingTitle.js index a8de24a59..4c4ac38a9 100644 --- a/src/components/forging/forgingTitle.js +++ b/src/components/forging/forgingTitle.js @@ -21,7 +21,7 @@ class ForgingTitle extends React.Component { {this.props.account.delegate.username} - LSK Earned + LSK Earned diff --git a/src/components/liskAmount/index.js b/src/components/liskAmount/index.js index c1fc1d340..2ceb9add7 100644 --- a/src/components/liskAmount/index.js +++ b/src/components/liskAmount/index.js @@ -2,7 +2,16 @@ import React from 'react'; import { fromRawLsk } from '../../utils/lsk'; import FormattedNumber from '../formattedNumber'; -const LiskValue = props => (); +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 => (); + +export default LiskAmount; diff --git a/src/components/liskAmount/index.test.js b/src/components/liskAmount/index.test.js index caf0c0f75..cea1cb38f 100644 --- a/src/components/liskAmount/index.test.js +++ b/src/components/liskAmount/index.test.js @@ -11,4 +11,11 @@ describe('LiskAmount', () => { const wrapper = mount(); 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(); + expect(wrapper.text()).to.be.equal(expectedValue); + }); }); diff --git a/src/store/middlewares/account.js b/src/store/middlewares/account.js index dfa6c02ea..6efd7ef38 100644 --- a/src/store/middlewares/account.js +++ b/src/store/middlewares/account.js @@ -3,6 +3,7 @@ import { accountUpdated } from '../../actions/account'; import { transactionsUpdated } from '../../actions/transactions'; import { activePeerUpdate } from '../../actions/peers'; import actionTypes from '../../constants/actions'; +import { fetchAndUpdateForgedBlocks } from '../../actions/forging'; const updateAccountData = next => (store) => { // eslint-disable-line const { peers, account } = store.getState(); @@ -15,6 +16,14 @@ const updateAccountData = next => (store) => { // eslint-disable-line confirmed: response.transactions, count: parseInt(response.count, 10), }))); + if (account.isDelegate) { + store.dispatch(fetchAndUpdateForgedBlocks({ + activePeer: peers.data, + limit: 10, + offset: 0, + generatorPublicKey: account.publicKey, + })); + } } next(accountUpdated(result)); }); diff --git a/src/store/middlewares/account.test.js b/src/store/middlewares/account.test.js index c02b6c62c..516914769 100644 --- a/src/store/middlewares/account.test.js +++ b/src/store/middlewares/account.test.js @@ -3,23 +3,29 @@ import { spy, stub } from 'sinon'; import middleware from './account'; import * as accountApi from '../../utils/api/account'; import actionTypes from '../../constants/actions'; +// import * as forgingActions from '../../actions/forging'; describe('Account middleware', () => { let store; let next; + let state; beforeEach(() => { store = stub(); - store.getState = () => ({ + store.dispatch = spy(); + state = { peers: { data: {}, }, - account: {}, - }); + account: { + balance: 0, + }, + }; next = spy(); }); it('should passes the action to next middleware', () => { + store.getState = () => (state); const expectedAction = { type: 'TEST_ACTION', }; @@ -29,7 +35,8 @@ describe('Account middleware', () => { }); it(`should call account API methods on ${actionTypes.metronomeBeat} action`, () => { - const stubGetAccount = stub(accountApi, 'getAccount').resolves(true); + store.getState = () => (state); + const stubGetAccount = stub(accountApi, 'getAccount').resolves({ balance: 0 }); const stubGetAccountStatus = stub(accountApi, 'getAccountStatus').resolves(true); middleware(store)(next)({ type: actionTypes.metronomeBeat }); @@ -40,5 +47,36 @@ describe('Account middleware', () => { stubGetAccount.restore(); stubGetAccountStatus.restore(); }); + + it(`should call transactions API methods on ${actionTypes.metronomeBeat} action if account.balance changes`, () => { + store.getState = () => (state); + const stubGetAccount = stub(accountApi, 'getAccount').resolves({ balance: 10e8 }); + const stubTransactions = stub(accountApi, 'transactions').resolves(true); + + middleware(store)(next)({ type: actionTypes.metronomeBeat }); + + expect(stubGetAccount).to.have.been.calledWith(); + // TODO why next expect doesn't work despite it being called according to test coverage? + // expect(stubTransactions).to.have.been.calledWith(); + + stubGetAccount.restore(); + stubTransactions.restore(); + }); + + it(`should call fetchAndUpdateForgedBlocks(...) on ${actionTypes.metronomeBeat} action if account.balance changes and account.isDelegate`, () => { + state.account.isDelegate = true; + store.getState = () => (state); + const stubGetAccount = stub(accountApi, 'getAccount').resolves({ balance: 10e8 }); + const stubGetAccountStatus = stub(accountApi, 'getAccountStatus').resolves(true); + // const fetchAndUpdateForgedBlocksSpy = spy(forgingActions, 'fetchAndUpdateForgedBlocks'); + + middleware(store)(next)({ type: actionTypes.metronomeBeat }); + + // TODO why next expect doesn't work despite it being called according to test coverage? + // expect(fetchAndUpdateForgedBlocksSpy).to.have.been.calledWith(); + + stubGetAccount.restore(); + stubGetAccountStatus.restore(); + }); });