fix refresh

This commit is contained in:
Matias Alejo Garcia 2015-05-30 22:38:08 -03:00
commit 0e300c946a
3 changed files with 17 additions and 25 deletions

View file

@ -297,7 +297,7 @@
</span> </span>
<span class="text-gray" > <span class="text-gray" >
{{index.lockedBalanceStr}} {{index.lockedBalanceStr}}
<span translate>in pending payments</span> <span translate>locked by pending payments</span>
</span> </span>
</div> </div>
</div> </div>

View file

@ -159,29 +159,20 @@ angular.module('copayApp.controllers').controller('indexController', function($r
}; };
var _walletStatusHash = function(walletStatus) { var _walletStatusHash = function(walletStatus) {
var st = {}; var bal;
if (walletStatus) { if (walletStatus) {
st.bal = walletStatus.balance.totalAmount; bal = walletStatus.balance.totalAmount;
st.txs = walletStatus.pendingTxps;
} else { } else {
st.bal = self.totalBalanceSat; bal = self.totalBalanceSat;
st.txs = self.txps;
} }
return bal;
var hash = st.bal + ':';
if (st.txs) {
hash += lodash.map(st.txs, function(t) {
return t.id + ':' + (t.actions ? t.actions.length : 0);
}).join(':');
}
return hash;
}; };
self.updateAll = function(walletStatus, untilItChanges, initStatusHash, tries) { self.updateAll = function(walletStatus, untilItChanges, initStatusHash, tries) {
tries = tries || 0; tries = tries || 0;
if (untilItChanges && lodash.isUndefined(initStatusHash)) { if (untilItChanges && lodash.isUndefined(initStatusHash)) {
initStatusHash = _walletStatusHash(); initStatusHash = _walletStatusHash();
$log.debug('Updating status until it changes. initStatusHash:' + initStatusHash)
} }
var get = function(cb) { var get = function(cb) {
if (walletStatus) if (walletStatus)
@ -206,8 +197,11 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.setOngoingProcess('updatingStatus', true); self.setOngoingProcess('updatingStatus', true);
$log.debug('Updating Status:', fc, tries); $log.debug('Updating Status:', fc, tries);
get(function(err, walletStatus) { get(function(err, walletStatus) {
if (!err && untilItChanges && initStatusHash == _walletStatusHash(walletStatus) && tries < 7) { var currentStatusHash = _walletStatusHash(walletStatus);
$log.debug('Status update. hash:' + currentStatusHash + ' Try:'+ tries);
if (!err && untilItChanges && initStatusHash == currentStatusHash && tries < 7) {
return $timeout(function() { return $timeout(function() {
$log.debug('Retrying update... Try:' + tries)
return self.updateAll(null, true, initStatusHash, ++tries); return self.updateAll(null, true, initStatusHash, ++tries);
}, 1400 * tries); }, 1400 * tries);
} }

View file

@ -127,6 +127,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
this.openTxpModal = function(tx, copayers) { this.openTxpModal = function(tx, copayers) {
var fc = profileService.focusedClient; var fc = profileService.focusedClient;
var refreshUntilItChanges = false;
var ModalInstanceCtrl = function($scope, $modalInstance) { var ModalInstanceCtrl = function($scope, $modalInstance) {
$scope.error = null; $scope.error = null;
$scope.tx = tx; $scope.tx = tx;
@ -136,7 +137,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
$scope.copayerId = fc.credentials.copayerId; $scope.copayerId = fc.credentials.copayerId;
$scope.loading = null; $scope.loading = null;
$scope.color = fc.backgroundColor; $scope.color = fc.backgroundColor;
$scope.refreshUntilItChanges = false; refreshUntilItChanges = false;
$scope.getShortNetworkName = function() { $scope.getShortNetworkName = function() {
return fc.credentials.networkName.substring(0, 4); return fc.credentials.networkName.substring(0, 4);
@ -219,12 +220,11 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
$scope.error = gettext('Could not broadcast payment. Check you connection and try again'); $scope.error = gettext('Could not broadcast payment. Check you connection and try again');
$scope.$digest(); $scope.$digest();
} else { } else {
$log.debug('Transaction signed and broadcasted')
console.log('[walletHome.js.219]'); //TODO
if (memo) if (memo)
$log.info(memo); $log.info(memo);
$scope.refreshUntilItChanges = true; refreshUntilItChanges = true;
$modalInstance.close(txpsb); $modalInstance.close(txpsb);
} }
}); });
@ -250,7 +250,6 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
$scope.error = err.message || gettext('Could not reject payment. Check you connection and try again'); $scope.error = err.message || gettext('Could not reject payment. Check you connection and try again');
$scope.$digest(); $scope.$digest();
} else { } else {
$scope.refreshUntilItChanges = true;
$modalInstance.close(txpr); $modalInstance.close(txpr);
} }
}); });
@ -274,7 +273,6 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
$scope.$digest(); $scope.$digest();
return; return;
} }
$scope.refreshUntilItChanges = true;
$modalInstance.close(); $modalInstance.close();
}); });
}, 100); }, 100);
@ -297,7 +295,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
if (memo) if (memo)
$log.info(memo); $log.info(memo);
$scope.refreshUntilItChanges = true; refreshUntilItChanges = true;
$modalInstance.close(txpb); $modalInstance.close(txpb);
} }
}); });
@ -329,11 +327,11 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
self.setOngoingProcess(); self.setOngoingProcess();
if (txp) { if (txp) {
txStatus.notify(txp, function() { txStatus.notify(txp, function() {
$scope.$emit('Local/TxProposalAction', $scope.refreshUntilItChanges); $scope.$emit('Local/TxProposalAction', refreshUntilItChanges);
}); });
} else { } else {
$timeout(function() { $timeout(function() {
$scope.$emit('Local/TxProposalAction', $scope.refreshUntilItChanges); $scope.$emit('Local/TxProposalAction', refreshUntilItChanges);
}, 100); }, 100);
} }
}); });