From 20b3d50ef97feb802d0bcc189d18cde88fa3957f Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Mon, 13 Jul 2015 12:52:28 -0300 Subject: [PATCH] use template for public tx url --- config.js | 4 ++++ lib/blockchainexplorers/insight.js | 4 ---- lib/emailservice.js | 15 ++++++++++++--- test/blockchainexplorer.js | 1 - test/integration/server.js | 6 +++++- 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/config.js b/config.js index 22128a1..5546ab9 100644 --- a/config.js +++ b/config.js @@ -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; diff --git a/lib/blockchainexplorers/insight.js b/lib/blockchainexplorers/insight.js index e436c9c..f11e901 100644 --- a/lib/blockchainexplorers/insight.js +++ b/lib/blockchainexplorers/insight.js @@ -108,8 +108,4 @@ Insight.prototype.initSocket = function() { return socket; }; -Insight.prototype.getPublicUrlForTx = function(txid) { - return this.url + '/tx/' + txid; -}; - module.exports = Insight; diff --git a/lib/emailservice.js b/lib/emailservice.js index 7252efe..b05bb07 100644 --- a/lib/emailservice.js +++ b/lib/emailservice.js @@ -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); }); }; diff --git a/test/blockchainexplorer.js b/test/blockchainexplorer.js index 0431c5a..097dfa0 100644 --- a/test/blockchainexplorer.js +++ b/test/blockchainexplorer.js @@ -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', diff --git a/test/integration/server.js b/test/integration/server.js index 546f39d..3d8a92d 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -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;