From 1fca607300c4188dbd09eb5c0e6ee9f78a56fcda Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Fri, 29 May 2015 11:46:33 -0300 Subject: [PATCH 1/3] better connection error handling --- public/views/walletHome.html | 8 ++++++++ src/js/controllers/index.js | 2 +- src/js/controllers/walletHome.js | 32 ++++++++++++++++++++++---------- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/public/views/walletHome.html b/public/views/walletHome.html index 7e24a8dac..c07f831ac 100644 --- a/public/views/walletHome.html +++ b/public/views/walletHome.html @@ -214,6 +214,14 @@

My Bitcoin address

+ +
+ + {{home.addrError|translate}} + +
+ +
diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index ff69df286..75eff1ee5 100644 --- a/src/js/controllers/index.js +++ b/src/js/controllers/index.js @@ -677,7 +677,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r go.walletHome(); } else if (err && err.cors == 'rejected') { $log.debug('CORS error:', err); - } else if (err.code === 'ETIMEDOUT') { + } else if (err.code === 'ETIMEDOUT' || err.code === 'CONNERROR') { $log.debug('Time out:', err); } else { var msg = 'Error at Wallet Service: '; diff --git a/src/js/controllers/walletHome.js b/src/js/controllers/walletHome.js index 789db0e6e..7e725f2c1 100644 --- a/src/js/controllers/walletHome.js +++ b/src/js/controllers/walletHome.js @@ -91,9 +91,11 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi var parseError = function(err) { if (err.message) { + // TODO : this is not used anymore? if (err.message.indexOf('CORS') >= 0) { err.message = gettext('Could not connect wallet service. Check your Internet connexion and your wallet service configuration.'); } + if (err.message.indexOf('TIMEDOUT') >= 0) { err.message = gettext('Wallet service timed out. Check your Internet connexion and your wallet service configuration.'); } @@ -200,7 +202,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi if (err) { $scope.loading = false; parseError(err); - $scope.error = err.message || gettext('Could not sign transaction. Please try again.'); + $scope.error = err.message || gettext('Could not accept payment. Check you connection and try again'); $scope.$digest(); } else { //if txp has required signatures then broadcast it @@ -213,11 +215,15 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi $scope.loading = false; if (err) { parseError(err); - $scope.error = gettext('Could not broadcast transaction. Please try again.'); + $scope.error = gettext('Could not broadcast payment. Check you connection and try again'); $scope.$digest(); } else { + + console.log('[walletHome.js.219]'); //TODO if (memo) $log.info(memo); + + console.log('[walletHome.js.223]'); //TODO $modalInstance.close(txpsb, true); } }); @@ -240,7 +246,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi $scope.loading = false; if (err) { parseError(err); - $scope.error = err.message || gettext('Could not reject transaction. Please try again.'); + $scope.error = err.message || gettext('Could not reject payment. Check you connection and try again'); $scope.$digest(); } else { $modalInstance.close(txpr); @@ -262,7 +268,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi // Hacky: request tries to parse an empty response if (err && !(err.message && err.message.match(/Unexpected/))) { parseError(err); - $scope.error = err.message || gettext('Could not delete transaction. Please try again.'); + $scope.error = err.message || gettext('Could not delete payment proposal. Check you connection and try again'); $scope.$digest(); return; } @@ -281,7 +287,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi $scope.loading = false; if (err) { parseError(err); - $scope.error = err.message || gettext('Could not send transaction. Please try again.'); + $scope.error = err.message || gettext('Could not broadcast payment. Check you connection and try again'); $scope.$digest(); } else { @@ -333,21 +339,24 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi this.setNewAddress = function() { var fc = profileService.focusedClient; self.generatingAddress = true; + self.addrError = null; fc.createAddress(function(err, addr) { self.generatingAddress = false; if (err) { - if (err.error.match(/locked/gi)) { + if (err.error && err.error.match(/locked/gi)) { $log.debug(err.error); $timeout(function() { self.setNewAddress(); }, 5000); } else { $log.debug('Creating address ERROR:', err); - $scope.$emit('Local/ClientError', err); + parseError(err); + self.addrError = err.message || gettext('Could not create address. Check you connection and try again'); $scope.$digest(); } return; } + self.addrError = null; self.addr = addr.address; storageService.storeLastAddress(fc.credentials.walletId, addr.address, function() { @@ -358,6 +367,8 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi }; this.setAddress = function() { + self.addrError = null; + if (self.addr) return; @@ -410,7 +421,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi }; this.resetError = function() { - this.error = this.success = null; + this.error = this.success = null; }; this.bindTouchDown = function(tries) { @@ -527,9 +538,10 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi var fc = profileService.focusedClient; $log.warn(err); parseError(err); - var errMessage = 'The transaction' + (fc.credentials.m > 1 ? ' proposal' : '') + + var errMessage = + fc.credentials.m > 1 ? gettext('Could not create payment proposal') : gettext('Could not send payment'); - ' could not be created: ' + (err.message ? err.message : err); + errMessage = errMessage + '. ' + (err.message ? err.message : gettext('Check you connection and try again')); this.error = errMessage; From b32b29259a364133a523159502cd2c6ff159dcb2 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Fri, 29 May 2015 12:39:17 -0300 Subject: [PATCH 2/3] fix refreshUntilItChanges --- src/js/controllers/index.js | 12 ++++++++---- src/js/controllers/walletHome.js | 14 +++++++++----- src/js/services/notificationsService.js | 7 +++++-- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index 75eff1ee5..9378e3cfb 100644 --- a/src/js/controllers/index.js +++ b/src/js/controllers/index.js @@ -185,12 +185,12 @@ angular.module('copayApp.controllers').controller('indexController', function($r $timeout(function() { self.setOngoingProcess('updatingStatus', true); - $log.debug('Updating Status:', fc); + $log.debug('Updating Status:', fc, tries); get(function(err, walletStatus) { - if (!err && untilItChanges && initBalance == walletStatus.balance.totalAmount && tries < 10) { + if (!err && untilItChanges && initBalance == walletStatus.balance.totalAmount && tries < 7) { return $timeout(function() { return self.updateAll(null, true, initBalance, ++tries); - }, 1000); + }, 1400 * tries); } self.setOngoingProcess('updatingStatus', false); if (err) { @@ -709,7 +709,11 @@ angular.module('copayApp.controllers').controller('indexController', function($r }, 5000); }); - lodash.each(['NewOutgoingTx', 'NewTxProposal', 'TxProposalFinallyRejected', 'TxProposalRemoved', + $rootScope.$on('NewOutgoingTx', function() { + self.updateAll(null, true); + }); + + lodash.each(['NewTxProposal', 'TxProposalFinallyRejected', 'TxProposalRemoved', 'Local/NewTxProposal', 'Local/TxProposalAction', 'ScanFinished' ], function(eventName) { $rootScope.$on(eventName, function(event, untilItChanges) { diff --git a/src/js/controllers/walletHome.js b/src/js/controllers/walletHome.js index 7e725f2c1..93f0e2795 100644 --- a/src/js/controllers/walletHome.js +++ b/src/js/controllers/walletHome.js @@ -223,8 +223,8 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi if (memo) $log.info(memo); - console.log('[walletHome.js.223]'); //TODO - $modalInstance.close(txpsb, true); + txpsb.refreshUntilItChanges = true; + $modalInstance.close(txpsb); } }); } else { @@ -293,7 +293,9 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi if (memo) $log.info(memo); - $modalInstance.close(txpb, true); + + txpb.refreshUntilItChanges = true; + $modalInstance.close(txpb); } }); }, 100); @@ -320,7 +322,9 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi m.addClass('slideOutRight'); }); - modalInstance.result.then(function(txp, refreshUntilItChanges) { + 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() { @@ -421,7 +425,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi }; this.resetError = function() { - this.error = this.success = null; + this.error = this.success = null; }; this.bindTouchDown = function(tries) { diff --git a/src/js/services/notificationsService.js b/src/js/services/notificationsService.js index 986ed3e24..029d2d2ca 100644 --- a/src/js/services/notificationsService.js +++ b/src/js/services/notificationsService.js @@ -15,6 +15,10 @@ angular.module('copayApp.services') }; root.storeLast = function(notificationData, walletId) { + + if (notificationData.type == 'NewAddress') + return; + lastNotificationOnWallet[walletId] = { creatorId: notificationData.creatorId, type: notificationData.type, @@ -38,7 +42,6 @@ angular.module('copayApp.services') && notificationData.type === 'TxProposalFinallyRejected') return true; - return false; }; @@ -73,7 +76,7 @@ angular.module('copayApp.services') name, {color: color} ); break; case 'NewOutgoingTx': - notification.sent(gettext('Payment Proposal Sent'), + notification.sent(gettext('Payment Sent'), name, {color: color} ); break; case 'NewIncomingTx': From a13bfa84c27fb02d6c43eda0a6f4aeb58a45f230 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Fri, 29 May 2015 12:41:10 -0300 Subject: [PATCH 3/3] update bower --- bower.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bower.json b/bower.json index abfa19ab7..f0e923bbd 100644 --- a/bower.json +++ b/bower.json @@ -17,7 +17,7 @@ "ng-lodash": "~0.2.0", "angular-moment": "~0.10.1", "moment": "~2.10.3", - "angular-bitcore-wallet-client": "^0.0.23", + "angular-bitcore-wallet-client": "^0.0.24", "angular-ui-router": "~0.2.13", "qrcode-decoder-js": "*", "fastclick": "*",