Browse Source

Merge pull request #209 from isocolsky/notify_wallet_complete

Notify wallet complete
activeAddress
Matias Alejo Garcia 10 years ago
parent
commit
52a794bc0e
  1. 4
      lib/emailservice.js
  2. 51
      lib/server.js
  3. 2
      lib/templates/wallet_complete.plain
  4. 1
      package.json
  5. 40
      test/integration/server.js

4
lib/emailservice.js

@ -15,6 +15,10 @@ var EMAIL_TYPES = {
filename: 'new_copayer', filename: 'new_copayer',
notifyDoer: false, notifyDoer: false,
}, },
'WalletComplete': {
filename: 'wallet_complete',
notifyDoer: true,
},
'NewTxProposal': { 'NewTxProposal': {
filename: 'new_tx_proposal', filename: 'new_tx_proposal',
notifyDoer: false, notifyDoer: false,

51
lib/server.js

@ -423,11 +423,28 @@ WalletService.prototype.joinWallet = function(opts, cb) {
self.storage.storeWalletAndUpdateCopayersLookup(wallet, function(err) { self.storage.storeWalletAndUpdateCopayersLookup(wallet, function(err) {
if (err) return cb(err); if (err) return cb(err);
self._notify('NewCopayer', {
walletId: opts.walletId, async.series([
copayerId: copayer.id,
copayerName: copayer.name, function(next) {
}, function() { self._notify('NewCopayer', {
walletId: opts.walletId,
copayerId: copayer.id,
copayerName: copayer.name,
}, next);
},
function(next) {
if (wallet.isComplete() && wallet.isShared()) {
self._notify('WalletComplete', {
walletId: opts.walletId,
}, {
isGlobal: true
}, next);
} else {
next();
}
},
], function() {
return cb(null, { return cb(null, {
copayerId: copayer.id, copayerId: copayer.id,
wallet: wallet wallet: wallet
@ -934,21 +951,21 @@ WalletService.prototype.signTx = function(opts, cb) {
self.storage.storeTx(self.walletId, txp, function(err) { self.storage.storeTx(self.walletId, txp, function(err) {
if (err) return cb(err); if (err) return cb(err);
async.parallel([ async.series([
function(done) { function(next) {
self._notify('TxProposalAcceptedBy', { self._notify('TxProposalAcceptedBy', {
txProposalId: opts.txProposalId, txProposalId: opts.txProposalId,
copayerId: self.copayerId, copayerId: self.copayerId,
}, done); }, next);
}, },
function(done) { function(next) {
if (txp.isAccepted()) { if (txp.isAccepted()) {
self._notify('TxProposalFinallyAccepted', { self._notify('TxProposalFinallyAccepted', {
txProposalId: opts.txProposalId, txProposalId: opts.txProposalId,
}, done); }, next);
} else { } else {
done(); next();
} }
}, },
], function() { ], function() {
@ -1035,21 +1052,21 @@ WalletService.prototype.rejectTx = function(opts, cb) {
self.storage.storeTx(self.walletId, txp, function(err) { self.storage.storeTx(self.walletId, txp, function(err) {
if (err) return cb(err); if (err) return cb(err);
async.parallel([ async.series([
function(done) { function(next) {
self._notify('TxProposalRejectedBy', { self._notify('TxProposalRejectedBy', {
txProposalId: opts.txProposalId, txProposalId: opts.txProposalId,
copayerId: self.copayerId, copayerId: self.copayerId,
}, done); }, next);
}, },
function(done) { function(next) {
if (txp.status == 'rejected') { if (txp.status == 'rejected') {
self._notify('TxProposalFinallyRejected', { self._notify('TxProposalFinallyRejected', {
txProposalId: opts.txProposalId, txProposalId: opts.txProposalId,
}, done); }, next);
} else { } else {
done(); next();
} }
}, },
], function() { ], function() {

2
lib/templates/wallet_complete.plain

@ -0,0 +1,2 @@
<%= subjectPrefix %>Wallet complete
Your wallet <%= walletName %> is complete.

1
package.json

@ -31,6 +31,7 @@
"locker-server": "^0.1.3", "locker-server": "^0.1.3",
"lodash": "^3.3.1", "lodash": "^3.3.1",
"mocha-lcov-reporter": "0.0.1", "mocha-lcov-reporter": "0.0.1",
"moment": "^2.10.3",
"mongodb": "^2.0.27", "mongodb": "^2.0.27",
"morgan": "*", "morgan": "*",
"nodemailer": "^1.3.4", "nodemailer": "^1.3.4",

40
test/integration/server.js

@ -478,7 +478,22 @@ describe('Wallet service', function() {
var copayer = wallet.copayers[0]; var copayer = wallet.copayers[0];
copayer.name.should.equal('me'); copayer.name.should.equal('me');
copayer.id.should.equal(copayerId); copayer.id.should.equal(copayerId);
done(); server.getNotifications({}, function(err, notifications) {
should.not.exist(err);
var notif = _.find(notifications, {
type: 'NewCopayer'
});
should.exist(notif);
notif.data.walletId.should.equal(walletId);
notif.data.copayerId.should.equal(copayerId);
notif.data.copayerName.should.equal('me');
notif = _.find(notifications, {
type: 'WalletComplete'
});
should.not.exist(notif);
done();
});
}); });
}); });
}); });
@ -548,7 +563,7 @@ describe('Wallet service', function() {
}); });
}); });
it('should fail two wallets with same xPubKey', function(done) { it('should fail to join two wallets with same xPubKey', function(done) {
var copayerOpts = helpers.getSignedCopayerOpts({ var copayerOpts = helpers.getSignedCopayerOpts({
walletId: walletId, walletId: walletId,
name: 'me', name: 'me',
@ -630,6 +645,27 @@ describe('Wallet service', function() {
should.not.exist(err); should.not.exist(err);
wallet.status.should.equal('complete'); wallet.status.should.equal('complete');
wallet.publicKeyRing.length.should.equal(3); wallet.publicKeyRing.length.should.equal(3);
server.getNotifications({}, function(err, notifications) {
should.not.exist(err);
var notif = _.find(notifications, {
type: 'WalletComplete'
});
should.exist(notif);
notif.data.walletId.should.equal(wallet.id);
done();
});
});
});
});
it('should not notify WalletComplete if 1-of-1', function(done) {
helpers.createAndJoinWallet(1, 1, function(server) {
server.getNotifications({}, function(err, notifications) {
should.not.exist(err);
var notif = _.find(notifications, {
type: 'WalletComplete'
});
should.not.exist(notif);
done(); done();
}); });
}); });

Loading…
Cancel
Save