diff --git a/src/store/middlewares/account.js b/src/store/middlewares/account.js index 6f749dcbe..931d26214 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 || !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 7cb85dc4d..a2b795fb7 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.calledOnce; + }); + 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 });