From f4fd6c24f763737b43a2246ed36f329961874a6b Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sun, 30 Nov 2014 23:14:46 -0300 Subject: [PATCH] better state handling at home --- js/controllers/home.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/js/controllers/home.js b/js/controllers/home.js index 58c70e93e..c5da16cc0 100644 --- a/js/controllers/home.js +++ b/js/controllers/home.js @@ -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); + } }); }