Merge pull request #1356 from isocolsky/bug/subscribe
Separated subscribeToAddresses from getAddressesInfo
This commit is contained in:
commit
bf3840f77c
5 changed files with 34 additions and 14 deletions
|
|
@ -1925,21 +1925,16 @@ Wallet.prototype.getAddressesStr = function(opts) {
|
|||
});
|
||||
};
|
||||
|
||||
Wallet.prototype.subscribeToAddresses = function() {
|
||||
var addrInfo = this.publicKeyRing.getAddressesInfo();
|
||||
this.blockchain.subscribe(_.pluck(addrInfo, 'addressStr'));
|
||||
};
|
||||
|
||||
/**
|
||||
* @desc Alias for {@link PublicKeyRing#getAddressesInfo}
|
||||
*/
|
||||
Wallet.prototype.getAddressesInfo = function(opts) {
|
||||
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;
|
||||
return this.publicKeyRing.getAddressesInfo(opts, this.publicKey);
|
||||
};
|
||||
/**
|
||||
* @desc Returns true if a given address was generated by deriving our master public key
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ angular.module('copayApp.services')
|
|||
}, 3000);
|
||||
});
|
||||
w.on('txProposalEvent', function(e) {
|
||||
|
||||
|
||||
var user = w.publicKeyRing.nicknameForCopayer(e.cId);
|
||||
switch (e.type) {
|
||||
case 'signed':
|
||||
|
|
@ -158,8 +158,10 @@ angular.module('copayApp.services')
|
|||
// TODO movie this to wallet
|
||||
root.updateAddressList = function() {
|
||||
var w = $rootScope.wallet;
|
||||
if (w && w.isReady())
|
||||
if (w && w.isReady()) {
|
||||
w.subscribeToAddresses();
|
||||
$rootScope.addrInfos = w.getAddressesInfo();
|
||||
}
|
||||
};
|
||||
|
||||
root.updateBalance = function(cb) {
|
||||
|
|
|
|||
|
|
@ -84,6 +84,8 @@ FakeWallet.prototype.getAddressesInfo = function() {
|
|||
return ret;
|
||||
};
|
||||
|
||||
FakeWallet.prototype.subscribeToAddresses = function() {};
|
||||
|
||||
FakeWallet.prototype.isShared = function() {
|
||||
return this.totalCopayers > 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
var _ = require('underscore');
|
||||
var chai = chai || require('chai');
|
||||
var should = chai.should();
|
||||
var sinon = require('sinon');
|
||||
|
|
@ -914,6 +915,22 @@ describe('Wallet model', function() {
|
|||
});
|
||||
});
|
||||
|
||||
describe('#subscribeToAddresses', function() {
|
||||
it('should subscribe successfully', function() {
|
||||
var w = cachedCreateW2();
|
||||
var addr1 = w.getAddresses()[0].toString();
|
||||
var addr2 = w.generateAddress().toString();
|
||||
var addr3 = w.generateAddress(true).toString();
|
||||
chai.expect(w.getAddresses().length).to.equal(3);
|
||||
|
||||
w.blockchain.subscribe = sinon.spy();
|
||||
w.subscribeToAddresses();
|
||||
w.blockchain.subscribe.calledOnce.should.equal(true);
|
||||
var arg = w.blockchain.subscribe.getCall(0).args[0];
|
||||
chai.expect(_.difference(arg, [addr1, addr2, addr3]).length).to.equal(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#send', function() {
|
||||
it('should call this.network.send', function() {
|
||||
var w = cachedCreateW2();
|
||||
|
|
|
|||
|
|
@ -113,7 +113,11 @@ describe('Unit: Rate Service', function() {
|
|||
beforeEach(module(function($provide) {
|
||||
$provide.value('request', {
|
||||
'get': function(_, cb) {
|
||||
cb(null, null, [{name: 'lol currency', code: 'LOL', rate: 2}]);
|
||||
cb(null, null, [{
|
||||
name: 'lol currency',
|
||||
code: 'LOL',
|
||||
rate: 2
|
||||
}]);
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue