simplifies error handling at index + universal error popup

This commit is contained in:
Matias Alejo Garcia 2015-08-12 13:04:39 -03:00
parent 5ad2532593
commit e4651ef7b0
4 changed files with 56 additions and 78 deletions

View File

@ -24,8 +24,8 @@
<div ng-include="'views/includes/sidebar.html'" ng-if="index.hasProfile"></div>
<div notifications="right top"></div>
<div ng-include="'views/includes/password.html'" ng-if="index.askPassword"
></div>
<div ng-include="'views/includes/password.html'" ng-if="index.askPassword"></div>
<div ng-include="'views/includes/alert.html'" ng-if="index.showAlert"></div>
<div id="sectionContainer">
<div id="mainSection">
<section ui-view="main"

View File

@ -76,7 +76,7 @@
<div class="amount" ng-style="{'background-color':index.backgroundColor}">
<div ng-if="!index.anyOnGoingProcess && !index.notAuthorized">
<div ng-show="index.updateError" ng-click='index.openWallet(); index.updateTxHistory()'>
<span class="size-12 db m10b">{{index.updateError}}</span>
<span class="size-12 db m10b">{{index.updateError|translate}}</span>
<button class="outline white tiny round" translate>Tap to retry</button>
</div>
@ -481,7 +481,7 @@
<div class="large-12 columns">
<div class="oh text-center">
<span ng-show="index.txHistoryError && !index.notAuthorized" ng-click='index.updateTxHistory()'>
<p class="size-12 m10b db text-gray" translate>Could not fetch transaction history</p>
<p class="size-12 m10b db text-gray">Could not fetch transaction history</p>
<button class="outline round light-gray tiny" translate>Tap to retry</button>
</span>
<span ng-if="!index.txHistoryError" translate>

View File

@ -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);

View File

@ -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,