diff --git a/lamassu-schema.json b/lamassu-schema.json index c2064d60..4ca4729c 100644 --- a/lamassu-schema.json +++ b/lamassu-schema.json @@ -212,6 +212,12 @@ "display": "SMS", "fieldType": "account", "fieldClass": "sms" + }, + { + "code": "lowBalanceThreshold", + "display": "Low Balance Threshold", + "fieldType": "integer", + "fieldClass": null } ] } diff --git a/lib/plugins.js b/lib/plugins.js index 113bb631..6bf5f94a 100644 --- a/lib/plugins.js +++ b/lib/plugins.js @@ -690,12 +690,16 @@ exports.getcryptoCodes = function getcryptoCodes () { } function sendMessage (rec) { - const pluginTypes = cachedConfig.exchanges.plugins.current.notify - const pluginPromises = pluginTypes.map(pluginType => { - if (pluginType === 'email') return emailPlugin.sendMessage(rec) - if (pluginType === 'sms') return smsPlugin.sendMessage(rec) - throw new Error('No such plugin type: ' + pluginType) - }) + const pluginPromises = [] + if (!cachedConfig.notifications.notificationsEnabled) return Promise.all([]) + + if (cachedConfig.notifications.notificationsEmailEnabled) { + pluginPromises.push(emailPlugin.sendMessage(rec)) + } + + if (cachedConfig.notifications.notificationsSMSEnabled) { + pluginPromises.push(smsPlugin.sendMessage(rec)) + } return Promise.all(pluginPromises) } @@ -770,7 +774,7 @@ function checkBalances () { } exports.startCheckingNotification = function startCheckingNotification () { - const config = cachedConfig.exchanges.plugins.settings.notifier + const config = cachedConfig.notifications notifier.init(db, checkBalances, config) checkNotification() setInterval(checkNotification, CHECK_NOTIFICATION_INTERVAL)