Chore: move fromNamespace call to configManager
This commit is contained in:
parent
61fec80899
commit
4ce1b949d0
3 changed files with 4 additions and 11 deletions
|
|
@ -72,6 +72,7 @@ const getNotifications = (cryptoCurrency, machine, config) => {
|
||||||
|
|
||||||
const smsSettings = fromNamespace('sms', notifications)
|
const smsSettings = fromNamespace('sms', notifications)
|
||||||
const emailSettings = fromNamespace('email', notifications)
|
const emailSettings = fromNamespace('email', notifications)
|
||||||
|
const notificationCenterSettings = fromNamespace('notificationCenter', notifications)
|
||||||
|
|
||||||
const notifNoOverrides = _.omit(['cryptoBalanceOverrides', 'fiatBalanceOverrides'], notifications)
|
const notifNoOverrides = _.omit(['cryptoBalanceOverrides', 'fiatBalanceOverrides'], notifications)
|
||||||
|
|
||||||
|
|
@ -96,8 +97,7 @@ const getNotifications = (cryptoCurrency, machine, config) => {
|
||||||
|
|
||||||
const getFiatSettings = _.compose(_.pick(fiatFields), _.defaultTo(notifications), findByMachine)
|
const getFiatSettings = _.compose(_.pick(fiatFields), _.defaultTo(notifications), findByMachine)
|
||||||
const fiatSettings = getFiatSettings(notifications.fiatBalanceOverrides)
|
const fiatSettings = getFiatSettings(notifications.fiatBalanceOverrides)
|
||||||
|
return { ...notifNoOverrides, sms: smsSettings, email: emailSettings, ...cryptoSettings, ...fiatSettings, notificationCenter: notificationCenterSettings }
|
||||||
return { ...notifNoOverrides, sms: smsSettings, email: emailSettings, ...cryptoSettings, ...fiatSettings }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const getGlobalNotifications = config => getNotifications(null, null, config)
|
const getGlobalNotifications = config => getNotifications(null, null, config)
|
||||||
|
|
|
||||||
|
|
@ -207,7 +207,7 @@ function sendTransactionMessage (rec, isHighValueTx) {
|
||||||
// for notification center, check if type of notification is active before calling the respective notify function
|
// for notification center, check if type of notification is active before calling the respective notify function
|
||||||
const notifyIfActive = (type, fnName, ...args) => {
|
const notifyIfActive = (type, fnName, ...args) => {
|
||||||
return settingsLoader.loadLatest().then(settings => {
|
return settingsLoader.loadLatest().then(settings => {
|
||||||
const notificationSettings = utils.fromNamespace('notificationCenter', configManager.getGlobalNotifications(settings.config))
|
const notificationSettings = configManager.getGlobalNotifications(settings.config).notificationCenter
|
||||||
if (!notificationCenter[fnName]) return Promise.reject(new Error(`Notification function ${fnName} for type ${type} does not exist`))
|
if (!notificationCenter[fnName]) return Promise.reject(new Error(`Notification function ${fnName} for type ${type} does not exist`))
|
||||||
if (!(notificationSettings.active && notificationSettings[type])) return Promise.resolve()
|
if (!(notificationSettings.active && notificationSettings[type])) return Promise.resolve()
|
||||||
return notificationCenter[fnName](...args)
|
return notificationCenter[fnName](...args)
|
||||||
|
|
|
||||||
|
|
@ -180,12 +180,6 @@ function getAlertTypes (alertRec, config) {
|
||||||
return alerts
|
return alerts
|
||||||
}
|
}
|
||||||
|
|
||||||
const stripl = _.curry((q, str) => _.startsWith(q, str) ? str.slice(q.length) : str)
|
|
||||||
const filter = namespace => _.pickBy((value, key) => _.startsWith(`${namespace}_`)(key))
|
|
||||||
const strip = key => _.mapKeys(stripl(`${key}_`))
|
|
||||||
|
|
||||||
const fromNamespace = _.curry((key, config) => _.compose(strip(key), filter(key))(config))
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
codeDisplay,
|
codeDisplay,
|
||||||
parseEventNote,
|
parseEventNote,
|
||||||
|
|
@ -202,6 +196,5 @@ module.exports = {
|
||||||
formatCurrency,
|
formatCurrency,
|
||||||
formatAge,
|
formatAge,
|
||||||
buildDetail,
|
buildDetail,
|
||||||
deviceAlerts,
|
deviceAlerts
|
||||||
fromNamespace
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue