Merge pull request #392 from yemel/fix/handle-sudden-disconnection

Fix/handle sudden disconnection
This commit is contained in:
Gustavo Maximiliano Cortez 2014-05-16 09:42:51 -03:00
commit 66c1588fef
4 changed files with 33 additions and 8 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

@ -44,11 +44,7 @@ angular.module('copay.header').controller('HeaderController',
};
$scope.signout = function() {
var w = $rootScope.wallet;
if (w) {
w.disconnect();
controllerUtils.logout();
}
logout();
$scope.clearFlashMessage();
};
@ -64,4 +60,19 @@ angular.module('copay.header').controller('HeaderController',
};
$rootScope.isCollapsed = true;
function logout() {
var w = $rootScope.wallet;
if (w) {
w.disconnect();
controllerUtils.logout();
}
}
// Ensures a graceful disconnect
window.onbeforeunload = logout;
$scope.$on('$destroy', function() {
window.onbeforeunload = undefined;
});
});

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();
});