use template for public tx url

This commit is contained in:
Ivan Socolsky 2015-07-13 12:52:28 -03:00
parent 4edb212c49
commit 20b3d50ef9
5 changed files with 21 additions and 9 deletions

View File

@ -55,6 +55,10 @@ var config = {
templatePath: './lib/templates',
defaultLanguage: 'en',
defaultUnit: 'btc',
publicTxUrlTemplate: {
livenet: 'https://insight.bitpay.com/tx/{{txid}}',
testnet: 'https://test-insight.bitpay.com/tx/{{txid}}',
},
},
};
module.exports = config;

View File

@ -108,8 +108,4 @@ Insight.prototype.initSocket = function() {
return socket;
};
Insight.prototype.getPublicUrlForTx = function(txid) {
return this.url + '/tx/' + txid;
};
module.exports = Insight;

View File

@ -69,6 +69,9 @@ EmailService.prototype.start = function(opts, cb) {
self.defaultLanguage = opts.emailOpts.defaultLanguage || 'en';
self.defaultUnit = opts.emailOpts.defaultUnit || 'btc';
self.templatePath = path.normalize((opts.emailOpts.templatePath || (__dirname + '/templates')) + '/');
self.publicTxUrlTemplate = opts.emailOpts.publicTxUrlTemplate || {};
self.subjectPrefix = opts.emailOpts.subjectPrefix || '[Wallet service]';
self.from = opts.emailOpts.from;
async.parallel([
@ -119,8 +122,6 @@ EmailService.prototype.start = function(opts, cb) {
},
function(done) {
self.mailer = opts.mailer || nodemailer.createTransport(opts.emailOpts);
self.subjectPrefix = opts.emailOpts.subjectPrefix || '[Wallet service]';
self.from = opts.emailOpts.from;
done();
},
], function(err) {
@ -255,8 +256,16 @@ EmailService.prototype._getDataForTemplate = function(notification, recipient, c
}
if (_.contains(['NewIncomingTx', 'NewOutgoingTx'], notification.type) && data.txid) {
data.urlForTx = self.explorers[wallet.network].getPublicUrlForTx(data.txid);
var urlTemplate = self.publicTxUrlTemplate[wallet.network];
if (urlTemplate) {
try {
data.urlForTx = Mustache.render(urlTemplate, data);
} catch (ex) {
log.warn('Could not render public url for tx', ex);
}
}
}
return cb(null, data);
});
};

View File

@ -20,7 +20,6 @@ describe('Blockchain explorer', function() {
exp.should.respondTo('getAddressActivity');
exp.should.respondTo('getUnspentUtxos');
exp.should.respondTo('initSocket');
exp.should.respondTo('getPublicUrlForTx');
var exp = new BlockchainExplorer({
provider: 'insight',
network: 'livenet',

View File

@ -340,6 +340,10 @@ describe('Wallet service', function() {
emailOpts: {
from: 'bws@dummy.net',
subjectPrefix: '[test wallet]',
publicTxUrlTemplate: {
livenet: 'https://insight.bitpay.com/tx/{{txid}}',
testnet: 'https://test-insight.bitpay.com/tx/{{txid}}',
},
},
}, function(err) {
should.not.exist(err);
@ -463,7 +467,7 @@ describe('Wallet service', function() {
one.text.should.contain(wallet.name);
one.text.should.contain('800,000');
should.exist(one.html);
one.html.should.contain('https://insight.bitpay.com:443/tx/999');
one.html.should.contain('https://insight.bitpay.com/tx/999');
server.storage.fetchUnsentEmails(function(err, unsent) {
should.not.exist(err);
unsent.should.be.empty;