diff --git a/lib/notifier/index.js b/lib/notifier/index.js index 19e13a56..4ea0793c 100644 --- a/lib/notifier/index.js +++ b/lib/notifier/index.js @@ -207,11 +207,11 @@ function sendTransactionMessage (rec, isHighValueTx) { // for notification center, check if type of notification is active before calling the respective notify function const notifyIfActive = (type, fnName, ...args) => { return settingsLoader.loadLatest().then(settings => { - const notificationSettings = configManager.getGlobalNotifications(settings.config).notificationCenter + const notificationSettings = utils.fromNamespace('notificationCenter', configManager.getGlobalNotifications(settings.config)) 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() return notificationCenter[fnName](...args) - }) + }).catch(console.error) } module.exports = { diff --git a/lib/notifier/utils.js b/lib/notifier/utils.js index 15465d7a..ff548c7c 100644 --- a/lib/notifier/utils.js +++ b/lib/notifier/utils.js @@ -180,6 +180,12 @@ function getAlertTypes (alertRec, config) { 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 = { codeDisplay, parseEventNote, @@ -196,5 +202,6 @@ module.exports = { formatCurrency, formatAge, buildDetail, - deviceAlerts + deviceAlerts, + fromNamespace }