From 4a1ab0eb16769497112666d2dd45dc9b77811f31 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sat, 30 May 2015 12:46:38 -0300 Subject: [PATCH 1/4] better handling of sign/broadcast fail --- src/js/controllers/walletHome.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/js/controllers/walletHome.js b/src/js/controllers/walletHome.js index 93f0e2795..5f693a56d 100644 --- a/src/js/controllers/walletHome.js +++ b/src/js/controllers/walletHome.js @@ -323,8 +323,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi }); modalInstance.result.then(function(txp) { - var refreshUntilItChanges = txp.refreshUntilItChanges; - console.log('[walletHome.js.323:refreshUntilItChanges:]', refreshUntilItChanges); //TODO + var refreshUntilItChanges = txp ? txp.refreshUntilItChanges : null; self.setOngoingProcess(); if (txp) { txStatus.notify(txp, function() { @@ -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) From e9d90d16fa69a79c66f354280218148b2e829270 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sat, 30 May 2015 14:28:18 -0300 Subject: [PATCH 2/4] handler for untilItchanges to txps --- src/js/controllers/index.js | 29 ++++++++++++++++++++++++----- src/js/controllers/walletHome.js | 12 +++++++----- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index e853b88e5..15479db48 100644 --- a/src/js/controllers/index.js +++ b/src/js/controllers/index.js @@ -158,11 +158,30 @@ angular.module('copayApp.controllers').controller('indexController', function($r }); }; + var _walletStatusHash = function(walletStatus) { + var st = {}; - self.updateAll = function(walletStatus, untilItChanges, initBalance, tries) { + if (walletStatus) { + st.bal = walletStatus.balance.totalAmount; + st.txs = walletStatus.pendingTxps; + } else { + st.bal = self.totalBalanceSat; + st.txs = self.txps; + } + + 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) { tries = tries || 0; - if (untilItChanges && lodash.isUndefined(initBalance)) { - initBalance = self.totalBalanceSat; + if (untilItChanges && lodash.isUndefined(initStatusHash)) { + initStatusHash = _walletStatusHash(); } var get = function(cb) { if (walletStatus) @@ -187,9 +206,9 @@ 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) { + if (!err && untilItChanges && initStatusHash == _walletStatusHash(walletStatus) && tries < 7) { return $timeout(function() { - return self.updateAll(null, true, initBalance, ++tries); + return self.updateAll(null, true, initStatusHash, ++tries); }, 1400 * tries); } self.setOngoingProcess('updatingStatus', false); diff --git a/src/js/controllers/walletHome.js b/src/js/controllers/walletHome.js index 5f693a56d..6b915b188 100644 --- a/src/js/controllers/walletHome.js +++ b/src/js/controllers/walletHome.js @@ -136,6 +136,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi $scope.copayerId = fc.credentials.copayerId; $scope.loading = null; $scope.color = fc.backgroundColor; + $scope.refreshUntilItChanges = false; $scope.getShortNetworkName = function() { return fc.credentials.networkName.substring(0, 4); @@ -223,7 +224,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi if (memo) $log.info(memo); - txpsb.refreshUntilItChanges = true; + $scope.refreshUntilItChanges = true; $modalInstance.close(txpsb); } }); @@ -249,6 +250,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi $scope.error = err.message || gettext('Could not reject payment. Check you connection and try again'); $scope.$digest(); } else { + $scope.refreshUntilItChanges = true; $modalInstance.close(txpr); } }); @@ -272,6 +274,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi $scope.$digest(); return; } + $scope.refreshUntilItChanges = true; $modalInstance.close(); }); }, 100); @@ -294,7 +297,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi if (memo) $log.info(memo); - txpb.refreshUntilItChanges = true; + $scope.refreshUntilItChanges = true; $modalInstance.close(txpb); } }); @@ -323,15 +326,14 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi }); modalInstance.result.then(function(txp) { - var refreshUntilItChanges = txp ? txp.refreshUntilItChanges : null; self.setOngoingProcess(); if (txp) { txStatus.notify(txp, function() { - $scope.$emit('Local/TxProposalAction', refreshUntilItChanges); + $scope.$emit('Local/TxProposalAction', $scope.refreshUntilItChanges); }); } else { $timeout(function() { - $scope.$emit('Local/TxProposalAction'); + $scope.$emit('Local/TxProposalAction', $scope.refreshUntilItChanges); }, 100); } }); From 0e300c946a54040864eb6f44324c21944a737059 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sat, 30 May 2015 22:38:08 -0300 Subject: [PATCH 3/4] fix refresh --- public/views/walletHome.html | 2 +- src/js/controllers/index.js | 24 +++++++++--------------- src/js/controllers/walletHome.js | 16 +++++++--------- 3 files changed, 17 insertions(+), 25 deletions(-) diff --git a/public/views/walletHome.html b/public/views/walletHome.html index 86c4dd3d1..a7453ec7e 100644 --- a/public/views/walletHome.html +++ b/public/views/walletHome.html @@ -297,7 +297,7 @@ {{index.lockedBalanceStr}} - in pending payments + locked by pending payments diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index 15479db48..d3e2a9bec 100644 --- a/src/js/controllers/index.js +++ b/src/js/controllers/index.js @@ -159,29 +159,20 @@ angular.module('copayApp.controllers').controller('indexController', function($r }; var _walletStatusHash = function(walletStatus) { - var st = {}; - + var bal; if (walletStatus) { - st.bal = walletStatus.balance.totalAmount; - st.txs = walletStatus.pendingTxps; + bal = walletStatus.balance.totalAmount; } else { - st.bal = self.totalBalanceSat; - st.txs = self.txps; + bal = self.totalBalanceSat; } - - 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; + return bal; }; self.updateAll = function(walletStatus, untilItChanges, initStatusHash, tries) { tries = tries || 0; if (untilItChanges && lodash.isUndefined(initStatusHash)) { initStatusHash = _walletStatusHash(); + $log.debug('Updating status until it changes. initStatusHash:' + initStatusHash) } var get = function(cb) { if (walletStatus) @@ -206,8 +197,11 @@ 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 && 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() { + $log.debug('Retrying update... Try:' + tries) return self.updateAll(null, true, initStatusHash, ++tries); }, 1400 * tries); } diff --git a/src/js/controllers/walletHome.js b/src/js/controllers/walletHome.js index 6b915b188..9666d3589 100644 --- a/src/js/controllers/walletHome.js +++ b/src/js/controllers/walletHome.js @@ -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,7 +137,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi $scope.copayerId = fc.credentials.copayerId; $scope.loading = null; $scope.color = fc.backgroundColor; - $scope.refreshUntilItChanges = false; + refreshUntilItChanges = false; $scope.getShortNetworkName = function() { 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.$digest(); } else { - - console.log('[walletHome.js.219]'); //TODO + $log.debug('Transaction signed and broadcasted') if (memo) $log.info(memo); - $scope.refreshUntilItChanges = true; + refreshUntilItChanges = true; $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.$digest(); } else { - $scope.refreshUntilItChanges = true; $modalInstance.close(txpr); } }); @@ -274,7 +273,6 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi $scope.$digest(); return; } - $scope.refreshUntilItChanges = true; $modalInstance.close(); }); }, 100); @@ -297,7 +295,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi if (memo) $log.info(memo); - $scope.refreshUntilItChanges = true; + refreshUntilItChanges = true; $modalInstance.close(txpb); } }); @@ -329,11 +327,11 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi self.setOngoingProcess(); if (txp) { txStatus.notify(txp, function() { - $scope.$emit('Local/TxProposalAction', $scope.refreshUntilItChanges); + $scope.$emit('Local/TxProposalAction', refreshUntilItChanges); }); } else { $timeout(function() { - $scope.$emit('Local/TxProposalAction', $scope.refreshUntilItChanges); + $scope.$emit('Local/TxProposalAction', refreshUntilItChanges); }, 100); } }); From 2df939ae3a4027a533c951c29b16a7916bb3029e Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sat, 30 May 2015 23:01:45 -0300 Subject: [PATCH 4/4] fix available balance --- public/views/walletHome.html | 2 +- src/js/controllers/index.js | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/public/views/walletHome.html b/public/views/walletHome.html index a7453ec7e..c890ef6da 100644 --- a/public/views/walletHome.html +++ b/public/views/walletHome.html @@ -278,7 +278,7 @@

-
+
Available Balance: diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index d3e2a9bec..710cdb6d8 100644 --- a/src/js/controllers/index.js +++ b/src/js/controllers/index.js @@ -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;