add details to txp related notifications

This commit is contained in:
Ivan Socolsky 2016-09-01 17:43:41 -03:00
parent 3fdc6485c0
commit 270d40f50e
No known key found for this signature in database
GPG Key ID: FAECE6A05FAA4F56
2 changed files with 31 additions and 23 deletions

View File

@ -457,6 +457,23 @@ WalletService.prototype._notify = function(type, data, opts, cb) {
};
WalletService.prototype._notifyTxProposalAction = function(type, txp, extraArgs, cb) {
var self = this;
if (_.isFunction(extraArgs)) {
cb = extraArgs;
extraArgs = {};
}
var data = _.assign({
txProposalId: txp.id,
creatorId: txp.creatorId,
amount: txp.getTotalAmount(),
message: txp.message,
}, extraArgs);
self._notify(type, data, {}, cb);
};
WalletService.prototype._addCopayerToWallet = function(wallet, opts, cb) {
var self = this;
@ -1991,11 +2008,7 @@ WalletService.prototype.publishTx = function(opts, cb) {
self.storage.storeTx(self.walletId, txp, function(err) {
if (err) return cb(err);
self._notify('NewTxProposal', {
amount: txp.getTotalAmount(),
txProposalId: txp.id,
message: txp.message,
}, function() {
self._notifyTxProposalAction('NewTxProposal', txp, function() {
return cb(null, txp);
});
});
@ -2144,7 +2157,7 @@ WalletService.prototype.removePendingTx = function(opts, cb) {
if (deleteLockTime > 0) return cb(Errors.TX_CANNOT_REMOVE);
self.storage.removeTx(self.walletId, txp.id, function() {
self._notify('TxProposalRemoved', {}, cb);
self._notifyTxProposalAction('TxProposalRemoved', txp, cb);
});
});
});
@ -2236,16 +2249,13 @@ WalletService.prototype.signTx = function(opts, cb) {
async.series([
function(next) {
self._notify('TxProposalAcceptedBy', {
txProposalId: opts.txProposalId,
self._notifyTxProposalAction('TxProposalAcceptedBy', txp, {
copayerId: self.copayerId,
}, next);
},
function(next) {
if (txp.isAccepted()) {
self._notify('TxProposalFinallyAccepted', {
txProposalId: opts.txProposalId,
}, next);
self._notifyTxProposalAction('TxProposalFinallyAccepted', txp, next);
} else {
next();
}
@ -2267,16 +2277,13 @@ WalletService.prototype._processBroadcast = function(txp, opts, cb) {
self.storage.storeTx(self.walletId, txp, function(err) {
if (err) return cb(err);
var args = {
txProposalId: txp.id,
var extraArgs = {
txid: txp.txid,
amount: txp.getTotalAmount(),
};
if (opts.byThirdParty) {
self._notify('NewOutgoingTxByThirdParty', args);
self._notifyTxProposalAction('NewOutgoingTxByThirdParty', txp, extraArgs);
} else {
self._notify('NewOutgoingTx', args);
self._notifyTxProposalAction('NewOutgoingTx', txp, extraArgs);
}
self.storage.softResetTxHistoryCache(self.walletId, function() {
@ -2369,8 +2376,7 @@ WalletService.prototype.rejectTx = function(opts, cb) {
async.series([
function(next) {
self._notify('TxProposalRejectedBy', {
txProposalId: opts.txProposalId,
self._notifyTxProposalAction('TxProposalRejectedBy', txp, {
copayerId: self.copayerId,
}, next);
},
@ -2380,8 +2386,7 @@ WalletService.prototype.rejectTx = function(opts, cb) {
type: 'reject'
}), 'copayerId');
self._notify('TxProposalFinallyRejected', {
txProposalId: opts.txProposalId,
self._notifyTxProposalAction('TxProposalFinallyRejected', txp, {
rejectedBy: rejectedBy,
}, next);
} else {

View File

@ -2606,11 +2606,14 @@ describe('Wallet service', function() {
server.getNotifications({}, function(err, notifications) {
should.not.exist(err);
var n = _.find(notifications, {'type': 'NewTxProposal'});
var n = _.find(notifications, {
'type': 'NewTxProposal'
});
should.exist(n);
should.exist(n.data.txProposalId);
should.exist(n.data.message);
should.exist(n.data.creatorId);
n.data.creatorId.should.equal(server.copayerId);
done();
});
});