refacor blockchain handlers

This commit is contained in:
Matias Alejo Garcia 2014-09-09 19:05:23 -03:00
commit dd8fcaa1b1
5 changed files with 17 additions and 23 deletions

View file

@ -9,7 +9,7 @@ angular.module('copayApp.controllers').controller('AddressesController',
$scope.loading = true; $scope.loading = true;
w.generateAddress(null, function() { w.generateAddress(null, function() {
$timeout(function() { $timeout(function() {
controllerUtils.updateGlobalAddresses(); controllerUtils.updateAddressList();
$scope.loading = false; $scope.loading = false;
}, 1); }, 1);
}); });

View file

@ -17,7 +17,7 @@ angular.module('copayApp.controllers').controller('CopayersController',
} }
$scope.goToWallet = function() { $scope.goToWallet = function() {
controllerUtils.updateGlobalAddresses(); controllerUtils.updateAddressList();
$location.path('/receive'); $location.path('/receive');
}; };

View file

@ -163,7 +163,7 @@ Insight.prototype.subscribe = function(addresses) {
}; };
Insight.prototype.getSubscriptions = function(addresses) { Insight.prototype.getSubscriptions = function(addresses) {
return Object.keys(this.subscribed); return this.subscribed;
} }
Insight.prototype.unsubscribe = function(addresses) { Insight.prototype.unsubscribe = function(addresses) {
@ -178,7 +178,7 @@ Insight.prototype.unsubscribe = function(addresses) {
}; };
Insight.prototype.unsubscribeAll = function() { Insight.prototype.unsubscribeAll = function() {
this.unsubscribe(this.getSubscriptions()); this.unsubscribe(Object.keys(this.subscribed));
}; };
Insight.prototype.broadcast = function(rawtx, cb) { Insight.prototype.broadcast = function(rawtx, cb) {

View file

@ -1887,7 +1887,17 @@ Wallet.prototype.getAddressesStr = function(opts) {
* @desc Alias for {@link PublicKeyRing#getAddressesInfo} * @desc Alias for {@link PublicKeyRing#getAddressesInfo}
*/ */
Wallet.prototype.getAddressesInfo = function(opts) { 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 * @desc Returns true if a given address was generated by deriving our master public key

View file

@ -64,7 +64,7 @@ angular.module('copayApp.services')
}); });
w.on('publicKeyRingUpdated', function(dontDigest) { w.on('publicKeyRingUpdated', function(dontDigest) {
root.updateGlobalAddresses(); root.updateAddressList();
if (!dontDigest) { if (!dontDigest) {
$rootScope.$digest(); $rootScope.$digest();
} }
@ -149,7 +149,7 @@ angular.module('copayApp.services')
root.startNetwork = function(w, $scope) { root.startNetwork = function(w, $scope) {
root.setupRootVariables(); root.setupRootVariables();
root.installWalletHandlers(w, $scope); root.installWalletHandlers(w, $scope);
root.updateGlobalAddresses(); root.updateAddressList();
notification.enableHtml5Mode(); // for chrome: if support, enable it notification.enableHtml5Mode(); // for chrome: if support, enable it
w.netStart(); 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; return root;
}); });