From e01d6e96520485ff324293d4cd84fb166f887382 Mon Sep 17 00:00:00 2001 From: Gina Contrino Date: Wed, 22 Nov 2017 14:17:04 +0100 Subject: [PATCH 1/3] Fix transaction update problem --- src/store/middlewares/account.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/store/middlewares/account.js b/src/store/middlewares/account.js index 6f749dcbe..8e7c7fcb6 100644 --- a/src/store/middlewares/account.js +++ b/src/store/middlewares/account.js @@ -23,11 +23,11 @@ const hasRecentTransactions = txs => ( ); const updateAccountData = (store, action) => { - const { peers, account } = store.getState(); + const { peers, account, transactions } = store.getState(); getAccount(peers.data, account.address).then((result) => { if (result.balance !== account.balance) { - if (!action.data.windowIsFocused) { + if (!action.data.windowIsFocused || transactions.count === 0) { updateTransactions(store, peers, account); } if (account.isDelegate) { From 6d7ed4fde3de793c3a3cfb8d5ddba23bbe871be4 Mon Sep 17 00:00:00 2001 From: Gina Contrino Date: Wed, 22 Nov 2017 14:52:24 +0100 Subject: [PATCH 2/3] Add test --- src/store/middlewares/account.test.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/store/middlewares/account.test.js b/src/store/middlewares/account.test.js index 7cb85dc4d..00d666fd4 100644 --- a/src/store/middlewares/account.test.js +++ b/src/store/middlewares/account.test.js @@ -119,6 +119,17 @@ describe('Account middleware', () => { expect(stubTransactions).to.have.been.calledWith(); }); + it(`should call transactions API methods on ${actionTypes.newBlockCreated} action if account.balance changes the user has no transactions yet`, () => { + stubGetAccount.resolves({ balance: 10e8 }); + + state.transactions.count = 0; + middleware(store)(next)(newBlockCreated); + + expect(stubGetAccount).to.have.been.calledWith(); + // eslint-disable-next-line no-unused-expressions + expect(stubTransactions).to.have.been.calledTwice; + }); + it(`should call transactions API methods on ${actionTypes.newBlockCreated} action if the window is in focus and there are recent transactions`, () => { stubGetAccount.resolves({ balance: 0 }); From f71bee12b636b80edf1c46021bb95c9348382b3d Mon Sep 17 00:00:00 2001 From: Gina Contrino Date: Wed, 22 Nov 2017 15:22:16 +0100 Subject: [PATCH 3/3] Add little correction --- src/store/middlewares/account.js | 2 +- src/store/middlewares/account.test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/store/middlewares/account.js b/src/store/middlewares/account.js index 8e7c7fcb6..931d26214 100644 --- a/src/store/middlewares/account.js +++ b/src/store/middlewares/account.js @@ -27,7 +27,7 @@ const updateAccountData = (store, action) => { getAccount(peers.data, account.address).then((result) => { if (result.balance !== account.balance) { - if (!action.data.windowIsFocused || transactions.count === 0) { + if (!action.data.windowIsFocused || !hasRecentTransactions(transactions)) { updateTransactions(store, peers, account); } if (account.isDelegate) { diff --git a/src/store/middlewares/account.test.js b/src/store/middlewares/account.test.js index 00d666fd4..a2b795fb7 100644 --- a/src/store/middlewares/account.test.js +++ b/src/store/middlewares/account.test.js @@ -127,7 +127,7 @@ describe('Account middleware', () => { expect(stubGetAccount).to.have.been.calledWith(); // eslint-disable-next-line no-unused-expressions - expect(stubTransactions).to.have.been.calledTwice; + expect(stubTransactions).to.have.been.calledOnce; }); it(`should call transactions API methods on ${actionTypes.newBlockCreated} action if the window is in focus and there are recent transactions`, () => {