From 4ce1b949d07d3ae73662322353f502954058f65b Mon Sep 17 00:00:00 2001 From: csrapr <26280794+csrapr@users.noreply.github.com> Date: Mon, 1 Mar 2021 16:23:02 +0000 Subject: [PATCH] Chore: move fromNamespace call to configManager --- lib/new-config-manager.js | 4 ++-- lib/notifier/index.js | 2 +- lib/notifier/utils.js | 9 +-------- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/lib/new-config-manager.js b/lib/new-config-manager.js index 97974b45..57cf1105 100644 --- a/lib/new-config-manager.js +++ b/lib/new-config-manager.js @@ -72,6 +72,7 @@ const getNotifications = (cryptoCurrency, machine, config) => { const smsSettings = fromNamespace('sms', notifications) const emailSettings = fromNamespace('email', notifications) + const notificationCenterSettings = fromNamespace('notificationCenter', 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 fiatSettings = getFiatSettings(notifications.fiatBalanceOverrides) - - return { ...notifNoOverrides, sms: smsSettings, email: emailSettings, ...cryptoSettings, ...fiatSettings } + return { ...notifNoOverrides, sms: smsSettings, email: emailSettings, ...cryptoSettings, ...fiatSettings, notificationCenter: notificationCenterSettings } } const getGlobalNotifications = config => getNotifications(null, null, config) diff --git a/lib/notifier/index.js b/lib/notifier/index.js index 4ea0793c..65f22192 100644 --- a/lib/notifier/index.js +++ b/lib/notifier/index.js @@ -207,7 +207,7 @@ 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 = 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 (!(notificationSettings.active && notificationSettings[type])) return Promise.resolve() return notificationCenter[fnName](...args) diff --git a/lib/notifier/utils.js b/lib/notifier/utils.js index ff548c7c..15465d7a 100644 --- a/lib/notifier/utils.js +++ b/lib/notifier/utils.js @@ -180,12 +180,6 @@ 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, @@ -202,6 +196,5 @@ module.exports = { formatCurrency, formatAge, buildDetail, - deviceAlerts, - fromNamespace + deviceAlerts }