diff --git a/js/controllers/create.js b/js/controllers/create.js index 65ccb27b9..49f6daa01 100644 --- a/js/controllers/create.js +++ b/js/controllers/create.js @@ -62,7 +62,8 @@ angular.module('copayApp.controllers').controller('CreateController', $scope.error = 'Could not create wallet: ' + err; } } - $rootScope.$digest() + + $rootScope.$digest(); }); }; }); diff --git a/js/controllers/createWallet.js b/js/controllers/createWallet.js deleted file mode 100644 index 5a7e034db..000000000 --- a/js/controllers/createWallet.js +++ /dev/null @@ -1,5 +0,0 @@ -'use strict'; -angular.module('copayApp.controllers').controller('CreateWalletController', function($scope, $rootScope) { - - $rootScope.title = 'Create Wallet'; -}); diff --git a/js/controllers/home.js b/js/controllers/home.js index f2c509a87..d38c4a45c 100644 --- a/js/controllers/home.js +++ b/js/controllers/home.js @@ -18,14 +18,14 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc $scope.done = function() { $rootScope.starting = false; - setTimeout(function () { $rootScope.$digest(); }, 1); + $rootScope.$digest(); }; $scope.$on("$destroy", function(){ var iden = $rootScope.iden; if (iden) { - iden.removeListener('newWallets', $scope.done ); + iden.removeListener('newWallet', $scope.done ); iden.removeListener('noWallets', $scope.done ); } }); diff --git a/js/controllers/homeWallet.js b/js/controllers/homeWallet.js index 146fc2fae..f09bd182a 100644 --- a/js/controllers/homeWallet.js +++ b/js/controllers/homeWallet.js @@ -1,7 +1,7 @@ 'use strict'; -angular.module('copayApp.controllers').controller('HomeWalletController', - function($scope, $rootScope) { +angular.module('copayApp.controllers').controller('HomeWalletController', function($scope, $rootScope) { + $scope.init = function() { $rootScope.title = 'Home'; $scope.addr = _.last($rootScope.wallet.getReceiveAddresses()); @@ -9,5 +9,5 @@ angular.module('copayApp.controllers').controller('HomeWalletController', $rootScope.$watch('wallet', function() { $scope.addr = _.last($rootScope.wallet.getReceiveAddresses()); }); - } -); + }; +}); diff --git a/js/models/Identity.js b/js/models/Identity.js index d404fc9f3..a35a1446d 100644 --- a/js/models/Identity.js +++ b/js/models/Identity.js @@ -151,6 +151,7 @@ Identity.prototype.readAndBindWallet = function(walletId, cb) { var self = this; self.retrieveWalletFromStorage(walletId, {}, function(error, wallet) { if (!error) { + self.wallets[wallet.getId()] = wallet; self.bindWallet(wallet); } return cb(error); @@ -386,6 +387,8 @@ Identity.prototype.importWalletFromObj = function(obj, opts, cb) { log.debug('Updating Indexes for wallet:' + w.getName()); w.updateIndexes(function(err) { log.debug('Adding wallet to profile:' + w.getName()); + self.wallets[w.getId()] = w; + self.updateFocusedTimestamp(w.getId()); self.bindWallet(w); self.storeWallet(w, cb); }); @@ -472,7 +475,6 @@ Identity.importFromFullJson = function(str, password, opts, cb) { */ Identity.prototype.bindWallet = function(w) { var self = this; - self.wallets[w.getId()] = w; log.debug('Binding wallet:' + w.getName()); w.on('txProposalsUpdated', function() { @@ -572,8 +574,9 @@ Identity.prototype.createWallet = function(opts, cb) { var w = new walletClass(opts); - self.bindWallet(w); + self.wallets[w.getId()] = w; self.updateFocusedTimestamp(w.getId()); + self.bindWallet(w); self.storeWallet(w, function(err) { if (err) return cb(err); @@ -664,15 +667,16 @@ Identity.prototype.decodeSecret = function(secret) { * @return {string} walletId */ Identity.prototype.getLastFocusedWalletId = function() { - var max = _.max(this.focusedTimestamp); - var aId = _.findKey(this.wallets) || this.walletIds[0]; + if (this.walletIds.length == 0) return undefined; + + var max = _.max(this.focusedTimestamps); if (!max) - return aId; + return this.walletIds[0]; return _.findKey(this.focusedTimestamps, function(ts) { return ts == max; - }) || aId; + }) || this.walletIds[0]; }; Identity.prototype.updateFocusedTimestamp = function(wid) { diff --git a/views/homeWallet.html b/views/homeWallet.html index 5563d1fd5..798473247 100644 --- a/views/homeWallet.html +++ b/views/homeWallet.html @@ -1,4 +1,4 @@ -
+

Home