Fix: fix crypto overrides not being respected
This commit is contained in:
parent
c457faab40
commit
366adad375
3 changed files with 29 additions and 21 deletions
|
|
@ -1,5 +1,4 @@
|
|||
const _ = require('lodash/fp')
|
||||
const logger = require('./logger')
|
||||
|
||||
const namespaces = {
|
||||
WALLETS: 'wallets',
|
||||
|
|
@ -19,13 +18,6 @@ const filter = namespace => _.pickBy((value, key) => _.startsWith(`${namespace}_
|
|||
const strip = key => _.mapKeys(stripl(`${key}_`))
|
||||
|
||||
const fromNamespace = _.curry((key, config) => _.compose(strip(key), filter(key))(config))
|
||||
const toNamespace = (key, config) => _.mapKeys(it => `${key}_${it}`)(config)
|
||||
|
||||
const resolveOverrides = (original, filter, overrides, overridesPath = 'overrides') => {
|
||||
if (_.isEmpty(overrides)) return _.omit(overridesPath, original)
|
||||
|
||||
return _.omit(overridesPath, _.assignAll([original, ..._.filter(filter)(overrides)]))
|
||||
}
|
||||
|
||||
const getCommissions = (cryptoCode, deviceId, config) => {
|
||||
const commissions = fromNamespace(namespaces.COMMISSIONS)(config)
|
||||
|
|
@ -55,7 +47,7 @@ const getLocale = (deviceId, it) => {
|
|||
const locale = fromNamespace(namespaces.LOCALE)(it)
|
||||
|
||||
const filter = _.matches({ machine: deviceId })
|
||||
return resolveOverrides(locale, filter, locale.overrides)
|
||||
return _.omit('overrides', _.assignAll([locale, ..._.filter(filter)(locale.overrides)]))
|
||||
}
|
||||
|
||||
const getGlobalLocale = it => getLocale(null, it)
|
||||
|
|
@ -78,17 +70,34 @@ const getAllCryptoCurrencies = (config) => {
|
|||
const getNotifications = (cryptoCurrency, machine, config) => {
|
||||
const notifications = fromNamespace(namespaces.NOTIFICATIONS)(config)
|
||||
|
||||
const cryptoFilter = _.matches({ cryptoCurrency })
|
||||
const withCryptoBalance = resolveOverrides(notifications, cryptoFilter, notifications.cryptoBalanceOverrides, 'cryptoBalanceOverrides')
|
||||
const smsSettings = fromNamespace('sms', notifications)
|
||||
const emailSettings = fromNamespace('email', notifications)
|
||||
|
||||
const fiatFilter = _.matches({ machine })
|
||||
const withFiatBalance = resolveOverrides(withCryptoBalance, fiatFilter, withCryptoBalance.fiatBalanceOverrides, 'fiatBalanceOverrides')
|
||||
const notifNoOverrides = _.omit(['cryptoBalanceOverrides', 'fiatBalanceOverrides'], notifications)
|
||||
|
||||
const withSms = fromNamespace('sms', withFiatBalance)
|
||||
const withEmail = fromNamespace('email', withFiatBalance)
|
||||
const findByCryptoCurrency = _.find(_.matches({ cryptoCurrency }))
|
||||
const findByMachine = _.find(_.matches({ machine }))
|
||||
|
||||
const final = { ...withFiatBalance, sms: withSms, email: withEmail }
|
||||
return final
|
||||
const cryptoFields = ['cryptoHighBalance', 'cryptoLowBalance', 'highBalance', 'lowBalance']
|
||||
const fiatFields = ['fiatBalanceCassette1', 'fiatBalanceCassette2']
|
||||
|
||||
const getCryptoSettings = _.compose(_.pick(cryptoFields), _.defaultTo(notifications), findByCryptoCurrency)
|
||||
const cryptoSettings = getCryptoSettings(notifications.cryptoBalanceOverrides)
|
||||
|
||||
if (cryptoSettings.highBalance) {
|
||||
cryptoSettings['cryptoHighBalance'] = cryptoSettings.highBalance
|
||||
delete cryptoSettings.highBalance
|
||||
}
|
||||
|
||||
if (cryptoSettings.lowBalance) {
|
||||
cryptoSettings['cryptoLowBalance'] = cryptoSettings.lowBalance
|
||||
delete cryptoSettings.lowBalance
|
||||
}
|
||||
|
||||
const getFiatSettings = _.compose(_.pick(fiatFields), _.defaultTo(notifications), findByMachine)
|
||||
const fiatSettings = getFiatSettings(notifications.fiatBalanceOverrides)
|
||||
|
||||
return { ...notifNoOverrides, sms: smsSettings, email: emailSettings, ...cryptoSettings, ...fiatSettings }
|
||||
}
|
||||
|
||||
const getGlobalNotifications = config => getNotifications(null, null, config)
|
||||
|
|
|
|||
|
|
@ -618,9 +618,8 @@ function plugins (settings, deviceId) {
|
|||
if (!fiatBalance) return null
|
||||
|
||||
const notifications = configManager.getNotifications(cryptoCode, null, settings.config)
|
||||
const override = _.find(override => override.cryptoCurrency === cryptoCode, settings.config.notifications_cryptoBalanceOverrides)
|
||||
const lowAlertThreshold = override ? override.lowBalance : notifications.cryptoLowBalance
|
||||
const highAlertThreshold = override ? override.highBalance : notifications.cryptoHighBalance
|
||||
const lowAlertThreshold = notifications.cryptoLowBalance
|
||||
const highAlertThreshold = notifications.cryptoHighBalance
|
||||
|
||||
const req = {
|
||||
cryptoCode,
|
||||
|
|
|
|||
|
|
@ -363,7 +363,7 @@ function triggerSuspend (req, res, next) {
|
|||
customers.update(id, { suspendedUntil: date })
|
||||
.then(customer => {
|
||||
notifier.customerComplianceNotify(customer, req.deviceId, 'SUSPENDED', days)
|
||||
respond(req, res, { customer })
|
||||
return respond(req, res, { customer })
|
||||
})
|
||||
.catch(next)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue