Browse Source

add walletId to notification model

activeAddress
Ivan Socolsky 10 years ago
parent
commit
ef45a97e5b
  1. 2
      lib/model/notification.js
  2. 7
      lib/server.js
  3. 4
      test/integration/server.js

2
lib/model/notification.js

@ -37,6 +37,7 @@ Notification.create = function(opts) {
x.id = _.padLeft(now, 14, '0') + _.padLeft(opts.ticker || 0, 4, '0'); x.id = _.padLeft(now, 14, '0') + _.padLeft(opts.ticker || 0, 4, '0');
x.type = opts.type || 'general'; x.type = opts.type || 'general';
x.data = opts.data; x.data = opts.data;
x.walletId = opts.walletId;
x.creatorId = opts.creatorId; x.creatorId = opts.creatorId;
return x; return x;
@ -49,6 +50,7 @@ Notification.fromObj = function(obj) {
x.id = obj.id; x.id = obj.id;
x.type = obj.type, x.type = obj.type,
x.data = obj.data; x.data = obj.data;
x.walletId = obj.walletId;
x.creatorId = obj.creatorId; x.creatorId = obj.creatorId;
return x; return x;

7
lib/server.js

@ -189,6 +189,7 @@ WalletService.prototype._notify = function(type, data) {
data: data, data: data,
ticker: this.notifyTicker++, ticker: this.notifyTicker++,
creatorId: self.copayerId, creatorId: self.copayerId,
walletId: walletId,
}); });
this.storage.storeNotification(walletId, n, function() { this.storage.storeNotification(walletId, n, function() {
self._emit('notification', n); self._emit('notification', n);
@ -351,13 +352,13 @@ WalletService.prototype._getBlockExplorer = function(provider, network) {
return this.blockExplorer; return this.blockExplorer;
switch (provider) { switch (provider) {
default:; default: ;
case 'insight': case 'insight':
switch (network) { switch (network) {
default: default:
case 'livenet': case 'livenet':
url = 'https://insight.bitpay.com:443'; url = 'https://insight.bitpay.com:443';
break; break;
case 'testnet': case 'testnet':
url = 'https://test-insight.bitpay.com:443' url = 'https://test-insight.bitpay.com:443'
break; break;

4
test/integration/server.js

@ -1611,6 +1611,7 @@ describe('Copay server', function() {
should.not.exist(err); should.not.exist(err);
var last = _.last(notifications); var last = _.last(notifications);
last.type.should.equal('TxProposalFinallyAccepted'); last.type.should.equal('TxProposalFinallyAccepted');
last.walletId.should.equal(wallet.id);
last.creatorId.should.equal(wallet.copayers[1].id); last.creatorId.should.equal(wallet.copayers[1].id);
last.data.txProposalId.should.equal(txp.id); last.data.txProposalId.should.equal(txp.id);
done(); done();
@ -1869,6 +1870,9 @@ describe('Copay server', function() {
should.not.exist(err); should.not.exist(err);
var types = _.pluck(notifications, 'type'); var types = _.pluck(notifications, 'type');
types.should.deep.equal(['NewTxProposal', 'NewTxProposal', 'NewTxProposal', 'NewAddress']); types.should.deep.equal(['NewTxProposal', 'NewTxProposal', 'NewTxProposal', 'NewAddress']);
var walletIds = _.uniq(_.pluck(notifications, 'walletId'));
walletIds.length.should.equal(1);
walletIds[0].should.equal(wallet.id);
var creators = _.uniq(_.pluck(notifications, 'creatorId')); var creators = _.uniq(_.pluck(notifications, 'creatorId'));
creators.length.should.equal(1); creators.length.should.equal(1);
creators[0].should.equal(wallet.copayers[0].id); creators[0].should.equal(wallet.copayers[0].id);

Loading…
Cancel
Save