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

Commit

Permalink
Refetch transactions only if there are some recent ones
Browse files Browse the repository at this point in the history
  • Loading branch information
slaweet committed Sep 14, 2017
1 parent 2da347e commit 6d5e7a8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/store/middlewares/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@ const updateTransactions = (store, peers, account) => {
})));
};

const hasRecentTransactions = state => (
state.transactions.confirmed.filter(tx => tx.confirmations < 1000).length !== 0 ||
state.transactions.pending.length !== 0
);

const updateAccountData = (store, action) => { // eslint-disable-line
const { peers, account } = store.getState();
const state = store.getState();
const { peers, account } = state;

getAccount(peers.data, account.address).then((result) => {
if (action.data.interval === SYNC_ACTIVE_INTERVAL) {
if (action.data.interval === SYNC_ACTIVE_INTERVAL && hasRecentTransactions(state)) {
updateTransactions(store, peers, account);
}
if (result.balance !== account.balance) {
Expand Down
8 changes: 7 additions & 1 deletion src/store/middlewares/account.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ describe('Account middleware', () => {
account: {
balance: 0,
},
transactions: {
pending: [{
id: 12498250891724098,
}],
confirmed: [],
},
};
store.getState = () => (state);

Expand Down Expand Up @@ -103,7 +109,7 @@ describe('Account middleware', () => {
// expect(stubTransactions).to.have.been.calledWith();
});

it(`should call transactions API methods on ${actionTypes.metronomeBeat} action if action.data.interval is SYNC_ACTIVE_INTERVAL`, () => {
it(`should call transactions API methods on ${actionTypes.metronomeBeat} action if action.data.interval is SYNC_ACTIVE_INTERVAL and there are recent transactions`, () => {
stubGetAccount.resolves({ balance: 0 });

middleware(store)(next)(activeBeatAction);
Expand Down

0 comments on commit 6d5e7a8

Please sign in to comment.