mirror of https://github.com/BTCPrivate/copay.git
simplifies error handling at index + universal error popup
This commit is contained in:
parent
5ad2532593
commit
e4651ef7b0
|
@ -24,8 +24,8 @@
|
||||||
<div ng-include="'views/includes/sidebar.html'" ng-if="index.hasProfile"></div>
|
<div ng-include="'views/includes/sidebar.html'" ng-if="index.hasProfile"></div>
|
||||||
|
|
||||||
<div notifications="right top"></div>
|
<div notifications="right top"></div>
|
||||||
<div ng-include="'views/includes/password.html'" ng-if="index.askPassword"
|
<div ng-include="'views/includes/password.html'" ng-if="index.askPassword"></div>
|
||||||
></div>
|
<div ng-include="'views/includes/alert.html'" ng-if="index.showAlert"></div>
|
||||||
<div id="sectionContainer">
|
<div id="sectionContainer">
|
||||||
<div id="mainSection">
|
<div id="mainSection">
|
||||||
<section ui-view="main"
|
<section ui-view="main"
|
||||||
|
|
|
@ -76,7 +76,7 @@
|
||||||
<div class="amount" ng-style="{'background-color':index.backgroundColor}">
|
<div class="amount" ng-style="{'background-color':index.backgroundColor}">
|
||||||
<div ng-if="!index.anyOnGoingProcess && !index.notAuthorized">
|
<div ng-if="!index.anyOnGoingProcess && !index.notAuthorized">
|
||||||
<div ng-show="index.updateError" ng-click='index.openWallet(); index.updateTxHistory()'>
|
<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>
|
<button class="outline white tiny round" translate>Tap to retry</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -481,7 +481,7 @@
|
||||||
<div class="large-12 columns">
|
<div class="large-12 columns">
|
||||||
<div class="oh text-center">
|
<div class="oh text-center">
|
||||||
<span ng-show="index.txHistoryError && !index.notAuthorized" ng-click='index.updateTxHistory()'>
|
<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>
|
<button class="outline round light-gray tiny" translate>Tap to retry</button>
|
||||||
</span>
|
</span>
|
||||||
<span ng-if="!index.txHistoryError" translate>
|
<span ng-if="!index.txHistoryError" translate>
|
||||||
|
|
|
@ -1119,6 +1119,17 @@ input.ng-invalid-match, input.ng-invalid-match:focus {
|
||||||
padding: 0.6rem 0.8rem !important;
|
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 {
|
.passModal {
|
||||||
background: #FFFFFF;
|
background: #FFFFFF;
|
||||||
box-shadow: 0px 0px 6px 0px rgba(0,0,0,0.50);
|
box-shadow: 0px 0px 6px 0px rgba(0,0,0,0.50);
|
||||||
|
|
|
@ -324,7 +324,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
|
|
||||||
// KB to send max
|
// KB to send max
|
||||||
if (self.totalBytesToSendMax) {
|
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.availableMaxBalance = strip((self.availableBalanceSat - feeToSendMaxSat) * self.satToUnit);
|
||||||
self.feeToSendMaxStr = profileService.formatAmount(feeToSendMaxSat) + ' ' + self.unitName;
|
self.feeToSendMaxStr = profileService.formatAmount(feeToSendMaxSat) + ' ' + self.unitName;
|
||||||
} else {
|
} else {
|
||||||
|
@ -360,8 +360,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
fc.getBalance(function(err, balance) {
|
fc.getBalance(function(err, balance) {
|
||||||
self.setOngoingProcess('updatingBalance', false);
|
self.setOngoingProcess('updatingBalance', false);
|
||||||
if (err) {
|
if (err) {
|
||||||
$log.debug('Wallet Balance ERROR:', err);
|
self.handleError(err);
|
||||||
$scope.$emit('Local/ClientError', err);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$log.debug('Wallet Balance:', balance);
|
$log.debug('Wallet Balance:', balance);
|
||||||
|
@ -378,8 +377,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
fc.getTxProposals({}, function(err, txps) {
|
fc.getTxProposals({}, function(err, txps) {
|
||||||
self.setOngoingProcess('updatingPendingTxps', false);
|
self.setOngoingProcess('updatingPendingTxps', false);
|
||||||
if (err) {
|
if (err) {
|
||||||
$log.debug('Wallet PendingTxps ERROR:', err);
|
self.handleError(err);
|
||||||
$scope.$emit('Local/ClientError', err);
|
|
||||||
} else {
|
} else {
|
||||||
$log.debug('Wallet PendingTxps:', txps);
|
$log.debug('Wallet PendingTxps:', txps);
|
||||||
self.setPendingTxps(txps);
|
self.setPendingTxps(txps);
|
||||||
|
@ -392,7 +390,6 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
self.updateTxHistory = function(skip) {
|
self.updateTxHistory = function(skip) {
|
||||||
var fc = profileService.focusedClient;
|
var fc = profileService.focusedClient;
|
||||||
if (!fc.isComplete()) return;
|
if (!fc.isComplete()) return;
|
||||||
|
|
||||||
if (!skip) {
|
if (!skip) {
|
||||||
self.txHistory = [];
|
self.txHistory = [];
|
||||||
}
|
}
|
||||||
|
@ -401,6 +398,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
self.txHistoryError = false;
|
self.txHistoryError = false;
|
||||||
self.updatingTxHistory = true;
|
self.updatingTxHistory = true;
|
||||||
self.txHistoryPaging = false;
|
self.txHistoryPaging = false;
|
||||||
|
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
fc.getTxHistory({
|
fc.getTxHistory({
|
||||||
skip: self.skipHistory,
|
skip: self.skipHistory,
|
||||||
|
@ -410,8 +408,10 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
if (err) {
|
if (err) {
|
||||||
$log.debug('TxHistory ERROR:', err);
|
$log.debug('TxHistory ERROR:', err);
|
||||||
// We do not should errors here, since history is usually
|
// We do not should errors here, since history is usually
|
||||||
// fetched AFTER others requests.
|
// fetched AFTER others requests (if skip=0)
|
||||||
//self.handleError(err);
|
if (skip)
|
||||||
|
self.handleError(err);
|
||||||
|
|
||||||
self.txHistoryError = true;
|
self.txHistoryError = true;
|
||||||
} else {
|
} else {
|
||||||
$log.debug('Wallet Transaction History:', txs);
|
$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) {
|
self.handleError = function(err) {
|
||||||
$log.warn('Client ERROR:', err);
|
$log.warn('Client ERROR:', err);
|
||||||
if (err.code === 'NOT_AUTHORIZED') {
|
if (err.code === 'NOT_AUTHORIZED') {
|
||||||
$scope.$emit('Local/NotAuthorized');
|
self.notAuthorized = true;
|
||||||
|
go.walletHome();
|
||||||
} else if (err.code === 'NOT_FOUND') {
|
} else if (err.code === 'NOT_FOUND') {
|
||||||
$scope.$emit('Local/BWSNotFound');
|
self.showErrorPopup(gettext('Could not access Wallet Service: Not found'));
|
||||||
} else {
|
} else {
|
||||||
|
var msg = ""
|
||||||
$scope.$emit('Local/ClientError', (err.error ? err.error : err));
|
$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() {
|
self.openWallet = function() {
|
||||||
|
@ -718,7 +724,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
getHistory(null, function(err, txs) {
|
getHistory(null, function(err, txs) {
|
||||||
self.setOngoingProcess('generatingCSV', false);
|
self.setOngoingProcess('generatingCSV', false);
|
||||||
if (err) {
|
if (err) {
|
||||||
$log.debug('TxHistory ERROR:', err);
|
self.handleError(err);
|
||||||
} else {
|
} else {
|
||||||
$log.debug('Wallet Transaction History:', txs);
|
$log.debug('Wallet Transaction History:', txs);
|
||||||
|
|
||||||
|
@ -768,35 +774,21 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
self.clientError = function(err) {
|
self.showErrorPopup = function (msg, cb) {
|
||||||
if (isCordova) {
|
$log.warn('Showing err popup:' + msg);
|
||||||
navigator.notification.confirm(
|
self.showAlert = {
|
||||||
err,
|
msg: msg,
|
||||||
function() {},
|
close: function(err) {
|
||||||
'Wallet Server Error', ['OK']
|
self.showAlert = null;
|
||||||
);
|
if (cb) return cb(err);
|
||||||
} else {
|
},
|
||||||
if (!isChromeApp) {
|
|
||||||
alert(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) {
|
self.recreate = function(cb) {
|
||||||
var fc = profileService.focusedClient;
|
var fc = profileService.focusedClient;
|
||||||
self.setOngoingProcess('recreating', true);
|
self.setOngoingProcess('recreating', true);
|
||||||
|
@ -972,41 +964,12 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
$rootScope.$on('Local/BackupDone', function(event) {
|
$rootScope.$on('Local/BackupDone', function(event) {
|
||||||
self.needsBackup = false;
|
self.needsBackup = false;
|
||||||
storageService.setBackupFlag(self.walletId, function(err) {
|
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) {
|
$rootScope.$on('Local/DeviceError', function(event, err) {
|
||||||
self.deviceError(err);
|
root.showErrorPopup(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();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$rootScope.$on('Local/WalletImported', function(event, walletId) {
|
$rootScope.$on('Local/WalletImported', function(event, walletId) {
|
||||||
|
@ -1032,7 +995,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
self.updateAll();
|
self.updateAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self.network =='testnet') {
|
if (self.network == 'testnet') {
|
||||||
self.debouncedUpdateHistory();
|
self.debouncedUpdateHistory();
|
||||||
} else {
|
} else {
|
||||||
self.updateTxHistory();
|
self.updateTxHistory();
|
||||||
|
@ -1105,6 +1068,10 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
self.setTab(tab, reset);
|
self.setTab(tab, reset);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$rootScope.$on('Local/ShowAlert', function(event, msg, cb) {
|
||||||
|
self.showErrorPopup(msg,cb);
|
||||||
|
});
|
||||||
|
|
||||||
$rootScope.$on('Local/NeedsPassword', function(event, isSetup, cb) {
|
$rootScope.$on('Local/NeedsPassword', function(event, isSetup, cb) {
|
||||||
self.askPassword = {
|
self.askPassword = {
|
||||||
isSetup: isSetup,
|
isSetup: isSetup,
|
||||||
|
|
Loading…
Reference in New Issue