refactor quiet

This commit is contained in:
Matias Alejo Garcia 2015-06-19 15:09:15 -03:00
commit 7e23bd3406
2 changed files with 25 additions and 14 deletions

View file

@ -279,8 +279,9 @@
<h4 class="title m0"> <h4 class="title m0">
<button class="outline light-gray round tiny right m0 lh" <button class="outline light-gray round tiny right m0 lh"
ng-if="index.feeToSendMaxStr && index.availableBalance > 0 && !home.blockUx && !home.lockAmount"
ng-click="home.sendAll(index.availableMaxBalance, index.feeToSendMaxStr)" ng-click="home.sendAll(index.availableMaxBalance, index.feeToSendMaxStr)"
ng-if="index.availableBalance > 0 && !home.blockUx && !home.lockAmount" translate> Send All translate> Send All
</button> </button>
<div ng-show="!index.lockedBalance && index.availableBalanceStr"> <div ng-show="!index.lockedBalance && index.availableBalanceStr">

View file

@ -57,9 +57,8 @@ angular.module('copayApp.controllers').controller('indexController', function($r
isoCode: 'pt', isoCode: 'pt',
}]; }];
self.setOngoingProcess = function(processName, isOn, quiet) { self.setOngoingProcess = function(processName, isOn) {
$log.debug('onGoingProcess', processName, isOn); $log.debug('onGoingProcess', processName, isOn);
if (quiet) return;
self[processName] = isOn; self[processName] = isOn;
self.onGoingProcess[processName] = isOn; self.onGoingProcess[processName] = isOn;
@ -179,13 +178,14 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.updateAll = function(opts, initStatusHash, tries) { self.updateAll = function(opts, initStatusHash, tries) {
tries = tries || 0; tries = tries || 0;
var quiet = (opts && opts.quiet) ? true : null; opts = opts || {};
if (opts && 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)
} }
var get = function(cb) { var get = function(cb) {
if (opts && opts.walletStatus) if (opts.walletStatus)
return cb(null, opts.walletStatus); return cb(null, opts.walletStatus);
else { else {
self.updateError = false; self.updateError = false;
@ -193,7 +193,8 @@ angular.module('copayApp.controllers').controller('indexController', function($r
if (err) { if (err) {
self.updateError = true; self.updateError = true;
} else { } else {
self.setOngoingProcess('scanning', ret.wallet.scanning, quiet); if (!opts.quiet)
self.setOngoingProcess('scanning', ret.wallet.scanning);
} }
return cb(err, ret); return cb(err, ret);
}); });
@ -204,18 +205,23 @@ angular.module('copayApp.controllers').controller('indexController', function($r
if (!fc) return; if (!fc) return;
$timeout(function() { $timeout(function() {
self.setOngoingProcess('updatingStatus', true, quiet);
if (!opts.quiet)
self.setOngoingProcess('updatingStatus', true);
$log.debug('Updating Status:', fc, tries); $log.debug('Updating Status:', fc, tries);
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 && opts.untilItChanges) && initStatusHash == currentStatusHash && tries < 7) { if (!err && opts.untilItChanges && initStatusHash == currentStatusHash && tries < 7) {
return $timeout(function() { return $timeout(function() {
$log.debug('Retrying update... Try:' + tries) $log.debug('Retrying update... Try:' + tries)
return self.updateAll({walletStatus: null, untilItChanges: true}, initStatusHash, ++tries); return self.updateAll({walletStatus: null, untilItChanges: true}, initStatusHash, ++tries);
}, 1400 * tries); }, 1400 * tries);
} }
self.setOngoingProcess('updatingStatus', false, quiet); if (!opts.quiet)
self.setOngoingProcess('updatingStatus', false);
if (err) { if (err) {
self.handleError(err); self.handleError(err);
return; return;
@ -438,10 +444,14 @@ angular.module('copayApp.controllers').controller('indexController', function($r
// KB to send max // KB to send max
self.feePerKbSat = config.feePerKbSat || 10000; self.feePerKbSat = config.feePerKbSat || 10000;
var feeToSendMaxSat = balance.totalKbToSendMax * self.feePerKbSat; if (balance.totalKbToSendMax) {
var feeToSendMaxSat = balance.totalKbToSendMax * self.feePerKbSat;
self.availableMaxBalance = strip((self.availableBalanceSat - feeToSendMaxSat) * self.satToUnit); self.availableMaxBalance = strip((self.availableBalanceSat - feeToSendMaxSat) * self.satToUnit);
self.feeToSendMaxStr = profileService.formatAmount(feeToSendMaxSat) + ' ' + self.unitName; self.feeToSendMaxStr = profileService.formatAmount(feeToSendMaxSat) + ' ' + self.unitName;
} else {
self.feeToSendMaxStr = null;
}
//STR //STR
self.totalBalanceStr = profileService.formatAmount(self.totalBalanceSat) + ' ' + self.unitName; self.totalBalanceStr = profileService.formatAmount(self.totalBalanceSat) + ' ' + self.unitName;