diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index 15b296667..183767817 100644 --- a/src/js/controllers/index.js +++ b/src/js/controllers/index.js @@ -57,8 +57,9 @@ angular.module('copayApp.controllers').controller('indexController', function($r isoCode: 'pt', }]; - self.setOngoingProcess = function(processName, isOn) { + self.setOngoingProcess = function(processName, isOn, quiet) { $log.debug('onGoingProcess', processName, isOn); + if (quiet) return; self[processName] = isOn; self.onGoingProcess[processName] = isOn; @@ -176,22 +177,23 @@ angular.module('copayApp.controllers').controller('indexController', function($r return bal; }; - self.updateAll = function(walletStatus, untilItChanges, initStatusHash, tries) { + self.updateAll = function(opts, initStatusHash, tries) { tries = tries || 0; - if (untilItChanges && lodash.isUndefined(initStatusHash)) { + var quiet = (opts && opts.quiet) ? true : null; + if (opts && opts.untilItChanges && lodash.isUndefined(initStatusHash)) { initStatusHash = _walletStatusHash(); $log.debug('Updating status until it changes. initStatusHash:' + initStatusHash) } var get = function(cb) { - if (walletStatus) - return cb(null, walletStatus); + if (opts && opts.walletStatus) + return cb(null, opts.walletStatus); else { self.updateError = false; return fc.getStatus(function(err, ret) { if (err) { self.updateError = true; } else { - self.setOngoingProcess('scanning', ret.wallet.scanning); + self.setOngoingProcess('scanning', ret.wallet.scanning, quiet); } return cb(err, ret); }); @@ -202,18 +204,18 @@ angular.module('copayApp.controllers').controller('indexController', function($r if (!fc) return; $timeout(function() { - self.setOngoingProcess('updatingStatus', true); + self.setOngoingProcess('updatingStatus', true, quiet); $log.debug('Updating Status:', fc, tries); get(function(err, walletStatus) { var currentStatusHash = _walletStatusHash(walletStatus); $log.debug('Status update. hash:' + currentStatusHash + ' Try:'+ tries); - if (!err && untilItChanges && initStatusHash == currentStatusHash && tries < 7) { + if (!err && (opts && opts.untilItChanges) && initStatusHash == currentStatusHash && tries < 7) { return $timeout(function() { $log.debug('Retrying update... Try:' + tries) - return self.updateAll(null, true, initStatusHash, ++tries); + return self.updateAll({walletStatus: null, untilItChanges: true}, initStatusHash, ++tries); }, 1400 * tries); } - self.setOngoingProcess('updatingStatus', false); + self.setOngoingProcess('updatingStatus', false, quiet); if (err) { self.handleError(err); return; @@ -329,7 +331,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r return; } $log.debug('Wallet Opened'); - self.updateAll(lodash.isObject(walletStatus) ? walletStatus : null); + self.updateAll(lodash.isObject(walletStatus) ? {walletStatus: walletStatus} : null); $rootScope.$apply(); }); }); @@ -634,7 +636,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r }); self.debouncedUpdate = lodash.throttle(function() { - self.updateAll(); + self.updateAll({quiet: true}); self.updateTxHistory(); }, 4000, { leading: false, @@ -730,14 +732,14 @@ angular.module('copayApp.controllers').controller('indexController', function($r }); $rootScope.$on('NewOutgoingTx', function() { - self.updateAll(null, true); + self.updateAll({walletStatus: null, untilItChanges: true}); }); lodash.each(['NewTxProposal', 'TxProposalFinallyRejected', 'TxProposalRemoved', 'Local/NewTxProposal', 'Local/TxProposalAction', 'ScanFinished' ], function(eventName) { $rootScope.$on(eventName, function(event, untilItChanges) { - self.updateAll(null, untilItChanges); + self.updateAll({walletStatus: null, untilItChanges: untilItChanges}); $timeout(function() { self.updateTxHistory(); }, 3000);