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,