use wallet unit for BCH

This commit is contained in:
Ivan Socolsky 2017-09-08 16:18:25 -03:00
parent 03a61f68f2
commit f0a48e1217
No known key found for this signature in database
GPG Key ID: FAECE6A05FAA4F56
4 changed files with 52 additions and 26 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);
});