mirror of https://github.com/BTCPrivate/copay.git
commit
53e0371b7f
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -209,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
|
||||
});
|
||||
}
|
||||
|
@ -218,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();
|
||||
});
|
||||
|
|
|
@ -68,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 = [];
|
||||
|
|
|
@ -147,11 +147,13 @@ describe('PublicKeyRing model', function() {
|
|||
for (var i = 0; i < 2; i++)
|
||||
w.generateAddress(isChange);
|
||||
|
||||
var as = w.getAddresses();
|
||||
var as = w.getAddressesInfo();
|
||||
as.length.should.equal(4);
|
||||
for (var j in as) {
|
||||
var a = as[j];
|
||||
a.isValid().should.equal(true);
|
||||
a.address.isValid().should.equal(true);
|
||||
a.addressStr.should.equal(a.address.toString());
|
||||
a.isChange.should.equal([false, false, true, true][j]);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -94,7 +94,14 @@ describe("Unit: controllerUtils", function() {
|
|||
});
|
||||
}));
|
||||
|
||||
|
||||
it('should set the rootScope', inject(function(controllerUtils, $rootScope) {
|
||||
controllerUtils.setupRootVariables(function() {
|
||||
expect($rootScope.txAlertCount).to.be.equal(0);
|
||||
expect($rootScope.insightError).to.be.equal(0);
|
||||
expect($rootScope.isCollapsed).to.be.equal(0);
|
||||
expect($rootScope.unitName).to.be.equal('bits');
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
describe("Unit: Notification Service", function() {
|
||||
|
|
Loading…
Reference in New Issue