diff --git a/js/controllers/addresses.js b/js/controllers/addresses.js index d53ff8ae1..03f6f5408 100644 --- a/js/controllers/addresses.js +++ b/js/controllers/addresses.js @@ -9,7 +9,7 @@ angular.module('copayApp.controllers').controller('AddressesController', $scope.loading = true; w.generateAddress(null, function() { $timeout(function() { - controllerUtils.updateGlobalAddresses(); + controllerUtils.updateAddressList(); $scope.loading = false; }, 1); }); diff --git a/js/controllers/copayers.js b/js/controllers/copayers.js index b48c265c2..fc140593b 100644 --- a/js/controllers/copayers.js +++ b/js/controllers/copayers.js @@ -17,7 +17,7 @@ angular.module('copayApp.controllers').controller('CopayersController', } $scope.goToWallet = function() { - controllerUtils.updateGlobalAddresses(); + controllerUtils.updateAddressList(); $location.path('/receive'); }; diff --git a/js/models/blockchain/Insight.js b/js/models/blockchain/Insight.js index 14825963d..33429d004 100644 --- a/js/models/blockchain/Insight.js +++ b/js/models/blockchain/Insight.js @@ -163,7 +163,7 @@ Insight.prototype.subscribe = function(addresses) { }; Insight.prototype.getSubscriptions = function(addresses) { - return Object.keys(this.subscribed); + return this.subscribed; } Insight.prototype.unsubscribe = function(addresses) { @@ -178,7 +178,7 @@ Insight.prototype.unsubscribe = function(addresses) { }; Insight.prototype.unsubscribeAll = function() { - this.unsubscribe(this.getSubscriptions()); + this.unsubscribe(Object.keys(this.subscribed)); }; Insight.prototype.broadcast = function(rawtx, cb) { diff --git a/js/models/core/Wallet.js b/js/models/core/Wallet.js index 1b35a85ba..fa3429bb2 100644 --- a/js/models/core/Wallet.js +++ b/js/models/core/Wallet.js @@ -1887,7 +1887,17 @@ Wallet.prototype.getAddressesStr = function(opts) { * @desc Alias for {@link PublicKeyRing#getAddressesInfo} */ Wallet.prototype.getAddressesInfo = function(opts) { - return this.publicKeyRing.getAddressesInfo(opts, this.publicKey); + var addrInfo = this.publicKeyRing.getAddressesInfo(opts, this.publicKey); + var currentAddrs = this.blockchain.getSubscriptions(); + + var newAddrs = []; + for (var i in addrInfo) { + var a = addrInfo[i]; + if (!currentAddrs[a.addressStr] && !a.isChange) + newAddrs.push(a.addressStr); + } + this.blockchain.subscribe(newAddrs); + return addrInfo; }; /** * @desc Returns true if a given address was generated by deriving our master public key diff --git a/js/services/controllerUtils.js b/js/services/controllerUtils.js index acc9c6e9d..77f822a58 100644 --- a/js/services/controllerUtils.js +++ b/js/services/controllerUtils.js @@ -64,7 +64,7 @@ angular.module('copayApp.services') }); w.on('publicKeyRingUpdated', function(dontDigest) { - root.updateGlobalAddresses(); + root.updateAddressList(); if (!dontDigest) { $rootScope.$digest(); } @@ -149,7 +149,7 @@ angular.module('copayApp.services') root.startNetwork = function(w, $scope) { root.setupRootVariables(); root.installWalletHandlers(w, $scope); - root.updateGlobalAddresses(); + root.updateAddressList(); notification.enableHtml5Mode(); // for chrome: if support, enable it w.netStart(); }; @@ -273,21 +273,5 @@ angular.module('copayApp.services') }); } - // TODO Move this to wallet model! - root.updateGlobalAddresses = function() { - if (!$rootScope.wallet) return; - root.updateAddressList(); - var currentAddrs = $rootScope.wallet.blockchain.getSubscriptions(); - var allAddrs = $rootScope.addrInfos; - - var newAddrs = []; - for (var i in allAddrs) { - var a = allAddrs[i]; - if (!currentAddrs[a.addressStr] && !a.isChange) - newAddrs.push(a.addressStr); - } - - $rootScope.wallet.blockchain.subscribe(newAddrs); - }; return root; });