Skip to content
This repository was 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 b49812d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 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
6 changes: 6 additions & 0 deletions 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

0 comments on commit b49812d

Please sign in to comment.