mirror of https://github.com/BTCPrivate/copay.git
fix address event subscription
This commit is contained in:
parent
88e6ea9f40
commit
792f48b2ea
|
@ -1,5 +1,4 @@
|
|||
'use strict';
|
||||
|
||||
var imports = require('soop').imports();
|
||||
|
||||
var http = require('http');
|
||||
|
|
|
@ -130,7 +130,6 @@ angular.module('copayApp.services')
|
|||
});
|
||||
|
||||
w.on('publicKeyRingUpdated', function(dontDigest) {
|
||||
root.updateAddressList();
|
||||
root.setSocketHandlers();
|
||||
if (!dontDigest) {
|
||||
$rootScope.$digest();
|
||||
|
@ -184,6 +183,7 @@ angular.module('copayApp.services')
|
|||
|
||||
root.updateAddressList = function() {
|
||||
var w = $rootScope.wallet;
|
||||
if (w)
|
||||
$rootScope.addrInfos = w.getAddressesInfo();
|
||||
};
|
||||
|
||||
|
@ -289,6 +289,7 @@ angular.module('copayApp.services')
|
|||
};
|
||||
|
||||
root.setSocketHandlers = function() {
|
||||
root.updateAddressList();
|
||||
if (!Socket.sysEventsSet) {
|
||||
Socket.sysOn('error', root._setCommError);
|
||||
Socket.sysOn('reconnect_error', root._setCommError);
|
||||
|
@ -315,7 +316,7 @@ angular.module('copayApp.services')
|
|||
Socket.on(a.addressStr, function(txid) {
|
||||
|
||||
if (!a.isChange)
|
||||
notification.funds('Received fund', a.addressStr);
|
||||
notification.funds('Funds received!', a.addressStr);
|
||||
|
||||
root.updateBalance(function() {
|
||||
$rootScope.$digest();
|
||||
|
|
|
@ -27,6 +27,7 @@ FakeWallet.prototype.getAddressesInfo = function() {
|
|||
for (var ii in this.balanceByAddr) {
|
||||
ret.push({
|
||||
address: ii,
|
||||
addressStr: ii,
|
||||
isChange: false,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -77,9 +77,9 @@ describe("Unit: controllerUtils", function() {
|
|||
scope = $rootScope.$new();
|
||||
|
||||
$rootScope.wallet = new FakeWallet();
|
||||
var addr = '1CjPR7Z5ZSyWk6WtXvSFgkptmpoi4UM9BC';
|
||||
var Waddr = Object.keys($rootScope.wallet.balanceByAddr)[0];
|
||||
var a = {};
|
||||
a[addr] = 100;
|
||||
a[Waddr] = 100;
|
||||
//SATs
|
||||
$rootScope.wallet.set(100000001, 90000002, a);
|
||||
|
||||
|
@ -90,7 +90,7 @@ describe("Unit: controllerUtils", function() {
|
|||
expect($rootScope.totalBalance).to.be.equal(1000000.01);
|
||||
expect($rootScope.availableBalance).to.be.equal(900000.02);
|
||||
expect($rootScope.addrInfos).not.to.equal(null);
|
||||
expect($rootScope.addrInfos[0].address).to.equal(addr);
|
||||
expect($rootScope.addrInfos[0].address).to.equal(Waddr);
|
||||
});
|
||||
}));
|
||||
|
||||
|
@ -102,6 +102,42 @@ describe("Unit: controllerUtils", function() {
|
|||
expect($rootScope.unitName).to.be.equal('bits');
|
||||
});
|
||||
}));
|
||||
describe("Unit: controllerUtils #setSocketHandlers", function() {
|
||||
|
||||
|
||||
it(' should call updateAddressList ', inject(function(controllerUtils, $rootScope) {
|
||||
var spy = sinon.spy(controllerUtils, 'updateAddressList');
|
||||
controllerUtils.setSocketHandlers();
|
||||
sinon.assert.callCount(spy, 1);
|
||||
}));
|
||||
|
||||
it('should update addresses', inject(function(controllerUtils, $rootScope) {
|
||||
$rootScope.wallet = new FakeWallet();
|
||||
var Waddr = Object.keys($rootScope.wallet.balanceByAddr)[0];
|
||||
controllerUtils.setSocketHandlers();
|
||||
expect($rootScope.addrInfos[0].address).to.be.equal(Waddr);;
|
||||
}));
|
||||
|
||||
it('should set System Event Handlers', inject(function(controllerUtils, $rootScope, Socket) {
|
||||
var spy = sinon.spy(Socket, 'sysOn');
|
||||
$rootScope.wallet = new FakeWallet();
|
||||
controllerUtils.setSocketHandlers();
|
||||
sinon.assert.callCount(spy, 5);
|
||||
['error', 'reconnect_error', 'reconnect_failed', 'connect', 'reconnect'].forEach(function(e) {
|
||||
sinon.assert.calledWith(spy, e);
|
||||
});
|
||||
}));
|
||||
|
||||
it('should set Address Event Handlers', inject(function(controllerUtils, $rootScope, Socket) {
|
||||
var spy = sinon.spy(Socket, 'on');
|
||||
$rootScope.wallet = new FakeWallet();
|
||||
var Waddr = Object.keys($rootScope.wallet.balanceByAddr)[0];
|
||||
controllerUtils.setSocketHandlers();
|
||||
sinon.assert.calledWith(spy, Waddr);
|
||||
}));
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
describe("Unit: Notification Service", function() {
|
||||
|
|
Loading…
Reference in New Issue