timing changes when switching wallets

This commit is contained in:
Matias Alejo Garcia 2016-02-23 11:12:49 -03:00
commit d572ddd2e9

View file

@ -286,6 +286,8 @@ angular.module('copayApp.controllers').controller('indexController', function($r
tries = tries || 0; tries = tries || 0;
opts = opts || {}; opts = opts || {};
var walletId = profileService.focusedClient.credentials.walletId
if (opts.untilItChanges && lodash.isUndefined(initStatusHash)) { if (opts.untilItChanges && lodash.isUndefined(initStatusHash)) {
initStatusHash = _walletStatusHash(); initStatusHash = _walletStatusHash();
$log.debug('Updating status until it changes. initStatusHash:' + initStatusHash) $log.debug('Updating status until it changes. initStatusHash:' + initStatusHash)
@ -312,6 +314,14 @@ angular.module('copayApp.controllers').controller('indexController', function($r
var fc = profileService.focusedClient; var fc = profileService.focusedClient;
if (!fc) return; if (!fc) return;
// If not untilItChanges...trigger history update now
if (opts.triggerTxUpdate && !opts.untilItChanges) {
$timeout(function() {
self.debounceUpdateHistory();
}, 1);
}
$timeout(function() { $timeout(function() {
if (!opts.quiet) if (!opts.quiet)
@ -321,7 +331,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
get(function(err, walletStatus) { get(function(err, walletStatus) {
var currentStatusHash = _walletStatusHash(walletStatus); var currentStatusHash = _walletStatusHash(walletStatus);
$log.debug('Status update. hash:' + currentStatusHash + ' Try:' + tries); $log.debug('Status update. hash:' + currentStatusHash + ' Try:' + tries);
if (!err && opts.untilItChanges && initStatusHash == currentStatusHash && tries < 7) { if (!err && opts.untilItChanges && initStatusHash == currentStatusHash && tries < 7 && walletId == profileService.focusedClient.credentials.walletId) {
return $timeout(function() { return $timeout(function() {
$log.debug('Retrying update... Try:' + tries) $log.debug('Retrying update... Try:' + tries)
return self.updateAll({ return self.updateAll({
@ -331,9 +341,14 @@ angular.module('copayApp.controllers').controller('indexController', function($r
}, initStatusHash, ++tries); }, initStatusHash, ++tries);
}, 1400 * tries); }, 1400 * tries);
} }
if (walletId != profileService.focusedClient.credentials.walletId)
return;
if (!opts.quiet) if (!opts.quiet)
self.setOngoingProcess('updatingStatus', false); self.setOngoingProcess('updatingStatus', false);
if (err) { if (err) {
self.handleError(err); self.handleError(err);
return; return;
@ -358,7 +373,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
$rootScope.$emit('Local/BalanceUpdated', walletStatus.balance); $rootScope.$emit('Local/BalanceUpdated', walletStatus.balance);
$rootScope.$apply(); $rootScope.$apply();
if (opts.triggerTxUpdate) { if (opts.triggerTxUpdate && opts.untilItChanges) {
$timeout(function() { $timeout(function() {
self.debounceUpdateHistory(); self.debounceUpdateHistory();
}, 1); }, 1);
@ -878,12 +893,17 @@ angular.module('copayApp.controllers').controller('indexController', function($r
var confirmedTxs = self.removeSoftConfirmedTx(txsFromLocal); var confirmedTxs = self.removeSoftConfirmedTx(txsFromLocal);
var endingTxid = confirmedTxs[0] ? confirmedTxs[0].txid : null; var endingTxid = confirmedTxs[0] ? confirmedTxs[0].txid : null;
// First update // First update
if (walletId == profileService.focusedClient.credentials.walletId) { if (walletId == profileService.focusedClient.credentials.walletId) {
self.completeHistory = txsFromLocal; self.completeHistory = txsFromLocal;
self.setCompactTxHistory(); self.setCompactTxHistory();
} }
if (historyUpdateInProgress[walletId])
return;
historyUpdateInProgress[walletId] = true;
function getNewTxs(newTxs, skip, i_cb) { function getNewTxs(newTxs, skip, i_cb) {
self.getTxsFromServer(client, skip, endingTxid, requestLimit, function(err, res, shouldContinue) { self.getTxsFromServer(client, skip, endingTxid, requestLimit, function(err, res, shouldContinue) {
@ -978,14 +998,13 @@ angular.module('copayApp.controllers').controller('indexController', function($r
if (!fc) return; if (!fc) return;
var walletId = fc.credentials.walletId; var walletId = fc.credentials.walletId;
if (!fc.isComplete() || historyUpdateInProgress[walletId]) { if (!fc.isComplete()) {
self.updatingTxHistory = historyUpdateInProgress[walletId];
return; return;
} }
$log.debug('Updating Transaction History'); $log.debug('Updating Transaction History');
self.txHistoryError = false; self.txHistoryError = false;
historyUpdateInProgress[walletId] = self.updatingTxHistory = true; self.updatingTxHistory = true;
$timeout(function() { $timeout(function() {
self.updateLocalTxHistory(fc, function(err) { self.updateLocalTxHistory(fc, function(err) {
@ -1015,7 +1034,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.throttledUpdateHistory = lodash.throttle(function() { self.throttledUpdateHistory = lodash.throttle(function() {
self.updateHistory(); self.updateHistory();
}, 10000); }, 5000);
self.showErrorPopup = function(msg, cb) { self.showErrorPopup = function(msg, cb) {
$log.warn('Showing err popup:' + msg); $log.warn('Showing err popup:' + msg);
@ -1050,9 +1069,9 @@ angular.module('copayApp.controllers').controller('indexController', function($r
}; };
self.openMenu = function() { self.openMenu = function() {
profileService.isDisclaimerAccepted(function(val){ profileService.isDisclaimerAccepted(function(val) {
if (val) go.swipe(true); if (val) go.swipe(true);
else else
$log.debug('Disclaimer not accepted, cannot open menu'); $log.debug('Disclaimer not accepted, cannot open menu');
}); });
}; };
@ -1312,7 +1331,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
quiet: true quiet: true
}); });
self.debounceUpdateHistory(); self.debounceUpdateHistory();
}, 4000, { }, 2000, {
leading: false, leading: false,
trailing: true trailing: true
}); });
@ -1465,7 +1484,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
$rootScope.$on('Local/NewFocusedWallet', function() { $rootScope.$on('Local/NewFocusedWallet', function() {
self.setUxLanguage(); self.setUxLanguage();
self.setFocusedWallet(); self.setFocusedWallet();
self.debounceUpdateHistory(); self.updateHistory();
storageService.getCleanAndScanAddresses(function(err, walletId) { storageService.getCleanAndScanAddresses(function(err, walletId) {
if (walletId && profileService.walletClients[walletId]) { if (walletId && profileService.walletClients[walletId]) {
$log.debug('Clear last address cache and Scan ', walletId); $log.debug('Clear last address cache and Scan ', walletId);