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

Fix transaction update problem - Closes #1002 #1004

Merged
merged 3 commits into from
Nov 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/store/middlewares/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 11 additions & 0 deletions src/store/middlewares/account.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });

Expand Down