From cbb1645369761326d86588d8a947af85342eecf0 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Tue, 30 Jun 2015 18:16:08 -0300 Subject: [PATCH 1/2] try catch on formatAmount --- lib/emailservice.js | 6 +++++- package.json | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/emailservice.js b/lib/emailservice.js index a0b9387..f3cfd7e 100644 --- a/lib/emailservice.js +++ b/lib/emailservice.js @@ -193,7 +193,11 @@ EmailService.prototype._getDataForTemplate = function(notification, recipient, c var data = _.cloneDeep(notification.data); data.subjectPrefix = _.trim(self.subjectPrefix) + ' '; if (data.amount) { - data.amount = WalletUtils.formatAmount(+data.amount, recipient.unit) + ' ' + recipient.unit; + try { + data.amount = WalletUtils.formatAmount(+data.amount, recipient.unit) + ' ' + recipient.unit; + } catch (ex) { + return cb(new Error('Could not format amount', ex)); + } } self.storage.fetchWallet(notification.walletId, function(err, wallet) { if (err) return cb(err); diff --git a/package.json b/package.json index e9dd0bf..77f8221 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "bitcore-wallet-service", "description": "A service for Mutisig HD Bitcoin Wallets", "author": "BitPay Inc", - "version": "0.0.39", + "version": "0.0.40", "keywords": [ "bitcoin", "copay", From 9c98502969089944643f9dd55d4a23fedee8e00c Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Tue, 30 Jun 2015 18:38:37 -0300 Subject: [PATCH 2/2] improve unit format in emails --- lib/emailservice.js | 9 ++++++++- test/integration/server.js | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/emailservice.js b/lib/emailservice.js index f3cfd7e..406020a 100644 --- a/lib/emailservice.js +++ b/lib/emailservice.js @@ -190,11 +190,18 @@ EmailService.prototype._getRecipientsList = function(notification, emailType, cb EmailService.prototype._getDataForTemplate = function(notification, recipient, cb) { var self = this; + // TODO: Declare these in BWU + var UNIT_LABELS = { + btc: 'BTC', + bit: 'bits' + }; + var data = _.cloneDeep(notification.data); data.subjectPrefix = _.trim(self.subjectPrefix) + ' '; if (data.amount) { try { - data.amount = WalletUtils.formatAmount(+data.amount, recipient.unit) + ' ' + recipient.unit; + var unit = recipient.unit.toLowerCase(); + data.amount = WalletUtils.formatAmount(+data.amount, unit) + ' ' + UNIT_LABELS[unit]; } catch (ex) { return cb(new Error('Could not format amount', ex)); } diff --git a/test/integration/server.js b/test/integration/server.js index 8411e31..7c763d0 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -607,14 +607,14 @@ describe('Wallet service', function() { spanish.from.should.equal('bws@dummy.net'); spanish.subject.should.contain('Nuevo pago recibido'); spanish.text.should.contain(wallet.name); - spanish.text.should.contain('0.123 btc'); + spanish.text.should.contain('0.123 BTC'); var english = _.find(emails, { to: 'copayer2@domain.com' }); english.from.should.equal('bws@dummy.net'); english.subject.should.contain('New payment received'); english.text.should.contain(wallet.name); - english.text.should.contain('123,000 bit'); + english.text.should.contain('123,000 bits'); done(); }, 100); });