From 494c21132ad50c0f9c092d2b8c01f2b40127ad9e Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sun, 30 Nov 2014 00:44:25 -0300 Subject: [PATCH] working with events --- js/controllers/home.js | 1 + js/controllers/sidebar.js | 18 +++++++++++++++++- js/models/Identity.js | 11 +++++------ js/services/identityService.js | 6 +++--- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/js/controllers/home.js b/js/controllers/home.js index 0d50cb53b..1d9790804 100644 --- a/js/controllers/home.js +++ b/js/controllers/home.js @@ -24,6 +24,7 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc } $rootScope.starting = true; identityService.open(form.email.$modelValue, form.password.$modelValue, function(err) { +console.log('[home.js.27]'); //TODO $rootScope.starting = false; if (err) { copay.logger.warn(err); diff --git a/js/controllers/sidebar.js b/js/controllers/sidebar.js index 760c15739..38fea1870 100644 --- a/js/controllers/sidebar.js +++ b/js/controllers/sidebar.js @@ -44,14 +44,30 @@ angular.module('copayApp.controllers').controller('SidebarController', function( $scope.init = function() { + + // Change focused wallet if ($rootScope.wallet) { $rootScope.$watch('wallet', function() { $scope.walletSelection = false; $scope.setWallets(); }); } - }; + // Change wallet list + if ($rootScope.iden) { + var iden = $rootScope.iden; + iden.on('newWallet', function() { + $scope.walletSelection = false; + $scope.setWallets(); + }); + iden.on('deleteWallet', function() { + $scope.walletSelection = false; + $scope.setWallets(); + }); + + } + + }; $scope.setWallets = function() { if (!$rootScope.iden) return; diff --git a/js/models/Identity.js b/js/models/Identity.js index cad0a9733..7e8ce6d38 100644 --- a/js/models/Identity.js +++ b/js/models/Identity.js @@ -165,17 +165,16 @@ Identity.prototype.emitAndKeepAlive = function(args) { /** * @desc open profile's wallets. Call it AFTER setting - * the proper even listeners + * the proper even listeners. no callback. * - * @param cb */ -Identity.prototype.openWallets = function(cb) { +Identity.prototype.openWallets = function() { var self = this; if (_.isEmpty(self.walletIds)) { self.emitAndKeepAlive('noWallets') - return cb(); + return; } // First read the lastFocused wallet @@ -187,10 +186,10 @@ Identity.prototype.openWallets = function(cb) { }); console.log('[Identity.js.188]', self.walletIds, self.focusedTimestamps); //TODO - // Then read the rest of the wallets... + // opens the wallets, in the order they were last accessed. Emits open events (newWallet) async.eachSeries(self.walletIds, function(walletId, a_cb) { self.readAndBindWallet(walletId, a_cb); - }, cb); + }); }; /** diff --git a/js/services/identityService.js b/js/services/identityService.js index 0c0526480..4ab811224 100644 --- a/js/services/identityService.js +++ b/js/services/identityService.js @@ -85,7 +85,8 @@ angular.module('copayApp.services') if (err) return cb(err); console.log('[identityService.js.95] LISTO OPEN!!'); //TODO root.bind(iden); - return iden.openWallets(cb); + iden.openWallets(); + return cb(); }); }; @@ -243,9 +244,8 @@ angular.module('copayApp.services') }; root.bind = function(iden) { - -console.log('[identityService.js.250] PROFILE BINE'); //TODO preconditions.checkArgument(_.isObject(iden)); + copay.logger.debug('Binding profile...'); var self = this; root.setupGlobalVariables(iden);