return after generating notification
This commit is contained in:
parent
bef20234f1
commit
1422107c6e
|
@ -260,8 +260,7 @@ WalletService.prototype.replaceTemporaryRequestKey = function(opts, cb) {
|
|||
walletId: opts.walletId,
|
||||
copayerId: self.copayerId,
|
||||
copayerName: opts.name,
|
||||
});
|
||||
|
||||
}, false, function() {
|
||||
return cb(null, {
|
||||
copayerId: self.copayerId,
|
||||
wallet: wallet
|
||||
|
@ -269,6 +268,7 @@ WalletService.prototype.replaceTemporaryRequestKey = function(opts, cb) {
|
|||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -297,7 +297,7 @@ WalletService.prototype._emit = function(eventName, args) {
|
|||
* @param {Object} data
|
||||
* @param {Boolean} isGlobal - If true, the notification is not issued on behalf of any particular copayer (defaults to false)
|
||||
*/
|
||||
WalletService.prototype._notify = function(type, data, isGlobal) {
|
||||
WalletService.prototype._notify = function(type, data, isGlobal, cb) {
|
||||
var self = this;
|
||||
|
||||
log.debug('Notification', type, data);
|
||||
|
@ -316,6 +316,7 @@ WalletService.prototype._notify = function(type, data, isGlobal) {
|
|||
});
|
||||
this.storage.storeNotification(walletId, n, function() {
|
||||
self._emit('notification', n);
|
||||
if (cb) return cb();
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -379,7 +380,7 @@ WalletService.prototype.joinWallet = function(opts, cb) {
|
|||
walletId: opts.walletId,
|
||||
copayerId: copayer.id,
|
||||
copayerName: copayer.name,
|
||||
});
|
||||
}, false, function() {
|
||||
return cb(null, {
|
||||
copayerId: copayer.id,
|
||||
wallet: wallet
|
||||
|
@ -388,6 +389,7 @@ WalletService.prototype.joinWallet = function(opts, cb) {
|
|||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -411,11 +413,12 @@ WalletService.prototype.createAddress = function(opts, cb) {
|
|||
|
||||
self._notify('NewAddress', {
|
||||
address: address.address,
|
||||
});
|
||||
}, false, function() {
|
||||
return cb(null, address);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -710,13 +713,14 @@ WalletService.prototype.createTx = function(opts, cb) {
|
|||
|
||||
self._notify('NewTxProposal', {
|
||||
amount: opts.amount
|
||||
});
|
||||
}, false, function() {
|
||||
return cb(null, txp);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -783,10 +787,11 @@ WalletService.prototype.removePendingTx = function(opts, cb) {
|
|||
if (actors.length > 1 || (actors.length == 1 && actors[0] !== self.copayerId))
|
||||
return cb(new ClientError('TXACTIONED', 'Cannot remove a proposal signed/rejected by other copayers'));
|
||||
|
||||
self._notify('TxProposalRemoved');
|
||||
self._notify('TxProposalRemoved', {}, false, function() {
|
||||
self.storage.removeTx(self.walletId, txp.id, cb);
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
@ -839,21 +844,29 @@ WalletService.prototype.signTx = function(opts, cb) {
|
|||
self.storage.storeTx(self.walletId, txp, function(err) {
|
||||
if (err) return cb(err);
|
||||
|
||||
async.parallel([
|
||||
|
||||
function(done) {
|
||||
self._notify('TxProposalAcceptedBy', {
|
||||
txProposalId: opts.txProposalId,
|
||||
copayerId: self.copayerId,
|
||||
});
|
||||
|
||||
}, false, done);
|
||||
},
|
||||
function(done) {
|
||||
if (txp.isAccepted()) {
|
||||
self._notify('TxProposalFinallyAccepted', {
|
||||
txProposalId: opts.txProposalId,
|
||||
});
|
||||
}, false, done);
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
|
||||
},
|
||||
], function() {
|
||||
return cb(null, txp);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
@ -892,13 +905,13 @@ WalletService.prototype.broadcastTx = function(opts, cb) {
|
|||
self._notify('NewOutgoingTx', {
|
||||
txProposalId: opts.txProposalId,
|
||||
txid: txid
|
||||
});
|
||||
|
||||
}, false, function() {
|
||||
return cb(null, txp);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -932,21 +945,28 @@ WalletService.prototype.rejectTx = function(opts, cb) {
|
|||
self.storage.storeTx(self.walletId, txp, function(err) {
|
||||
if (err) return cb(err);
|
||||
|
||||
async.parallel([
|
||||
|
||||
function(done) {
|
||||
self._notify('TxProposalRejectedBy', {
|
||||
txProposalId: opts.txProposalId,
|
||||
copayerId: self.copayerId,
|
||||
});
|
||||
|
||||
|
||||
}, false, done);
|
||||
},
|
||||
function(done) {
|
||||
if (txp.status == 'rejected') {
|
||||
self._notify('TxProposalFinallyRejected', {
|
||||
txProposalId: opts.txProposalId,
|
||||
});
|
||||
};
|
||||
|
||||
}, false, done);
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
},
|
||||
], function() {
|
||||
return cb(null, txp);
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -3014,7 +3014,6 @@ describe('Wallet service', function() {
|
|||
should.not.exist(err);
|
||||
var copayerId2 = result.copayerId;
|
||||
|
||||
|
||||
helpers.getAuthServer(copayerId, function(server) {
|
||||
server.getWallet({}, function(err, wallet) {
|
||||
|
||||
|
|
Loading…
Reference in New Issue