Fix balances update (#4077)

* Fix balances fetching

* Fix fetching balances while syncing
This commit is contained in:
Nicolas Gotchac 2017-01-09 11:15:00 +01:00 committed by Gav Wood
parent 40f0ee004f
commit e1847442cc
5 changed files with 8 additions and 10 deletions

View File

@ -86,7 +86,7 @@ export default class Balances {
// If syncing, only retrieve balances once every // If syncing, only retrieve balances once every
// few seconds // few seconds
if (syncing) { if (syncing) {
this.shortThrottledFetch(); this.shortThrottledFetch.cancel();
return this.longThrottledFetch(); return this.longThrottledFetch();
} }

View File

@ -173,18 +173,15 @@ export function fetchTokens (_tokenIds) {
export function fetchBalances (_addresses) { export function fetchBalances (_addresses) {
return (dispatch, getState) => { return (dispatch, getState) => {
const { api, personal } = getState(); const { api, personal } = getState();
const { visibleAccounts, accountsInfo } = personal; const { visibleAccounts, accounts } = personal;
const addresses = uniq((_addresses || visibleAccounts || []).concat(Object.keys(accountsInfo))); const addresses = uniq(_addresses || visibleAccounts || []);
if (addresses.length === 0) {
return Promise.resolve();
}
// With only a single account, more info will be displayed. // With only a single account, more info will be displayed.
const fullFetch = addresses.length === 1; const fullFetch = addresses.length === 1;
const addressesToFetch = uniq(addresses); // Add accounts addresses (for notifications, accounts selection, etc.)
const addressesToFetch = uniq(addresses.concat(Object.keys(accounts)));
return Promise return Promise
.all(addressesToFetch.map((addr) => fetchAccount(addr, api, fullFetch))) .all(addressesToFetch.map((addr) => fetchAccount(addr, api, fullFetch)))

View File

@ -218,6 +218,7 @@ export default class CertificationsMiddleware {
const _addresses = action.addresses || []; const _addresses = action.addresses || [];
addresses = uniq(addresses.concat(_addresses)); addresses = uniq(addresses.concat(_addresses));
fetchConfirmedEvents(); fetchConfirmedEvents();
next(action);
break; break;
default: default:

View File

@ -122,7 +122,7 @@ export function setVisibleAccounts (addresses) {
return; return;
} }
dispatch(fetchBalances(addresses));
dispatch(_setVisibleAccounts(addresses)); dispatch(_setVisibleAccounts(addresses));
dispatch(fetchBalances(addresses));
}; };
} }

View File

@ -47,7 +47,7 @@ export default handleActions({
setVisibleAccounts (state, action) { setVisibleAccounts (state, action) {
const addresses = (action.addresses || []).sort(); const addresses = (action.addresses || []).sort();
if (isEqual(addresses, state.addresses)) { if (isEqual(addresses, state.visibleAccounts)) {
return state; return state;
} }