small refactor on rootScope
This commit is contained in:
parent
621dcc1d09
commit
1abf1dc90d
4 changed files with 130 additions and 87 deletions
|
|
@ -31,8 +31,8 @@ angular.module('copayApp.controllers').controller('AddressesController',
|
|||
for (var i = 0; i < addrInfos.length; i++) {
|
||||
var addrinfo = addrInfos[i];
|
||||
$scope.addresses.push({
|
||||
'address' : addrinfo.address.toString(),
|
||||
'balance' : $rootScope.balanceByAddr ? $rootScope.balanceByAddr[addrinfo.address.toString()] : 0,
|
||||
'address': addrinfo.addressStr,
|
||||
'balance': $rootScope.balanceByAddr ? $rootScope.balanceByAddr[addrinfo.addressStr] : 0,
|
||||
'isChange': addrinfo.isChange
|
||||
});
|
||||
}
|
||||
|
|
@ -41,5 +41,4 @@ angular.module('copayApp.controllers').controller('AddressesController',
|
|||
$rootScope.receivedFund = null;
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
|
||||
|
|
@ -90,7 +89,9 @@ PublicKeyRing.prototype._checkKeys = function() {
|
|||
};
|
||||
|
||||
PublicKeyRing.prototype._newExtendedPublicKey = function() {
|
||||
return new PrivateKey({networkName: this.network.name})
|
||||
return new PrivateKey({
|
||||
networkName: this.network.name
|
||||
})
|
||||
.deriveBIP45Branch()
|
||||
.extendedPublicKeyString();
|
||||
};
|
||||
|
|
@ -147,10 +148,13 @@ PublicKeyRing.prototype.getPubKeys = function(index, isChange) {
|
|||
var hk = this.copayersHK[i].derive(path);
|
||||
pubKeys[i] = hk.eckey.public;
|
||||
}
|
||||
this.publicKeysCache[path] = pubKeys.map(function(pk){return pk.toString('hex');});
|
||||
}
|
||||
else {
|
||||
pubKeys = pubKeys.map(function(s){return new Buffer(s,'hex');});
|
||||
this.publicKeysCache[path] = pubKeys.map(function(pk) {
|
||||
return pk.toString('hex');
|
||||
});
|
||||
} else {
|
||||
pubKeys = pubKeys.map(function(s) {
|
||||
return new Buffer(s, 'hex');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -205,8 +209,10 @@ PublicKeyRing.prototype.getAddressesInfo = function(opts) {
|
|||
var ret = [];
|
||||
if (!opts.excludeChange) {
|
||||
for (var i = 0; i < this.indexes.getChangeIndex(); i++) {
|
||||
var a = this.getAddress(i, true);
|
||||
ret.unshift({
|
||||
address: this.getAddress(i, true),
|
||||
addressStr: a.toString(),
|
||||
isChange: true
|
||||
});
|
||||
}
|
||||
|
|
@ -214,8 +220,10 @@ PublicKeyRing.prototype.getAddressesInfo = function(opts) {
|
|||
|
||||
if (!opts.excludeMain) {
|
||||
for (var i = 0; i < this.indexes.getReceiveIndex(); i++) {
|
||||
var a = this.getAddress(i, false);
|
||||
ret.unshift({
|
||||
address: this.getAddress(i,false),
|
||||
address: a,
|
||||
addressStr: a.toString(),
|
||||
isChange: false
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ angular.module('copayApp.services')
|
|||
};
|
||||
|
||||
root.logout = function() {
|
||||
Socket.removeAllListeners();
|
||||
|
||||
$rootScope.wallet = null;
|
||||
delete $rootScope['wallet'];
|
||||
video.close();
|
||||
|
|
@ -70,10 +72,35 @@ angular.module('copayApp.services')
|
|||
});
|
||||
};
|
||||
|
||||
root.setupRootVariables = function() {
|
||||
$rootScope.unitName = config.unitName;
|
||||
$rootScope.txAlertCount = 0;
|
||||
$rootScope.insightError = 0;
|
||||
$rootScope.isCollapsed = true;
|
||||
$rootScope.$watch('insightError', function(status) {
|
||||
if (status === -1) {
|
||||
$rootScope.$flashMessage = {
|
||||
type: 'success',
|
||||
message: 'Networking Restored :)',
|
||||
};
|
||||
$rootScope.insightError = 0;
|
||||
}
|
||||
});
|
||||
|
||||
$rootScope.$watch('txAlertCount', function(txAlertCount) {
|
||||
if (txAlertCount && txAlertCount > 0) {
|
||||
notification.info('New Transaction', ($rootScope.txAlertCount == 1) ? 'You have a pending transaction proposal' : 'You have ' + $rootScope.txAlertCount + ' pending transaction proposals', txAlertCount);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
root.startNetwork = function(w, $scope) {
|
||||
Socket.removeAllListeners();
|
||||
|
||||
root.setupRootVariables();
|
||||
root.installStartupHandlers(w, $scope);
|
||||
root.setSocketHandlers();
|
||||
|
||||
var handlePeerVideo = function(err, peerID, url) {
|
||||
if (err) {
|
||||
|
|
@ -103,8 +130,8 @@ angular.module('copayApp.services')
|
|||
});
|
||||
|
||||
w.on('publicKeyRingUpdated', function(dontDigest) {
|
||||
root.setSocketHandlers();
|
||||
root.updateAddressList();
|
||||
root.setSocketHandlers();
|
||||
if (!dontDigest) {
|
||||
$rootScope.$digest();
|
||||
}
|
||||
|
|
@ -273,20 +300,23 @@ angular.module('copayApp.services')
|
|||
if (!$rootScope.wallet) return;
|
||||
|
||||
var currentAddrs = Socket.getListeners();
|
||||
var addrs = $rootScope.wallet.getAddressesStr();
|
||||
var allAddrs = $rootScope.addrInfos;
|
||||
|
||||
var newAddrs = [];
|
||||
for (var i in addrs) {
|
||||
var a = addrs[i];
|
||||
if (!currentAddrs[a])
|
||||
for (var i in allAddrs) {
|
||||
var a = allAddrs[i];
|
||||
if (!currentAddrs[a.addressStr])
|
||||
newAddrs.push(a);
|
||||
}
|
||||
for (var i = 0; i < newAddrs.length; i++) {
|
||||
Socket.emit('subscribe', newAddrs[i]);
|
||||
Socket.emit('subscribe', newAddrs[i].addressStr);
|
||||
}
|
||||
newAddrs.forEach(function(addr) {
|
||||
Socket.on(addr, function(txid) {
|
||||
$rootScope.receivedFund = [txid, addr];
|
||||
newAddrs.forEach(function(a) {
|
||||
Socket.on(a.addressStr, function(txid) {
|
||||
|
||||
if (!a.isChange)
|
||||
notification.funds('Received fund', a.addressStr);
|
||||
|
||||
root.updateBalance(function() {
|
||||
$rootScope.$digest();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -38,8 +38,12 @@ angular.module('copayApp.services').factory('Socket',
|
|||
var ret = {};
|
||||
|
||||
var addrList = listeners
|
||||
.filter(function(i) { return i.event != 'block'; })
|
||||
.map(function(i) {return i.event;});
|
||||
.filter(function(i) {
|
||||
return i.event != 'block';
|
||||
})
|
||||
.map(function(i) {
|
||||
return i.event;
|
||||
});
|
||||
|
||||
for (var i in addrList) {
|
||||
ret[addrList[i]] = 1;
|
||||
|
|
@ -47,7 +51,9 @@ angular.module('copayApp.services').factory('Socket',
|
|||
return ret;
|
||||
},
|
||||
isListeningBlocks: function() {
|
||||
return listeners.filter(function(i) { return i.event == 'block'; }).length > 0;
|
||||
return listeners.filter(function(i) {
|
||||
return i.event == 'block';
|
||||
}).length > 0;
|
||||
},
|
||||
emit: function(event, data, callback) {
|
||||
socket.emit(event, data, function() {
|
||||
|
|
@ -62,7 +68,7 @@ angular.module('copayApp.services').factory('Socket',
|
|||
removeAllListeners: function() {
|
||||
for (var i = 0; i < listeners.length; i++) {
|
||||
var details = listeners[i];
|
||||
socket.removeListener(details.event, details.fn);
|
||||
socket.removeAllListeners(details.event);
|
||||
}
|
||||
|
||||
listeners = [];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue