Browse Source

fetch new block notifications along with regular wallet notifications

activeAddress
Ivan Socolsky 9 years ago
parent
commit
5c048e390c
  1. 16
      lib/server.js
  2. 34
      test/integration/server.js

16
lib/server.js

@ -1660,9 +1660,21 @@ WalletService.prototype.getNotifications = function(opts, cb) {
var self = this;
opts = opts || {};
self.storage.fetchNotifications(self.walletId, opts.notificationId, opts.minTs || 0, function(err, notifications) {
self.getWallet({}, function(err, wallet) {
if (err) return cb(err);
return cb(null, notifications);
async.map([wallet.network, self.walletId], function(walletId, next) {
self.storage.fetchNotifications(walletId, opts.notificationId, opts.minTs || 0, next);
}, function(err, res) {
if (err) return cb(err);
var notifications = _.sortBy(_.map(_.flatten(res), function(n) {
n.walletId = self.walletId;
return n;
}), 'id');
return cb(null, notifications);
});
});
};

34
test/integration/server.js

@ -3923,6 +3923,38 @@ describe('Wallet service', function() {
});
});
it('should pull new block notifications along with wallet notifications in the last 60 seconds', function(done) {
// Simulate new block notification
server.walletId = 'livenet';
server._notify('NewBlock', {
hash: 'dummy hash',
}, {
isGlobal: true
}, function(err) {
should.not.exist(err);
server.walletId = 'testnet';
server._notify('NewBlock', {
hash: 'dummy hash',
}, {
isGlobal: true
}, function(err) {
should.not.exist(err);
server.walletId = wallet.id;
server.getNotifications({
minTs: +Date.now() - (60 * 1000),
}, function(err, notifications) {
should.not.exist(err);
var types = _.pluck(notifications, 'type');
types.should.deep.equal(['NewTxProposal', 'NewTxProposal', 'NewBlock']);
var walletIds = _.uniq(_.pluck(notifications, 'walletId'));
walletIds.length.should.equal(1);
walletIds[0].should.equal(wallet.id);
done();
});
});
});
});
it('should pull notifications in the last 60 seconds', function(done) {
server.getNotifications({
minTs: +Date.now() - (60 * 1000),
@ -4134,7 +4166,7 @@ describe('Wallet service', function() {
});
},
function(next) {
server.getNotifications({}, function(err, items) {
server.storage.fetchNotifications(wallet.id, null, 0, function(err, items) {
items.length.should.equal(0);
next();
});

Loading…
Cancel
Save