From fe07348a5a48781b803cfca064f7825502931386 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Wed, 12 Aug 2015 08:57:44 -0300 Subject: [PATCH 01/10] adds errorCb, handles blocks --- src/js/controllers/create.js | 3 +++ src/js/controllers/index.js | 17 +++++++++++++++++ src/js/services/profileService.js | 19 +++++++++++++++++-- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/js/controllers/create.js b/src/js/controllers/create.js index c696d487b..8ac67f68a 100644 --- a/src/js/controllers/create.js +++ b/src/js/controllers/create.js @@ -63,6 +63,9 @@ angular.module('copayApp.controllers').controller('createController', if (err) { $log.debug(err); self.error = err; + $timeout(function() { + $rootScope.$apply(); + }); } else { go.walletHome(); diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index 0963c7a7d..50935294a 100644 --- a/src/js/controllers/index.js +++ b/src/js/controllers/index.js @@ -960,6 +960,9 @@ angular.module('copayApp.controllers').controller('indexController', function($r trailing: true }); + self.debouncedUpdateHistory = lodash.throttle(function() { + self.updateTxHistory(); + }, 60000); $rootScope.$on('Local/Resume', function(event) { $log.debug('### Resume event'); @@ -1023,6 +1026,20 @@ angular.module('copayApp.controllers').controller('indexController', function($r }); }); + + $rootScope.$on('NewBlock', function() { + if (self.pendingAmount) { + self.updateAll(); + } + + if (self.network =='testnet') { + self.debouncedUpdateHistory(); + } else { + self.updateTxHistory(); + } + }); + + $rootScope.$on('NewOutgoingTx', function() { self.updateAll({ walletStatus: null, diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index e16408c45..bbb75921c 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -12,6 +12,21 @@ angular.module('copayApp.services') return bwcService.getUtils(); }; + root.errorCb = function(err, prefix, cb) { + var body = ''; + + prefix = gettext(prefix); + if (!err || !err.code) return cb(prefix); + + switch(err.code) { + case 'CONNECTION_ERROR': + body = gettext('Network connection error'); + ;; + } + + return cb(prefix + ( body ? ': ' + body : '')); + }; + root.formatAmount = function(amount) { var config = configService.getSync().wallet.settings; if (config.unitCode == 'sat') return amount; @@ -176,7 +191,7 @@ angular.module('copayApp.services') walletClient.createWallet('Personal Wallet', 'me', 1, 1, { network: 'livenet' }, function(err) { - if (err) return cb(gettext('Error creating wallet. Check your internet connection')); + if (err) return root.errorCb(err, 'Error creating wallet', cb); var p = Profile.create({ credentials: [JSON.parse(walletClient.export())], }); @@ -198,7 +213,7 @@ angular.module('copayApp.services') walletClient.createWallet(opts.name, opts.myName || 'me', opts.m, opts.n, { network: opts.networkName }, function(err, secret) { - if (err) return cb(gettext('Error creating wallet')); + if (err) return root.errorCb(err, 'Error creating wallet', cb); root.profile.credentials.push(JSON.parse(walletClient.export())); root.setWalletClients(); From 033f7c163fcd6d47d898adbb3644170195088ea2 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Wed, 12 Aug 2015 11:08:33 -0300 Subject: [PATCH 02/10] better handing of errors + prevent joining the same wallet more that once --- public/views/walletHome.html | 2 +- src/js/controllers/index.js | 4 +- src/js/controllers/join.js | 2 +- src/js/controllers/walletHome.js | 73 +++++------------ src/js/services/addressService.js | 5 +- src/js/services/bwsError.js | 125 ++++++++++++++++++++++++++++++ src/js/services/profileService.js | 35 ++++----- 7 files changed, 167 insertions(+), 79 deletions(-) create mode 100644 src/js/services/bwsError.js diff --git a/public/views/walletHome.html b/public/views/walletHome.html index 02d459b87..12d3bcba6 100644 --- a/public/views/walletHome.html +++ b/public/views/walletHome.html @@ -76,7 +76,7 @@
- Could not update Wallet + {{index.updateError}}
diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index 50935294a..00a6c50d7 100644 --- a/src/js/controllers/index.js +++ b/src/js/controllers/index.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.controllers').controller('indexController', function($rootScope, $scope, $log, $filter, $timeout, lodash, go, profileService, configService, isCordova, rateService, storageService, addressService, gettextCatalog, gettext, amMoment, nodeWebkit, addonManager, feeService, isChromeApp) { +angular.module('copayApp.controllers').controller('indexController', function($rootScope, $scope, $log, $filter, $timeout, lodash, go, profileService, configService, isCordova, rateService, storageService, addressService, gettextCatalog, gettext, amMoment, nodeWebkit, addonManager, feeService, isChromeApp, bwsError) { var self = this; self.isCordova = isCordova; self.onGoingProcess = {}; @@ -243,7 +243,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r self.updateError = false; return fc.getStatus(function(err, ret) { if (err) { - self.updateError = true; + self.updateError = bwsError.msg(err, 'Could not update Wallet'); } else { if (!opts.quiet) self.setOngoingProcess('scanning', ret.wallet.scanning); diff --git a/src/js/controllers/join.js b/src/js/controllers/join.js index 948cfe176..1ca442f8c 100644 --- a/src/js/controllers/join.js +++ b/src/js/controllers/join.js @@ -153,7 +153,7 @@ angular.module('copayApp.controllers').controller('joinController', }, function(err) { if (err) { self.loading = false; - self.error = gettext('Could not join wallet: ') + (err.message ? err.message : err); + self.error = err; $rootScope.$apply(); return } diff --git a/src/js/controllers/walletHome.js b/src/js/controllers/walletHome.js index ff1d59536..9b19db9c2 100644 --- a/src/js/controllers/walletHome.js +++ b/src/js/controllers/walletHome.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.controllers').controller('walletHomeController', function($scope, $rootScope, $timeout, $filter, $modal, $log, notification, txStatus, isCordova, profileService, lodash, configService, rateService, storageService, bitcore, isChromeApp, gettext, gettextCatalog, nodeWebkit, addressService, feeService) { +angular.module('copayApp.controllers').controller('walletHomeController', function($scope, $rootScope, $timeout, $filter, $modal, $log, notification, txStatus, isCordova, profileService, lodash, configService, rateService, storageService, bitcore, isChromeApp, gettext, gettextCatalog, nodeWebkit, addressService, feeService, bwsError) { var self = this; $rootScope.hideMenuBar = false; @@ -94,24 +94,6 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi var cancel_msg = gettextCatalog.getString('Cancel'); var confirm_msg = gettextCatalog.getString('Confirm'); - // walletHome - - - var parseError = function(err) { - if (!err) return; - - 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 connection and your wallet service configuration.'); - } - - if (err.message.indexOf('TIMEDOUT') >= 0) { - err.message = gettext('Wallet service timed out. Check your Internet connection and your wallet service configuration.'); - } - } - }; - $scope.openCopayersModal = function(copayers, copayerId) { var fc = profileService.focusedClient; @@ -152,13 +134,14 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi }); addressService.getAddress(walletId, false, function(err, addr) { $scope.gettingAddress = false; - if (!err || addr) - $modalInstance.close(addr); - else { - parseError(err); + + if (err) { self.error = err; $modalInstance.dismiss('cancel'); + return; } + + $modalInstance.close(addr); }); }; }; @@ -247,8 +230,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi if (fc.isPrivKeyEncrypted()) { profileService.unlockFC(function(err) { if (err) { - parseError(err); - $scope.error = err; + $scope.error = bwsError.msg(err); return; } return $scope.sign(txp); @@ -265,8 +247,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi self.setOngoingProcess(); if (err) { $scope.loading = false; - parseError(err); - $scope.error = err.message || gettext('Could not accept payment. Check your Internet connection and try again'); + $scope.error = bwsError.msg(err, gettext('Could not accept payment')); $scope.$digest(); } else { //if txp has required signatures then broadcast it @@ -278,8 +259,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi self.setOngoingProcess(); $scope.loading = false; if (err) { - parseError(err); - $scope.error = gettext('Could not broadcast payment. Check your Internet connection and try again'); + $scope.error = bwsError.msg('Could not broadcast payment'); $scope.$digest(); } else { $log.debug('Transaction signed and broadcasted') @@ -308,8 +288,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi self.setOngoingProcess(); $scope.loading = false; if (err) { - parseError(err); - $scope.error = err.message || gettext('Could not reject payment. Check your Internet connection and try again'); + $scope.error = bwsError.msg(err,gettext('Could not reject payment')); $scope.$digest(); } else { $modalInstance.close(txpr); @@ -330,8 +309,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 payment proposal. Check your Internet connection and try again'); + $scope.error = bwsError.msg(err, gettext('Could not delete payment proposal')); $scope.$digest(); return; } @@ -349,8 +327,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi self.setOngoingProcess(); $scope.loading = false; if (err) { - parseError(err); - $scope.error = err.message || gettext('Could not broadcast payment. Check your Internet connection and try again'); + $scope.error = bwsError.msg(gettext('Could not broadcast payment')); $scope.$digest(); } else { @@ -420,14 +397,13 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi addressService.getAddress(fc.credentials.walletId, forceNew, function(err, addr) { self.generatingAddress = false; - if (err) { - parseError(err); - self.addrError = err.message || gettext('Could not create address. Check your Internet connection and try again'); + if (err) { + self.addrError = err; + } else { + if (addr) + self.addr[fc.credentials.walletId] = addr; } - if (addr) - self.addr[fc.credentials.walletId] = addr; - $scope.$digest(); }); }); @@ -678,16 +654,10 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi this.setSendError = function(err) { var fc = profileService.focusedClient; - $log.warn(err); - parseError(err); - var errMessage = + var prefix = fc.credentials.m > 1 ? gettext('Could not create payment proposal') : gettext('Could not send payment'); - //This are abnormal situations, but still err message will not be translated - //(the should) we should switch using err.code and use proper gettext messages - errMessage = errMessage + '. ' + (err.message ? err.message : gettext('Check your Internet connection and try again')); - - this.error = errMessage; + this.error = bwsError.msg(err, prefix); $timeout(function() { $scope.$digest(); @@ -802,8 +772,7 @@ console.log('[walletHome.js.757:amount:]',amount, feePerKb); //TODO profileService.lockFC(); self.setOngoingProcess(); if (err) { - $log.debug('Sign error:', err); - err.message = gettext('The payment was created but could not be signed. Please try again from home screen.') + (err.message ? ' ' + err.message : ''); + err.message = bwsError.msg(err, gettext('The payment was created but could not be signed. Please try again from home screen')); return cb(err); } @@ -812,7 +781,7 @@ console.log('[walletHome.js.757:amount:]',amount, feePerKb); //TODO fc.broadcastTxProposal(signedTx, function(err, btx, memo) { self.setOngoingProcess(); if (err) { - err.message = gettext('The payment was signed but could not be broadcasted. Please try again from home screen.') + (err.message ? ' ' + err.message : ''); + err.message = bwsError.msg(err, gettext('The payment was signed but could not be broadcasted. Please try again from home screen')); return cb(err); } if (memo) diff --git a/src/js/services/addressService.js b/src/js/services/addressService.js index 39978f94a..b0432d00a 100644 --- a/src/js/services/addressService.js +++ b/src/js/services/addressService.js @@ -1,7 +1,7 @@ 'use strict'; 'use strict'; angular.module('copayApp.services') - .factory('addressService', function(storageService, profileService, $log, $timeout, lodash) { + .factory('addressService', function(storageService, profileService, $log, $timeout, lodash, bwsError, gettext) { var root = {}; @@ -34,8 +34,7 @@ angular.module('copayApp.services') root._createAddress(walletId, cb); }, 5000); } - $log.debug('Creating address ERROR:', err); - return cb(err); + return bwsError.cb(err, gettext('Could not create address'), cb); } return cb(null, addr.address); }); diff --git a/src/js/services/bwsError.js b/src/js/services/bwsError.js new file mode 100644 index 000000000..a8e513f18 --- /dev/null +++ b/src/js/services/bwsError.js @@ -0,0 +1,125 @@ +'use strict'; +angular.module('copayApp.services') + .factory('bwsError', function bwcErrorService($log, gettext) { + var root = {}; + + root.msg = function(err, prefix) { + var body = ''; + prefix = prefix || ''; + + if (err && err.code) { + switch(err.code) { + case 'CONNECTION_ERROR': + body = gettext('Network connection error'); + break; + ;; + case 'NOT_FOUND': + body = gettext('Wallet service not found'); + break; + ;; + case 'BAD_SIGNATURES': + body = gettext('Signatures rejected by server'); + break; + ;; + case 'COPAYER_DATA_MISMATCH': + body = gettext('Copayer data mismatch'); + break; + ;; + case 'COPAYER_IN_WALLET': + body = gettext('Copayer already in this wallet'); + break; + ;; + case 'COPAYER_REGISTERED': + body = gettext('Copayer already registered'); + break; + ;; + case 'COPAYER_VOTED': + body = gettext('Copayer already voted on this spend proposal'); + break; + ;; + case 'DUST_AMOUNT': + body = gettext('Amount below dust threshold'); + break; + ;; + case 'INCORRECT_ADDRESS_NETWORK': + body = gettext('Incorrect address network'); + break; + ;; + case 'INSUFFICIENT_FUNDS': + body = gettext('Insufficient funds'); + break; + ;; + case 'INSUFFICIENT_FUNDS_FOR_FEE': + body = gettext('Insufficient funds for fee'); + break; + ;; + case 'INVALID_ADDRESS': + body = gettext('Invalid address'); + break; + ;; + case 'LOCKED_FUNDS': + body = gettext('Funds are locked by pending spend proposals'); + break; + ;; + case 'NOT_AUTHORIZED': + body = gettext('Not authorized'); + break; + ;; + case 'TX_ALREADY_BROADCASTED': + body = gettext('Transaction already broadcasted'); + break; + ;; + case 'TX_CANNOT_CREATE': + body = gettext('Locktime in effect. Please wait to create a new spend proposal'); + break; + ;; + case 'TX_CANNOT_REMOVE': + body = gettext('Locktime in effect. Please wait to remove this spend proposal'); + break; + ;; + case 'TX_NOT_ACCEPTED': + body = gettext('Spend proposal is not accepted'); + break; + ;; + case 'TX_NOT_FOUND': + body = gettext('Spend proposal not found'); + break; + ;; + case 'TX_NOT_PENDING': + body = gettext('The spend proposal is not pending'); + break; + ;; + case 'UPGRADE_NEEDED': + body = gettext('Please upgrade Copay to perform this action'); + break; + ;; + case 'WALLET_ALREADY_EXISTS': + body = gettext('Wallet already exists'); + break; + ;; + case 'WALLET_FULL': + body = gettext('Wallet is full'); + break; + ;; + case 'WALLET_NOT_COMPLETE': + body = gettext('Wallet is not complete'); + break; + ;; + case 'WALLET_NOT_FOUND': + body = gettext('Wallet not found'); + break; + ;; + } + } + + var msg = prefix + ( body ? ': ' + body : ''); + $log.warn("BWC ERROR:" + msg); + return msg; + }; + + root.cb = function (err,prefix, cb) { + return cb(root.msg(err, prefix)) + }; + + return root; + }); diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index bbb75921c..3d9c03373 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -1,6 +1,6 @@ 'use strict'; angular.module('copayApp.services') - .factory('profileService', function profileServiceFactory($rootScope, $location, $timeout, $filter, $log, lodash, storageService, bwcService, configService, notificationService, isChromeApp, isCordova, gettext, nodeWebkit) { + .factory('profileService', function profileServiceFactory($rootScope, $location, $timeout, $filter, $log, lodash, storageService, bwcService, configService, notificationService, isChromeApp, isCordova, gettext, nodeWebkit, bwsError) { var root = {}; @@ -11,22 +11,6 @@ angular.module('copayApp.services') root.getUtils = function() { return bwcService.getUtils(); }; - - root.errorCb = function(err, prefix, cb) { - var body = ''; - - prefix = gettext(prefix); - if (!err || !err.code) return cb(prefix); - - switch(err.code) { - case 'CONNECTION_ERROR': - body = gettext('Network connection error'); - ;; - } - - return cb(prefix + ( body ? ': ' + body : '')); - }; - root.formatAmount = function(amount) { var config = configService.getSync().wallet.settings; if (config.unitCode == 'sat') return amount; @@ -191,7 +175,7 @@ angular.module('copayApp.services') walletClient.createWallet('Personal Wallet', 'me', 1, 1, { network: 'livenet' }, function(err) { - if (err) return root.errorCb(err, 'Error creating wallet', cb); + if (err) return bwsError.cb(err, gettext('Error creating wallet'), cb); var p = Profile.create({ credentials: [JSON.parse(walletClient.export())], }); @@ -213,7 +197,7 @@ angular.module('copayApp.services') walletClient.createWallet(opts.name, opts.myName || 'me', opts.m, opts.n, { network: opts.networkName }, function(err, secret) { - if (err) return root.errorCb(err, 'Error creating wallet', cb); + if (err) return bwsError.cb(err, gettext('Error creating wallet'), cb); root.profile.credentials.push(JSON.parse(walletClient.export())); root.setWalletClients(); @@ -236,8 +220,19 @@ angular.module('copayApp.services') return cb(gettext('Could not join using the specified extended private key')); } } + + + try { + var walletData = this.getUtils().fromSecret(opts.secret); + if (root.walletClients[walletData.walletId]) + return cb(gettext('Cannot join the same wallet more that once')); + + } catch (ex) { + return cb(gettext('Bad wallet invitation')); + } + walletClient.joinWallet(opts.secret, opts.myName || 'me', function(err) { - if (err) return cb(err); + if (err) return bwsError.cb(err, gettext('Could not join wallet'), cb); root.profile.credentials.push(JSON.parse(walletClient.export())); root.setWalletClients(); From 7c65b9907fec706d7c75b8582389e03bf7184290 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Wed, 12 Aug 2015 11:16:34 -0300 Subject: [PATCH 03/10] better find code --- src/js/services/profileService.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index 3d9c03373..d3bb65c1f 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -224,9 +224,13 @@ angular.module('copayApp.services') try { var walletData = this.getUtils().fromSecret(opts.secret); - if (root.walletClients[walletData.walletId]) - return cb(gettext('Cannot join the same wallet more that once')); + // check if exist + if (lodash.find(root.profile.credentials, { + 'walletId': walletData.walletId + })) { + return cb(gettext('Cannot join the same wallet more that once')); + } } catch (ex) { return cb(gettext('Bad wallet invitation')); } From ead4c403d4e29a69afdac19ca273ff6b7df605bd Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Wed, 12 Aug 2015 11:39:55 -0300 Subject: [PATCH 04/10] rm translate --- public/views/walletHome.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/views/walletHome.html b/public/views/walletHome.html index 12d3bcba6..14a38b4da 100644 --- a/public/views/walletHome.html +++ b/public/views/walletHome.html @@ -76,7 +76,7 @@
- {{index.updateError}} + {{index.updateError}}
From d61206d2c09970f251f674a62aa7aee62fa40e61 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Wed, 12 Aug 2015 11:49:13 -0300 Subject: [PATCH 05/10] fix parameters --- src/js/controllers/walletHome.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/js/controllers/walletHome.js b/src/js/controllers/walletHome.js index 9b19db9c2..24507e51c 100644 --- a/src/js/controllers/walletHome.js +++ b/src/js/controllers/walletHome.js @@ -175,7 +175,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi $scope.alternativeAmountStr = tx.alternativeAmountStr; $scope.copayers = copayers $scope.copayerId = fc.credentials.copayerId; - $scope.canSign= fc.canSign(); + $scope.canSign = fc.canSign(); $scope.loading = null; $scope.color = fc.backgroundColor; refreshUntilItChanges = false; @@ -259,7 +259,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi self.setOngoingProcess(); $scope.loading = false; if (err) { - $scope.error = bwsError.msg('Could not broadcast payment'); + $scope.error = bwsError.msg(err, gettext('Could not broadcast payment')); $scope.$digest(); } else { $log.debug('Transaction signed and broadcasted') @@ -288,7 +288,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi self.setOngoingProcess(); $scope.loading = false; if (err) { - $scope.error = bwsError.msg(err,gettext('Could not reject payment')); + $scope.error = bwsError.msg(err, gettext('Could not reject payment')); $scope.$digest(); } else { $modalInstance.close(txpr); @@ -327,7 +327,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi self.setOngoingProcess(); $scope.loading = false; if (err) { - $scope.error = bwsError.msg(gettext('Could not broadcast payment')); + $scope.error = bwsError.msg(err, gettext('Could not broadcast payment')); $scope.$digest(); } else { @@ -397,9 +397,9 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi addressService.getAddress(fc.credentials.walletId, forceNew, function(err, addr) { self.generatingAddress = false; - if (err) { + if (err) { self.addrError = err; - } else { + } else { if (addr) self.addr[fc.credentials.walletId] = addr; } @@ -657,7 +657,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi var prefix = fc.credentials.m > 1 ? gettext('Could not create payment proposal') : gettext('Could not send payment'); - this.error = bwsError.msg(err, prefix); + this.error = bwsError.msg(err, prefix); $timeout(function() { $scope.$digest(); @@ -691,7 +691,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi this.submitForm = function() { var fc = profileService.focusedClient; var unitToSat = this.unitToSatoshi; - + if (isCordova && this.isWindowsPhoneApp) { this.hideAddress = false; this.hideAmount = false; @@ -722,7 +722,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi feeService.getCurrentFeeValue(self.currentSendFeeLevel, function(err, feePerKb) { if (err) $log.debug(err); -console.log('[walletHome.js.757:amount:]',amount, feePerKb); //TODO + console.log('[walletHome.js.757:amount:]', amount, feePerKb); //TODO fc.sendTxProposal({ toAddress: address, amount: amount, @@ -1046,7 +1046,7 @@ console.log('[walletHome.js.757:amount:]',amount, feePerKb); //TODO }; this.confirmDialog = function(msg, cb) { - if (isCordova) { + if (isCordova) { navigator.notification.confirm( msg, function(buttonIndex) { @@ -1074,11 +1074,11 @@ console.log('[walletHome.js.757:amount:]',amount, feePerKb); //TODO fee: feeStr }); - this.confirmDialog(msg, function(confirmed){ - if (confirmed) + this.confirmDialog(msg, function(confirmed) { + if (confirmed) self._doSendAll(amount); }); - }; + }; /* Start setup */ From 5ad2532593d9a87785a046d6095b3c72eb0108c9 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Wed, 12 Aug 2015 11:52:04 -0300 Subject: [PATCH 06/10] fix parameters2 --- src/js/controllers/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index 00a6c50d7..e574db27c 100644 --- a/src/js/controllers/index.js +++ b/src/js/controllers/index.js @@ -243,7 +243,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r self.updateError = false; return fc.getStatus(function(err, ret) { if (err) { - self.updateError = bwsError.msg(err, 'Could not update Wallet'); + self.updateError = bwsError.msg(err, gettext('Could not update Wallet')); } else { if (!opts.quiet) self.setOngoingProcess('scanning', ret.wallet.scanning); From e4651ef7b08549a02326bb1ab81302b64820ffea Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Wed, 12 Aug 2015 13:04:39 -0300 Subject: [PATCH 07/10] simplifies error handling at index + universal error popup --- public/index.html | 4 +- public/views/walletHome.html | 4 +- src/css/main.css | 11 ++++ src/js/controllers/index.js | 115 +++++++++++++---------------------- 4 files changed, 56 insertions(+), 78 deletions(-) diff --git a/public/index.html b/public/index.html index 88cbd56cb..1c3633722 100644 --- a/public/index.html +++ b/public/index.html @@ -24,8 +24,8 @@
-
+
+
- {{index.updateError}} + {{index.updateError|translate}}
@@ -481,7 +481,7 @@
-

Could not fetch transaction history

+

Could not fetch transaction history

diff --git a/src/css/main.css b/src/css/main.css index 3de53f411..00bc52152 100644 --- a/src/css/main.css +++ b/src/css/main.css @@ -1119,6 +1119,17 @@ input.ng-invalid-match, input.ng-invalid-match:focus { padding: 0.6rem 0.8rem !important; } +.alertModal { + background: #FFFFFF; + box-shadow: 0px 0px 6px 0px rgba(0,0,0,0.50); + border-radius: 5px; + position: absolute; + width: 90%; + left: 5%; + top: 15%; + z-index: 1100; +} + .passModal { background: #FFFFFF; box-shadow: 0px 0px 6px 0px rgba(0,0,0,0.50); diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index e574db27c..4ee500d03 100644 --- a/src/js/controllers/index.js +++ b/src/js/controllers/index.js @@ -319,12 +319,12 @@ angular.module('copayApp.controllers').controller('indexController', function($r self.setSendMax = function() { // Set Send max - if (self.currentFeeLevel && self.totalBytesToSendMax) { + if (self.currentFeeLevel && self.totalBytesToSendMax) { feeService.getCurrentFeeValue(self.currentFeeLevel, function(err, feePerKb) { // KB to send max if (self.totalBytesToSendMax) { - var feeToSendMaxSat = parseInt(((self.totalBytesToSendMax * feePerKb ) / 1000.).toFixed(0)); + var feeToSendMaxSat = parseInt(((self.totalBytesToSendMax * feePerKb) / 1000.).toFixed(0)); self.availableMaxBalance = strip((self.availableBalanceSat - feeToSendMaxSat) * self.satToUnit); self.feeToSendMaxStr = profileService.formatAmount(feeToSendMaxSat) + ' ' + self.unitName; } else { @@ -360,8 +360,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r fc.getBalance(function(err, balance) { self.setOngoingProcess('updatingBalance', false); if (err) { - $log.debug('Wallet Balance ERROR:', err); - $scope.$emit('Local/ClientError', err); + self.handleError(err); return; } $log.debug('Wallet Balance:', balance); @@ -378,8 +377,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r fc.getTxProposals({}, function(err, txps) { self.setOngoingProcess('updatingPendingTxps', false); if (err) { - $log.debug('Wallet PendingTxps ERROR:', err); - $scope.$emit('Local/ClientError', err); + self.handleError(err); } else { $log.debug('Wallet PendingTxps:', txps); self.setPendingTxps(txps); @@ -392,7 +390,6 @@ angular.module('copayApp.controllers').controller('indexController', function($r self.updateTxHistory = function(skip) { var fc = profileService.focusedClient; if (!fc.isComplete()) return; - if (!skip) { self.txHistory = []; } @@ -401,6 +398,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r self.txHistoryError = false; self.updatingTxHistory = true; self.txHistoryPaging = false; + $timeout(function() { fc.getTxHistory({ skip: self.skipHistory, @@ -410,8 +408,10 @@ angular.module('copayApp.controllers').controller('indexController', function($r if (err) { $log.debug('TxHistory ERROR:', err); // We do not should errors here, since history is usually - // fetched AFTER others requests. - //self.handleError(err); + // fetched AFTER others requests (if skip=0) + if (skip) + self.handleError(err); + self.txHistoryError = true; } else { $log.debug('Wallet Transaction History:', txs); @@ -423,14 +423,20 @@ angular.module('copayApp.controllers').controller('indexController', function($r }); }; + // This handles errors from BWS/index with are nomally + // trigger from async events (like updates) self.handleError = function(err) { $log.warn('Client ERROR:', err); if (err.code === 'NOT_AUTHORIZED') { - $scope.$emit('Local/NotAuthorized'); + self.notAuthorized = true; + go.walletHome(); } else if (err.code === 'NOT_FOUND') { - $scope.$emit('Local/BWSNotFound'); + self.showErrorPopup(gettext('Could not access Wallet Service: Not found')); } else { + var msg = "" $scope.$emit('Local/ClientError', (err.error ? err.error : err)); + var msg = bwsError.msg(err, gettext('Error at Wallet Service')); + self.showErrorPopup(msg); } }; self.openWallet = function() { @@ -478,7 +484,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r if (tx.outputs.length === 1 && !tx.outputs[0].message) { tx.showSingle = true; tx.toAddress = tx.outputs[0].toAddress; // txproposal - tx.address = tx.outputs[0].address; // txhistory + tx.address = tx.outputs[0].address; // txhistory } } }; @@ -718,7 +724,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r getHistory(null, function(err, txs) { self.setOngoingProcess('generatingCSV', false); if (err) { - $log.debug('TxHistory ERROR:', err); + self.handleError(err); } else { $log.debug('Wallet Transaction History:', txs); @@ -745,11 +751,11 @@ angular.module('copayApp.controllers').controller('indexController', function($r _note += ' Moved:' + (it.amount * satToBtc).toFixed(8) dataString = formatDate(it.time * 1000) + ',' + formatString(it.addressTo) + ',' + _note + ',' + _amount + ',BTC,,,,'; - csvContent += dataString + "\n"; + csvContent += dataString + "\n"; if (it.fees && (it.action == 'moved' || it.action == 'sent')) { var _fee = (it.fees * satToBtc).toFixed(8) - csvContent += formatDate(it.time * 1000) + ',Bitcoin Network Fees,, -' + _fee + ',BTC,,,,' + "\n"; + csvContent += formatDate(it.time * 1000) + ',Bitcoin Network Fees,, -' + _fee + ',BTC,,,,' + "\n"; } }); @@ -768,35 +774,21 @@ angular.module('copayApp.controllers').controller('indexController', function($r }); }; - self.clientError = function(err) { - if (isCordova) { - navigator.notification.confirm( - err, - function() {}, - 'Wallet Server Error', ['OK'] - ); - } else { - if (!isChromeApp) { - alert(err); - } - } + self.showErrorPopup = function (msg, cb) { + $log.warn('Showing err popup:' + msg); + self.showAlert = { + msg: msg, + close: function(err) { + self.showAlert = null; + if (cb) return cb(err); + }, + }; + $timeout(function() { + $rootScope.$apply(); + }); + }; - self.deviceError = function(err) { - if (isCordova) { - navigator.notification.confirm( - err, - function() {}, - 'Device Error', ['OK'] - ); - } else { - if (!isChromeApp) { - alert(err); - } - } - }; - - self.recreate = function(cb) { var fc = profileService.focusedClient; self.setOngoingProcess('recreating', true); @@ -972,41 +964,12 @@ angular.module('copayApp.controllers').controller('indexController', function($r $rootScope.$on('Local/BackupDone', function(event) { self.needsBackup = false; storageService.setBackupFlag(self.walletId, function(err) { - if (err) $rootScope.$emit('Local/DeviceError', err) + if (err) root.showErrorPopup(err); }); }); - $rootScope.$on('Local/NotAuthorized', function(event) { - self.notAuthorized = true; - $rootScope.$apply(); - }); - - $rootScope.$on('Local/BWSNotFound', function(event) { - self.clientError('Could not access Wallet Service: Not found'); - $rootScope.$apply(); - }); - $rootScope.$on('Local/DeviceError', function(event, err) { - self.deviceError(err); - $rootScope.$apply(); - }); - - $rootScope.$on('Local/ClientError', function(event, err) { - if (err.code && err.code === 'NOT_AUTHORIZED') { - // Show not error, just redirect to home (where the recreate option is shown) - go.walletHome(); - } else if (err && err.cors == 'rejected') { - $log.debug('CORS error:', err); - } else if (err.code === 'ETIMEDOUT' || err.code === 'CONNECTION_ERROR') { - $log.debug('Time out:', err); - } else { - var msg = 'Error at Wallet Service: '; - if (err.message) msg = msg + err.message; - else if (err.error) msg = msg + err.error; - else msg = msg + (lodash.isObject(err) ? JSON.stringify(err) : err); - self.clientError(msg); - } - $rootScope.$apply(); + root.showErrorPopup(err); }); $rootScope.$on('Local/WalletImported', function(event, walletId) { @@ -1032,7 +995,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r self.updateAll(); } - if (self.network =='testnet') { + if (self.network == 'testnet') { self.debouncedUpdateHistory(); } else { self.updateTxHistory(); @@ -1105,6 +1068,10 @@ angular.module('copayApp.controllers').controller('indexController', function($r self.setTab(tab, reset); }); + $rootScope.$on('Local/ShowAlert', function(event, msg, cb) { + self.showErrorPopup(msg,cb); + }); + $rootScope.$on('Local/NeedsPassword', function(event, isSetup, cb) { self.askPassword = { isSetup: isSetup, From 46f78f4900e711a243a5c81f69595d02930f3332 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Wed, 12 Aug 2015 13:04:50 -0300 Subject: [PATCH 08/10] add alert template --- public/views/includes/alert.html | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 public/views/includes/alert.html diff --git a/public/views/includes/alert.html b/public/views/includes/alert.html new file mode 100644 index 000000000..2c9ed4b85 --- /dev/null +++ b/public/views/includes/alert.html @@ -0,0 +1,14 @@ +
+
+ +
+
+
+ + {{index.showAlert.msg|translate}} +
+
+ OK +
+
+
From d7af0bf9bedaf3895997cd061063fdd5e6ffe8a6 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Wed, 12 Aug 2015 14:36:07 -0300 Subject: [PATCH 09/10] fix translate --- public/views/walletHome.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/views/walletHome.html b/public/views/walletHome.html index 47cf110f0..d2a69224f 100644 --- a/public/views/walletHome.html +++ b/public/views/walletHome.html @@ -481,7 +481,7 @@
-

Could not fetch transaction history

+

Could not fetch transaction history

From 81ebe2708f2dbb5baf4b8526f60274a1f86655d9 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Wed, 12 Aug 2015 14:38:29 -0300 Subject: [PATCH 10/10] fix switch case --- src/js/services/bwsError.js | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/src/js/services/bwsError.js b/src/js/services/bwsError.js index a8e513f18..3dec7ccc4 100644 --- a/src/js/services/bwsError.js +++ b/src/js/services/bwsError.js @@ -12,103 +12,78 @@ angular.module('copayApp.services') case 'CONNECTION_ERROR': body = gettext('Network connection error'); break; - ;; case 'NOT_FOUND': body = gettext('Wallet service not found'); break; - ;; case 'BAD_SIGNATURES': body = gettext('Signatures rejected by server'); break; - ;; case 'COPAYER_DATA_MISMATCH': body = gettext('Copayer data mismatch'); break; - ;; case 'COPAYER_IN_WALLET': body = gettext('Copayer already in this wallet'); break; - ;; case 'COPAYER_REGISTERED': body = gettext('Copayer already registered'); break; - ;; case 'COPAYER_VOTED': body = gettext('Copayer already voted on this spend proposal'); break; - ;; case 'DUST_AMOUNT': body = gettext('Amount below dust threshold'); break; - ;; case 'INCORRECT_ADDRESS_NETWORK': body = gettext('Incorrect address network'); break; - ;; case 'INSUFFICIENT_FUNDS': body = gettext('Insufficient funds'); break; - ;; case 'INSUFFICIENT_FUNDS_FOR_FEE': body = gettext('Insufficient funds for fee'); break; - ;; case 'INVALID_ADDRESS': body = gettext('Invalid address'); break; - ;; case 'LOCKED_FUNDS': body = gettext('Funds are locked by pending spend proposals'); break; - ;; case 'NOT_AUTHORIZED': body = gettext('Not authorized'); break; - ;; case 'TX_ALREADY_BROADCASTED': body = gettext('Transaction already broadcasted'); break; - ;; case 'TX_CANNOT_CREATE': body = gettext('Locktime in effect. Please wait to create a new spend proposal'); break; - ;; case 'TX_CANNOT_REMOVE': body = gettext('Locktime in effect. Please wait to remove this spend proposal'); break; - ;; case 'TX_NOT_ACCEPTED': body = gettext('Spend proposal is not accepted'); break; - ;; case 'TX_NOT_FOUND': body = gettext('Spend proposal not found'); break; - ;; case 'TX_NOT_PENDING': body = gettext('The spend proposal is not pending'); break; - ;; case 'UPGRADE_NEEDED': body = gettext('Please upgrade Copay to perform this action'); break; - ;; case 'WALLET_ALREADY_EXISTS': body = gettext('Wallet already exists'); break; - ;; case 'WALLET_FULL': body = gettext('Wallet is full'); break; - ;; case 'WALLET_NOT_COMPLETE': body = gettext('Wallet is not complete'); break; - ;; case 'WALLET_NOT_FOUND': body = gettext('Wallet not found'); break; - ;; } }