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
// few seconds
if (syncing) {
this.shortThrottledFetch();
this.shortThrottledFetch.cancel();
return this.longThrottledFetch();
}

View File

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

View File

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

View File

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

View File

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