From e9d90d16fa69a79c66f354280218148b2e829270 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sat, 30 May 2015 14:28:18 -0300 Subject: [PATCH] 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); } });