Merge pull request #2799 from matiu/bug/broadcast-fail

better handling of sign/broadcast fail
This commit is contained in:
Gustavo Maximiliano Cortez 2015-05-30 23:07:33 -03:00
commit 55585f0a94
3 changed files with 41 additions and 25 deletions

View File

@ -278,7 +278,7 @@
<div>
<h4 class="title m0">
<div ng-show="!index.lockedBalance">
<div ng-show="!index.lockedBalance && index.availableBalanceStr">
<div class="size-12">
<span class="db text-bold">
<span translate>Available Balance</span>:
@ -297,7 +297,7 @@
</span>
<span class="text-gray" >
{{index.lockedBalanceStr}}
<span translate>in pending payments</span>
<span translate>locked by pending payments</span>
</span>
</div>
</div>

View File

@ -75,6 +75,9 @@ angular.module('copayApp.controllers').controller('indexController', function($r
// Clean status
self.lockedBalance = null;
self.availableBalanceStr = null;
self.totalBalanceStr = null;
self.lockedBalanceStr = null;
self.totalBalanceStr = null;
self.alternativeBalanceAvailable = false;
self.totalBalanceAlternative = null;
@ -82,7 +85,6 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.txHistory = [];
self.txHistoryPaging = false;
self.pendingTxProposalsCountForUs = null;
$timeout(function() {
self.hasProfile = true;
self.noFocusedWallet = false;
@ -158,11 +160,21 @@ angular.module('copayApp.controllers').controller('indexController', function($r
});
};
var _walletStatusHash = function(walletStatus) {
var bal;
if (walletStatus) {
bal = walletStatus.balance.totalAmount;
} else {
bal = self.totalBalanceSat;
}
return bal;
};
self.updateAll = function(walletStatus, untilItChanges, initBalance, tries) {
self.updateAll = function(walletStatus, untilItChanges, initStatusHash, tries) {
tries = tries || 0;
if (untilItChanges && lodash.isUndefined(initBalance)) {
initBalance = self.totalBalanceSat;
if (untilItChanges && lodash.isUndefined(initStatusHash)) {
initStatusHash = _walletStatusHash();
$log.debug('Updating status until it changes. initStatusHash:' + initStatusHash)
}
var get = function(cb) {
if (walletStatus)
@ -187,9 +199,12 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.setOngoingProcess('updatingStatus', true);
$log.debug('Updating Status:', fc, tries);
get(function(err, walletStatus) {
if (!err && untilItChanges && initBalance == walletStatus.balance.totalAmount && 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 self.updateAll(null, true, initBalance, ++tries);
$log.debug('Retrying update... Try:' + tries)
return self.updateAll(null, true, initStatusHash, ++tries);
}, 1400 * tries);
}
self.setOngoingProcess('updatingStatus', false);

View File

@ -127,6 +127,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
this.openTxpModal = function(tx, copayers) {
var fc = profileService.focusedClient;
var refreshUntilItChanges = false;
var ModalInstanceCtrl = function($scope, $modalInstance) {
$scope.error = null;
$scope.tx = tx;
@ -136,6 +137,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
$scope.copayerId = fc.credentials.copayerId;
$scope.loading = null;
$scope.color = fc.backgroundColor;
refreshUntilItChanges = false;
$scope.getShortNetworkName = function() {
return fc.credentials.networkName.substring(0, 4);
@ -218,12 +220,11 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
$scope.error = gettext('Could not broadcast payment. Check you connection and try again');
$scope.$digest();
} else {
console.log('[walletHome.js.219]'); //TODO
$log.debug('Transaction signed and broadcasted')
if (memo)
$log.info(memo);
txpsb.refreshUntilItChanges = true;
refreshUntilItChanges = true;
$modalInstance.close(txpsb);
}
});
@ -294,7 +295,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
if (memo)
$log.info(memo);
txpb.refreshUntilItChanges = true;
refreshUntilItChanges = true;
$modalInstance.close(txpb);
}
});
@ -323,8 +324,6 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
});
modalInstance.result.then(function(txp) {
var refreshUntilItChanges = txp.refreshUntilItChanges;
console.log('[walletHome.js.323:refreshUntilItChanges:]', refreshUntilItChanges); //TODO
self.setOngoingProcess();
if (txp) {
txStatus.notify(txp, function() {
@ -332,7 +331,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
});
} else {
$timeout(function() {
$scope.$emit('Local/TxProposalAction');
$scope.$emit('Local/TxProposalAction', refreshUntilItChanges);
}, 100);
}
});
@ -614,12 +613,16 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
}
self.signAndBroadcast(txp, function(err) {
if (err) {
self.setOngoingProcess();
return self.setSendError(err);
}
self.setOngoingProcess();
profileService.lockFC();
self.resetForm();
if (err) {
self.error = err.message ? err.message : gettext('The payment was created but could not be completed. Please try again from home screen');
$scope.$emit('Local/TxProposalAction');
$timeout(function() {
$scope.$digest();
}, 1);
}
});
});
}, 100);
@ -631,20 +634,18 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
self.setOngoingProcess(gettext('Signing transaction'));
fc.signTxProposal(txp, function(err, signedTx) {
profileService.lockFC();
self.setOngoingProcess();
if (err) {
self.setOngoingProcess();
err.message = gettext('The payment was created but could not be signed. Please try again from home screen.') + (err.message ? ' ' + err.message : '');
return cb(err);
}
if (signedTx.status == 'accepted') {
self.setOngoingProcess(gettext('Broadcasting transaction'));
fc.broadcastTxProposal(signedTx, function(err, btx, memo) {
self.setOngoingProcess();
if (err) {
$scope.error = gettext('Transaction not broadcasted. Please try again.');
$scope.$digest();
err.message = gettext('The payment was signed but could not be broadcasted. Please try again from home screen.') + (err.message ? ' ' + err.message : '');
return cb(err);
}
if (memo)