diff --git a/js/controllers/head.js b/js/controllers/head.js index cf40580f9..6593ee32d 100644 --- a/js/controllers/head.js +++ b/js/controllers/head.js @@ -13,12 +13,9 @@ angular.module('copayApp.controllers').controller('HeadController', function($sc }; $scope.signout = function() { - logout(); + controllerUtils.logout(); }; - function logout() { - controllerUtils.logout(); - } // Ensures a graceful disconnect window.onbeforeunload = function() { @@ -48,7 +45,7 @@ angular.module('copayApp.controllers').controller('HeadController', function($sc $scope.title = newTitle; }); $rootScope.$on('signout', function() { - $scope.signout(); + controllerUtils.logout(); }); } }); diff --git a/js/models/Identity.js b/js/models/Identity.js index b57f72a5d..65d3c1b05 100644 --- a/js/models/Identity.js +++ b/js/models/Identity.js @@ -228,6 +228,8 @@ Identity.prototype.exportWithWalletInfo = function(opts) { * @param {Function} cb */ Identity.prototype.store = function(opts, cb) { + log.debug('Storing profile'); + var self = this; opts = opts || {}; @@ -348,14 +350,10 @@ Identity.importFromFullJson = function(str, password, opts, cb) { callback(); }); }, function(err, results) { - if (err) { - return cb(err); - } + if (err) return cb(err); + iden.store(null, function(err) { - if (err) { - return cb(err); - } - return cb(null, iden); + return cb(err, iden); }); }); }; @@ -384,7 +382,9 @@ Identity.prototype.bindWallet = function(w) { }); w.on('ready', function() { log.debug(' Wallet' + w.getName()); - self.storeWallet(w); + self.store({noWallets:true}, function() { + self.storeWallet(w); + }); }); w.on('addressBookUpdated', function() { log.debug(' Wallet' + w.getName()); diff --git a/js/services/controllerUtils.js b/js/services/controllerUtils.js index e718b4312..0d42459ce 100644 --- a/js/services/controllerUtils.js +++ b/js/services/controllerUtils.js @@ -30,8 +30,12 @@ angular.module('copayApp.services') }; root.logout = function() { - if ($rootScope.iden) - $rootScope.iden.close(); + + if ($rootScope.iden) { + $rootScope.iden.store(null, function(){ + $rootScope.iden.close(); + }); + } delete $rootScope['wallet']; delete $rootScope['iden'];