refacor blockchain handlers

This commit is contained in:
Matias Alejo Garcia 2014-09-09 19:05:23 -03:00
parent 1c5b59a263
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;
w.generateAddress(null, function() {
$timeout(function() {
controllerUtils.updateGlobalAddresses();
controllerUtils.updateAddressList();
$scope.loading = false;
}, 1);
});

View File

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

View File

@ -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) {

View File

@ -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

View File

@ -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;
});