diff --git a/lib/graphql/resolvers.js b/lib/graphql/resolvers.js index 1270f1f3..29101102 100644 --- a/lib/graphql/resolvers.js +++ b/lib/graphql/resolvers.js @@ -61,6 +61,13 @@ const addReceiptInfo = receiptInfo => ret => { } +const addMachineScreenOpts = addSmthInfo( + 'screenOptions', + [ + 'rates.active' + ] +) + /* TODO: Simplify this. */ const buildTriggers = allTriggers => { const normalTriggers = [] @@ -117,6 +124,7 @@ const staticConfig = ({ currentConfigVersion, deviceId, deviceName, pq, settings configManager.getLocale(deviceId, settings.config), configManager.getOperatorInfo(settings.config), configManager.getReceipt(settings.config), + configManager.getAllMachineScreenOpts(settings.config), !!configManager.getCashOut(deviceId, settings.config).active, getMachine(deviceId, currentConfigVersion), configManager.getCustomerAuthenticationMethod(settings.config) @@ -129,6 +137,7 @@ const staticConfig = ({ currentConfigVersion, deviceId, deviceName, pq, settings localeInfo, operatorInfo, receiptInfo, + machineScreenOpts, twoWayMode, { numberOfCassettes, numberOfRecyclers }, customerAuthentication, @@ -153,7 +162,8 @@ const staticConfig = ({ currentConfigVersion, deviceId, deviceName, pq, settings urlsToPing, }), addOperatorInfo(operatorInfo), - addReceiptInfo(receiptInfo) + addReceiptInfo(receiptInfo), + addMachineScreenOpts(machineScreenOpts) )(staticConf)) } diff --git a/lib/graphql/types.js b/lib/graphql/types.js index 89296c6c..c0c72b1e 100644 --- a/lib/graphql/types.js +++ b/lib/graphql/types.js @@ -49,6 +49,14 @@ type ReceiptInfo { addressQRCode: Boolean! } +type MachineScreenOptions { + rates: RateScreenOptions! +} + +type RateScreenOptions { + active: Boolean! +} + type SpeedtestFile { url: String! size: Int! @@ -147,6 +155,7 @@ type StaticConfig { operatorInfo: OperatorInfo machineInfo: MachineInfo! receiptInfo: ReceiptInfo + screenOptions: MachineScreenOptions speedtestFiles: [SpeedtestFile!]! urlsToPing: [String!]! diff --git a/lib/new-config-manager.js b/lib/new-config-manager.js index 680b57a9..239bfa20 100644 --- a/lib/new-config-manager.js +++ b/lib/new-config-manager.js @@ -13,7 +13,12 @@ const namespaces = { TERMS_CONDITIONS: 'termsConditions', CASH_OUT: 'cashOut', CASH_IN: 'cashIn', - COMPLIANCE: 'compliance' + COMPLIANCE: 'compliance', + MACHINE_SCREENS: 'machineScreens' +} + +const machineScreens = { + RATES: 'rates' } const stripl = _.curry((q, str) => _.startsWith(q, str) ? str.slice(q.length) : str) @@ -72,6 +77,8 @@ const getCoinAtmRadar = fromNamespace(namespaces.COIN_ATM_RADAR) const getTermsConditions = fromNamespace(namespaces.TERMS_CONDITIONS) const getReceipt = fromNamespace(namespaces.RECEIPT) const getCompliance = fromNamespace(namespaces.COMPLIANCE) +const getMachineScreenOpts = (screenName, config) => _.compose(fromNamespace(screenName), fromNamespace(namespaces.MACHINE_SCREENS))(config) +const getAllMachineScreenOpts = config => _.reduce((acc, value) => ({ ...acc, [value]: getMachineScreenOpts(value, config) }), {}, _.values(machineScreens)) const getAllCryptoCurrencies = (config) => { const locale = fromNamespace(namespaces.LOCALE)(config) @@ -180,6 +187,8 @@ module.exports = { getWalletSettings, getCashInSettings, getOperatorInfo, + getMachineScreenOpts, + getAllMachineScreenOpts, getNotifications, getGlobalNotifications, getLocale, diff --git a/lib/plugins.js b/lib/plugins.js index d5bfcb4f..0d374672 100644 --- a/lib/plugins.js +++ b/lib/plugins.js @@ -278,6 +278,7 @@ function plugins (settings, deviceId) { const localeConfig = configManager.getLocale(deviceId, settings.config) const fiatCode = localeConfig.fiatCurrency const cryptoCodes = localeConfig.cryptoCurrencies + const machineScreenOpts = configManager.getAllMachineScreenOpts(settings.config) const tickerPromises = cryptoCodes.map(c => getTickerRates(fiatCode, c)) const balancePromises = cryptoCodes.map(c => fiatBalance(fiatCode, c)) @@ -327,7 +328,8 @@ function plugins (settings, deviceId) { coins, configVersion, areThereAvailablePromoCodes: numberOfAvailablePromoCodes > 0, - timezone + timezone, + screenOptions: machineScreenOpts } }) } diff --git a/migrations/1657909035091-rates-screen.js b/migrations/1657909035091-rates-screen.js new file mode 100644 index 00000000..94db1542 --- /dev/null +++ b/migrations/1657909035091-rates-screen.js @@ -0,0 +1,20 @@ +const _ = require('lodash/fp') +const { saveConfig, loadLatest } = require('../lib/new-settings-loader') + +exports.up = function (next) { + const newConfig = {} + return loadLatest() + .then(({ config }) => { + if (!_.isNil(config.machineScreens_rates_active)) return + newConfig[`machineScreens_rates_active`] = true + return saveConfig(newConfig) + }) + .then(next) + .catch(err => { + return next(err) + }) +} + +module.exports.down = function (next) { + next() +} diff --git a/new-lamassu-admin/src/pages/OperatorInfo/MachineScreens.js b/new-lamassu-admin/src/pages/OperatorInfo/MachineScreens.js new file mode 100644 index 00000000..c3ca3b53 --- /dev/null +++ b/new-lamassu-admin/src/pages/OperatorInfo/MachineScreens.js @@ -0,0 +1,80 @@ +import { useQuery, useMutation } from '@apollo/react-hooks' +import { makeStyles } from '@material-ui/core/styles' +import gql from 'graphql-tag' +import * as R from 'ramda' +import React, { memo } from 'react' + +import { Switch } from 'src/components/inputs' +import { H4, P, Label2 } from 'src/components/typography' +import { fromNamespace, toNamespace, namespaces } from 'src/utils/config' + +import { global } from './OperatorInfo.styles' + +const useStyles = makeStyles(global) + +const GET_CONFIG = gql` + query getData { + config + } +` + +const SAVE_CONFIG = gql` + mutation Save($config: JSONObject) { + saveConfig(config: $config) + } +` + +const MachineScreens = memo(({ wizard }) => { + const classes = useStyles() + + const { data } = useQuery(GET_CONFIG) + + const [saveConfig] = useMutation(SAVE_CONFIG, { + refetchQueries: () => ['getData'] + }) + + const machineScreensConfig = + data?.config && fromNamespace(namespaces.MACHINE_SCREENS, data.config) + + const ratesScreenConfig = + data?.config && + R.compose( + fromNamespace('rates'), + fromNamespace(namespaces.MACHINE_SCREENS) + )(data.config) + + if (!machineScreensConfig) return null + + return ( + <> +
Enable rates screen
+