From f716e4202c5e05a7bf65ab041f108754e482f046 Mon Sep 17 00:00:00 2001 From: Rafael Taranto Date: Sat, 19 Aug 2023 10:56:54 +0100 Subject: [PATCH] feat: admin picked sms provider --- lib/sms.js | 3 +- .../src/pages/Notifications/Notifications.js | 18 +++++ .../sections/ThirdPartyProvider.js | 69 +++++++++++++++++++ 3 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 new-lamassu-admin/src/pages/Notifications/sections/ThirdPartyProvider.js diff --git a/lib/sms.js b/lib/sms.js index 68e498e9..49f8f80c 100644 --- a/lib/sms.js +++ b/lib/sms.js @@ -25,7 +25,8 @@ function getSms (event, phone, content) { } function getPlugin (settings) { - const pluginCode = argv.mockSms ? 'mock-sms' : argv.telnyxSms ? 'telnyx' : 'twilio' + const smsProvider = settings.config.notifications_thirdParty_provider + const pluginCode = smsProvider ?? 'twilio' const plugin = ph.load(ph.SMS, pluginCode) const account = settings.accounts[pluginCode] diff --git a/new-lamassu-admin/src/pages/Notifications/Notifications.js b/new-lamassu-admin/src/pages/Notifications/Notifications.js index b79eb9a7..bb51cffd 100644 --- a/new-lamassu-admin/src/pages/Notifications/Notifications.js +++ b/new-lamassu-admin/src/pages/Notifications/Notifications.js @@ -19,11 +19,19 @@ import CryptoBalanceOverrides from './sections/CryptoBalanceOverrides' import FiatBalanceAlerts from './sections/FiatBalanceAlerts' import FiatBalanceOverrides from './sections/FiatBalanceOverrides' import Setup from './sections/Setup' +import ThirdPartyProvider from './sections/ThirdPartyProvider' import TransactionAlerts from './sections/TransactionAlerts' const GET_INFO = gql` query getData { config + accountsConfig { + code + display + class + cryptos + deprecated + } machines { name deviceId @@ -59,6 +67,7 @@ const Notifications = ({ displayCryptoAlerts = true, displayOverrides = true, displayTitle = true, + displayThirdPartyProvider = true, wizard = false }) => { const [section, setSection] = useState(null) @@ -86,6 +95,7 @@ const Notifications = ({ const config = fromNamespace(SCREEN_KEY)(data?.config) const machines = data?.machines + const accountsConfig = data?.accountsConfig const cryptoCurrencies = data?.cryptoCurrencies const twilioAvailable = R.has('twilio', data?.accounts || {}) const mailgunAvailable = R.has('mailgun', data?.accounts || {}) @@ -136,6 +146,7 @@ const Notifications = ({ setEditing, setSection, machines, + accountsConfig, cryptoCurrencies, twilioAvailable, setSmsSetupPopup, @@ -148,6 +159,13 @@ const Notifications = ({ <> {displayTitle && } + {displayThirdPartyProvider && ( +
+ +
+ )} {displaySetup && (
diff --git a/new-lamassu-admin/src/pages/Notifications/sections/ThirdPartyProvider.js b/new-lamassu-admin/src/pages/Notifications/sections/ThirdPartyProvider.js new file mode 100644 index 00000000..4312a2c5 --- /dev/null +++ b/new-lamassu-admin/src/pages/Notifications/sections/ThirdPartyProvider.js @@ -0,0 +1,69 @@ +import * as R from 'ramda' +import React, { useContext } from 'react' +import * as Yup from 'yup' + +import { Table as EditableTable } from 'src/components/editableTable' +import Autocomplete from 'src/components/inputs/formik/Autocomplete' +import { toNamespace, fromNamespace } from 'src/utils/config' + +import NotificationsCtx from '../NotificationsContext' + +const filterClass = type => R.filter(it => it.class === type) + +const ThirdPartyProvider = () => { + const { save, data: _data, error, accountsConfig } = useContext( + NotificationsCtx + ) + + const data = fromNamespace('thirdParty')(_data) + + const filterOptions = type => filterClass(type)(accountsConfig || []) + + const getDisplayName = type => it => + R.compose( + R.prop('display'), + R.find(R.propEq('code', it)) + )(filterOptions(type)) + + const innerSave = async value => { + const config = toNamespace('thirdParty')(value?.thirdParty[0]) + await save('thirdParty', config) + } + + const ThirdPartySchema = Yup.object().shape({ + sms: Yup.string('The ticker must be a string').required( + 'The ticker is required' + ) + }) + + const elements = [ + { + name: 'sms', + size: 'sm', + view: getDisplayName('sms'), + width: 175, + input: Autocomplete, + inputProps: { + options: filterOptions('sms'), + valueProp: 'code', + labelProp: 'display' + } + } + ] + + return ( + + ) +} + +export default ThirdPartyProvider