diff --git a/lib/common/utils.js b/lib/common/utils.js index 17bb18e..2d4d807 100644 --- a/lib/common/utils.js +++ b/lib/common/utils.js @@ -105,7 +105,12 @@ Utils.formatAmount = function(satoshis, unit, opts) { toSatoshis: 1, maxDecimals: 0, minDecimals: 0, - } + }, + bch: { + toSatoshis: 100000000, + maxDecimals: 6, + minDecimals: 2, + }, }; $.shouldBeNumber(satoshis); diff --git a/lib/emailservice.js b/lib/emailservice.js index 4bb6dcf..c3503a4 100644 --- a/lib/emailservice.js +++ b/lib/emailservice.js @@ -11,6 +11,7 @@ var path = require('path'); var nodemailer = require('nodemailer'); var Utils = require('./common/utils'); +var Defaults = require('./common/defaults'); var Storage = require('./storage'); var MessageBroker = require('./messagebroker'); var Lock = require('./lock'); @@ -173,33 +174,44 @@ EmailService.prototype._applyTemplate = function(template, data, cb) { EmailService.prototype._getRecipientsList = function(notification, emailType, cb) { var self = this; - self.storage.fetchPreferences(notification.walletId, null, function(err, preferences) { + self.storage.fetchWallet(notification.walletId, function(err, wallet) { if (err) return cb(err); - if (_.isEmpty(preferences)) return cb(null, []); - var usedEmails = {}; - var recipients = _.compact(_.map(preferences, function(p) { - if (!p.email || usedEmails[p.email]) return; + self.storage.fetchPreferences(notification.walletId, null, function(err, preferences) { + if (err) return cb(err); + if (_.isEmpty(preferences)) return cb(null, []); - usedEmails[p.email] = true; - if (notification.creatorId == p.copayerId && !emailType.notifyDoer) return; - if (notification.creatorId != p.copayerId && !emailType.notifyOthers) return; - if (!_.contains(self.availableLanguages, p.language)) { - if (p.language) { - log.warn('Language for email "' + p.language + '" not available.'); + var usedEmails = {}; + var recipients = _.compact(_.map(preferences, function(p) { + if (!p.email || usedEmails[p.email]) return; + + usedEmails[p.email] = true; + if (notification.creatorId == p.copayerId && !emailType.notifyDoer) return; + if (notification.creatorId != p.copayerId && !emailType.notifyOthers) return; + if (!_.contains(self.availableLanguages, p.language)) { + if (p.language) { + log.warn('Language for email "' + p.language + '" not available.'); + } + p.language = self.defaultLanguage; } - p.language = self.defaultLanguage; - } - return { - copayerId: p.copayerId, - emailAddress: p.email, - language: p.language, - unit: p.unit || self.defaultUnit, - }; - })); + var unit; + if (wallet.coin != Defaults.COIN) { + unit = wallet.coin; + } else { + unit = p.unit || self.defaultUnit; + } - return cb(null, recipients); + return { + copayerId: p.copayerId, + emailAddress: p.email, + language: p.language, + unit: unit, + }; + })); + + return cb(null, recipients); + }); }); }; @@ -209,7 +221,8 @@ EmailService.prototype._getDataForTemplate = function(notification, recipient, c // TODO: Declare these in BWU var UNIT_LABELS = { btc: 'BTC', - bit: 'bits' + bit: 'bits', + bch: 'BCH', }; var data = _.cloneDeep(notification.data); diff --git a/lib/pushnotificationsservice.js b/lib/pushnotificationsservice.js index 11e5349..df41c45 100644 --- a/lib/pushnotificationsservice.js +++ b/lib/pushnotificationsservice.js @@ -9,6 +9,7 @@ var Storage = require('./storage'); var fs = require('fs'); var path = require('path'); var Utils = require('./common/utils'); +var Defaults = require('./common/defaults'); var Model = require('./model'); var sjcl = require('sjcl'); var log = require('npmlog'); @@ -198,6 +199,11 @@ PushNotificationsService.prototype._getRecipientsList = function(notification, n self.storage.fetchWallet(notification.walletId, function(err, wallet) { if (err) return cb(err); + var unit; + if (wallet.coin != Defaults.COIN) { + unit = wallet.coin; + } + self.storage.fetchPreferences(notification.walletId, null, function(err, preferences) { if (err) log.error(err); @@ -214,7 +220,7 @@ PushNotificationsService.prototype._getRecipientsList = function(notification, n return { copayerId: p.copayerId, language: p.language, - unit: p.unit, + unit: unit || p.unit || self.defaultUnit, }; })); @@ -227,7 +233,7 @@ PushNotificationsService.prototype._getRecipientsList = function(notification, n return { copayerId: copayer.id, language: p.language || self.defaultLanguage, - unit: p.unit || self.defaultUnit, + unit: unit || p.unit || self.defaultUnit, } } })); @@ -275,7 +281,8 @@ PushNotificationsService.prototype._getDataForTemplate = function(notification, var self = this; var UNIT_LABELS = { btc: 'BTC', - bit: 'bits' + bit: 'bits', + bch: 'BCH', }; var data = _.cloneDeep(notification.data); diff --git a/test/integration/pushNotifications.js b/test/integration/pushNotifications.js index e30c126..ee6f32d 100644 --- a/test/integration/pushNotifications.js +++ b/test/integration/pushNotifications.js @@ -110,6 +110,7 @@ describe('Push notifications', function() { calls.length.should.equal(1); args[0].body.notification.title.should.contain('New payment received'); args[0].body.notification.body.should.contain('123,000'); + args[0].body.notification.body.should.contain('bits'); done(); }, 100); });