better state handling at home

This commit is contained in:
Matias Alejo Garcia 2014-11-30 23:14:46 -03:00
commit f4fd6c24f7

View file

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