better state handling at home

This commit is contained in:
Matias Alejo Garcia 2014-11-30 23:14:46 -03:00
parent f490f4a661
commit f4fd6c24f7
1 changed files with 21 additions and 2 deletions

View File

@ -16,6 +16,20 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
Compatibility.check($scope);
$scope.done = function() {
$rootScope.starting = false;
};
$scope.$on("$destroy", function(){
var iden = $rootScope.iden;
if (iden) {
iden.removeListener('newWallets', $scope.done );
iden.removeListener('noWallets', $scope.done );
}
});
$scope.openProfile = function(form) {
$scope.confirmedEmail = false;
if (form && form.$invalid) {
@ -24,8 +38,8 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
}
$rootScope.starting = true;
identityService.open(form.email.$modelValue, form.password.$modelValue, function(err, iden) {
$rootScope.starting = false;
if (err) {
if (err) {
$rootScope.starting = false;
copay.logger.warn(err);
if ((err.toString() || '').match('PNOTFOUND')) {
$scope.error = 'Invalid email or password';
@ -33,6 +47,11 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
$scope.error = 'Unknown error';
}
}
if (iden) {
iden.on('newWallet', $scope.done);
iden.on('noWallets', $scope.done);
}
});
}