handle the PeerID-already-in-use error and display a friendly message

This commit is contained in:
Yemel Jardi 2014-05-15 17:16:26 -07:00
parent f4f060a45b
commit 190185ac9c
3 changed files with 17 additions and 3 deletions

View File

@ -162,10 +162,14 @@
<!-- Templates -->
<script type="text/ng-template" id="signin.html">
<div class="signin" ng-controller="SigninController">
<div data-alert class="alert-box info radius" ng-show="loading">
<div data-alert class="alert-box info radius" ng-show="loading && !failure">
<i class="size-21 fi-bitcoin-circle icon-rotate spinner"></i>
Authenticating and Looking for peers...
</div>
<div class="alert-box error radius" ng-show="failure">
Oops, we had an error! Looks like you are already connected to this wallet,
please close all other Copay Wallets and <a ng-click='failure = false; loading = false'>Try again</a>.
</div>
<div ng-show="!loading">
<div class="row">
<div class="large-6 medium-6 columns">

View File

@ -7,7 +7,7 @@ angular.module('copay.signin').controller('SigninController',
return v1 > v2 ? 1 : ( v1 < v2 ) ? -1 : 0;
};
$scope.loading = false;
$scope.loading = $scope.failure = false;
$scope.wallets = walletFactory.getWallets().sort(cmp);
$scope.selectedWalletId = $scope.wallets.length ? $scope.wallets[0].id : null;
$scope.openPassword = '';
@ -34,12 +34,13 @@ angular.module('copay.signin').controller('SigninController',
Passphrase.getBase64Async(password, function(passphrase){
var w = walletFactory.open($scope.selectedWalletId, { passphrase: passphrase});
if (!w) {
$scope.loading = false;
$scope.loading = $scope.failure = false;
$rootScope.flashMessage = { message: 'Bad password or connection error', type: 'error'};
$rootScope.$digest();
return;
}
controllerUtils.startNetwork(w);
listenErrors(w);
});
};
@ -66,8 +67,16 @@ angular.module('copay.signin').controller('SigninController',
controllerUtils.onErrorDigest();
} else {
controllerUtils.startNetwork(w);
listenErrors(w);
}
});
});
};
function listenErrors(wallet) {
wallet.network.on('error', function(err) {
$scope.failure = true;
});
}
});

View File

@ -262,6 +262,7 @@ Network.prototype._setupPeerHandlers = function(openCallback) {
p.on('error', function(err) {
if (!err.message.match(/Could\snot\sconnect\sto peer/)) {
console.log('### PEER ERROR:', err);
self.emit('error', err);
}
self._checkAnyPeer();
});