feat: add machine rates screen toggle
This commit is contained in:
parent
d0573daa74
commit
3b12dd5608
9 changed files with 151 additions and 4 deletions
|
|
@ -61,6 +61,13 @@ const addReceiptInfo = receiptInfo => ret => {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const addMachineScreenOpts = addSmthInfo(
|
||||||
|
'screenOptions',
|
||||||
|
[
|
||||||
|
'rates.active'
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
/* TODO: Simplify this. */
|
/* TODO: Simplify this. */
|
||||||
const buildTriggers = allTriggers => {
|
const buildTriggers = allTriggers => {
|
||||||
const normalTriggers = []
|
const normalTriggers = []
|
||||||
|
|
@ -117,6 +124,7 @@ const staticConfig = ({ currentConfigVersion, deviceId, deviceName, pq, settings
|
||||||
configManager.getLocale(deviceId, settings.config),
|
configManager.getLocale(deviceId, settings.config),
|
||||||
configManager.getOperatorInfo(settings.config),
|
configManager.getOperatorInfo(settings.config),
|
||||||
configManager.getReceipt(settings.config),
|
configManager.getReceipt(settings.config),
|
||||||
|
configManager.getAllMachineScreenOpts(settings.config),
|
||||||
!!configManager.getCashOut(deviceId, settings.config).active,
|
!!configManager.getCashOut(deviceId, settings.config).active,
|
||||||
getMachine(deviceId, currentConfigVersion),
|
getMachine(deviceId, currentConfigVersion),
|
||||||
configManager.getCustomerAuthenticationMethod(settings.config)
|
configManager.getCustomerAuthenticationMethod(settings.config)
|
||||||
|
|
@ -129,6 +137,7 @@ const staticConfig = ({ currentConfigVersion, deviceId, deviceName, pq, settings
|
||||||
localeInfo,
|
localeInfo,
|
||||||
operatorInfo,
|
operatorInfo,
|
||||||
receiptInfo,
|
receiptInfo,
|
||||||
|
machineScreenOpts,
|
||||||
twoWayMode,
|
twoWayMode,
|
||||||
{ numberOfCassettes, numberOfRecyclers },
|
{ numberOfCassettes, numberOfRecyclers },
|
||||||
customerAuthentication,
|
customerAuthentication,
|
||||||
|
|
@ -153,7 +162,8 @@ const staticConfig = ({ currentConfigVersion, deviceId, deviceName, pq, settings
|
||||||
urlsToPing,
|
urlsToPing,
|
||||||
}),
|
}),
|
||||||
addOperatorInfo(operatorInfo),
|
addOperatorInfo(operatorInfo),
|
||||||
addReceiptInfo(receiptInfo)
|
addReceiptInfo(receiptInfo),
|
||||||
|
addMachineScreenOpts(machineScreenOpts)
|
||||||
)(staticConf))
|
)(staticConf))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,14 @@ type ReceiptInfo {
|
||||||
addressQRCode: Boolean!
|
addressQRCode: Boolean!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type MachineScreenOptions {
|
||||||
|
rates: RateScreenOptions!
|
||||||
|
}
|
||||||
|
|
||||||
|
type RateScreenOptions {
|
||||||
|
active: Boolean!
|
||||||
|
}
|
||||||
|
|
||||||
type SpeedtestFile {
|
type SpeedtestFile {
|
||||||
url: String!
|
url: String!
|
||||||
size: Int!
|
size: Int!
|
||||||
|
|
@ -147,6 +155,7 @@ type StaticConfig {
|
||||||
operatorInfo: OperatorInfo
|
operatorInfo: OperatorInfo
|
||||||
machineInfo: MachineInfo!
|
machineInfo: MachineInfo!
|
||||||
receiptInfo: ReceiptInfo
|
receiptInfo: ReceiptInfo
|
||||||
|
screenOptions: MachineScreenOptions
|
||||||
|
|
||||||
speedtestFiles: [SpeedtestFile!]!
|
speedtestFiles: [SpeedtestFile!]!
|
||||||
urlsToPing: [String!]!
|
urlsToPing: [String!]!
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,12 @@ const namespaces = {
|
||||||
TERMS_CONDITIONS: 'termsConditions',
|
TERMS_CONDITIONS: 'termsConditions',
|
||||||
CASH_OUT: 'cashOut',
|
CASH_OUT: 'cashOut',
|
||||||
CASH_IN: 'cashIn',
|
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)
|
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 getTermsConditions = fromNamespace(namespaces.TERMS_CONDITIONS)
|
||||||
const getReceipt = fromNamespace(namespaces.RECEIPT)
|
const getReceipt = fromNamespace(namespaces.RECEIPT)
|
||||||
const getCompliance = fromNamespace(namespaces.COMPLIANCE)
|
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 getAllCryptoCurrencies = (config) => {
|
||||||
const locale = fromNamespace(namespaces.LOCALE)(config)
|
const locale = fromNamespace(namespaces.LOCALE)(config)
|
||||||
|
|
@ -180,6 +187,8 @@ module.exports = {
|
||||||
getWalletSettings,
|
getWalletSettings,
|
||||||
getCashInSettings,
|
getCashInSettings,
|
||||||
getOperatorInfo,
|
getOperatorInfo,
|
||||||
|
getMachineScreenOpts,
|
||||||
|
getAllMachineScreenOpts,
|
||||||
getNotifications,
|
getNotifications,
|
||||||
getGlobalNotifications,
|
getGlobalNotifications,
|
||||||
getLocale,
|
getLocale,
|
||||||
|
|
|
||||||
|
|
@ -278,6 +278,7 @@ function plugins (settings, deviceId) {
|
||||||
const localeConfig = configManager.getLocale(deviceId, settings.config)
|
const localeConfig = configManager.getLocale(deviceId, settings.config)
|
||||||
const fiatCode = localeConfig.fiatCurrency
|
const fiatCode = localeConfig.fiatCurrency
|
||||||
const cryptoCodes = localeConfig.cryptoCurrencies
|
const cryptoCodes = localeConfig.cryptoCurrencies
|
||||||
|
const machineScreenOpts = configManager.getAllMachineScreenOpts(settings.config)
|
||||||
|
|
||||||
const tickerPromises = cryptoCodes.map(c => getTickerRates(fiatCode, c))
|
const tickerPromises = cryptoCodes.map(c => getTickerRates(fiatCode, c))
|
||||||
const balancePromises = cryptoCodes.map(c => fiatBalance(fiatCode, c))
|
const balancePromises = cryptoCodes.map(c => fiatBalance(fiatCode, c))
|
||||||
|
|
@ -327,7 +328,8 @@ function plugins (settings, deviceId) {
|
||||||
coins,
|
coins,
|
||||||
configVersion,
|
configVersion,
|
||||||
areThereAvailablePromoCodes: numberOfAvailablePromoCodes > 0,
|
areThereAvailablePromoCodes: numberOfAvailablePromoCodes > 0,
|
||||||
timezone
|
timezone,
|
||||||
|
screenOptions: machineScreenOpts
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
20
migrations/1657909035091-rates-screen.js
Normal file
20
migrations/1657909035091-rates-screen.js
Normal file
|
|
@ -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()
|
||||||
|
}
|
||||||
80
new-lamassu-admin/src/pages/OperatorInfo/MachineScreens.js
Normal file
80
new-lamassu-admin/src/pages/OperatorInfo/MachineScreens.js
Normal file
|
|
@ -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 (
|
||||||
|
<>
|
||||||
|
<div className={classes.header}>
|
||||||
|
<H4>Rates screen</H4>
|
||||||
|
</div>
|
||||||
|
<div className={classes.switchRow}>
|
||||||
|
<P>Enable rates screen</P>
|
||||||
|
<div className={classes.switch}>
|
||||||
|
<Switch
|
||||||
|
checked={ratesScreenConfig.active}
|
||||||
|
onChange={event =>
|
||||||
|
saveConfig({
|
||||||
|
variables: {
|
||||||
|
config: R.compose(
|
||||||
|
toNamespace(namespaces.MACHINE_SCREENS),
|
||||||
|
toNamespace('rates')
|
||||||
|
)(
|
||||||
|
R.merge(ratesScreenConfig, {
|
||||||
|
active: event.target.checked
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Label2>{ratesScreenConfig.active ? 'Yes' : 'No'}</Label2>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
export default MachineScreens
|
||||||
|
|
@ -16,6 +16,7 @@ import MachineStatus from 'src/pages/Maintenance/MachineStatus'
|
||||||
import Notifications from 'src/pages/Notifications/Notifications'
|
import Notifications from 'src/pages/Notifications/Notifications'
|
||||||
import CoinAtmRadar from 'src/pages/OperatorInfo/CoinATMRadar'
|
import CoinAtmRadar from 'src/pages/OperatorInfo/CoinATMRadar'
|
||||||
import ContactInfo from 'src/pages/OperatorInfo/ContactInfo'
|
import ContactInfo from 'src/pages/OperatorInfo/ContactInfo'
|
||||||
|
import MachineScreens from 'src/pages/OperatorInfo/MachineScreens'
|
||||||
import ReceiptPrinting from 'src/pages/OperatorInfo/ReceiptPrinting'
|
import ReceiptPrinting from 'src/pages/OperatorInfo/ReceiptPrinting'
|
||||||
import SMSNotices from 'src/pages/OperatorInfo/SMSNotices/SMSNotices'
|
import SMSNotices from 'src/pages/OperatorInfo/SMSNotices/SMSNotices'
|
||||||
import TermsConditions from 'src/pages/OperatorInfo/TermsConditions'
|
import TermsConditions from 'src/pages/OperatorInfo/TermsConditions'
|
||||||
|
|
@ -193,6 +194,13 @@ const getLamassuRoutes = () => [
|
||||||
route: '/settings/operator-info/terms-conditions',
|
route: '/settings/operator-info/terms-conditions',
|
||||||
allowedRoles: [ROLES.USER, ROLES.SUPERUSER],
|
allowedRoles: [ROLES.USER, ROLES.SUPERUSER],
|
||||||
component: TermsConditions
|
component: TermsConditions
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'machine-screens',
|
||||||
|
label: 'Machine screens',
|
||||||
|
route: '/settings/operator-info/machine-screens',
|
||||||
|
allowedRoles: [ROLES.USER, ROLES.SUPERUSER],
|
||||||
|
component: MachineScreens
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ import MachineStatus from 'src/pages/Maintenance/MachineStatus'
|
||||||
import Notifications from 'src/pages/Notifications/Notifications'
|
import Notifications from 'src/pages/Notifications/Notifications'
|
||||||
import CoinAtmRadar from 'src/pages/OperatorInfo/CoinATMRadar'
|
import CoinAtmRadar from 'src/pages/OperatorInfo/CoinATMRadar'
|
||||||
import ContactInfo from 'src/pages/OperatorInfo/ContactInfo'
|
import ContactInfo from 'src/pages/OperatorInfo/ContactInfo'
|
||||||
|
import MachineScreens from 'src/pages/OperatorInfo/MachineScreens'
|
||||||
import ReceiptPrinting from 'src/pages/OperatorInfo/ReceiptPrinting'
|
import ReceiptPrinting from 'src/pages/OperatorInfo/ReceiptPrinting'
|
||||||
import SMSNotices from 'src/pages/OperatorInfo/SMSNotices/SMSNotices'
|
import SMSNotices from 'src/pages/OperatorInfo/SMSNotices/SMSNotices'
|
||||||
import TermsConditions from 'src/pages/OperatorInfo/TermsConditions'
|
import TermsConditions from 'src/pages/OperatorInfo/TermsConditions'
|
||||||
|
|
@ -172,6 +173,13 @@ const getPazuzRoutes = () => [
|
||||||
route: '/settings/operator-info/terms-conditions',
|
route: '/settings/operator-info/terms-conditions',
|
||||||
allowedRoles: [ROLES.USER, ROLES.SUPERUSER],
|
allowedRoles: [ROLES.USER, ROLES.SUPERUSER],
|
||||||
component: TermsConditions
|
component: TermsConditions
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'machine-screens',
|
||||||
|
label: 'Machine screens',
|
||||||
|
route: '/settings/operator-info/machine-screens',
|
||||||
|
allowedRoles: [ROLES.USER, ROLES.SUPERUSER],
|
||||||
|
component: MachineScreens
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,8 @@ const namespaces = {
|
||||||
RECEIPT: 'receipt',
|
RECEIPT: 'receipt',
|
||||||
COIN_ATM_RADAR: 'coinAtmRadar',
|
COIN_ATM_RADAR: 'coinAtmRadar',
|
||||||
TERMS_CONDITIONS: 'termsConditions',
|
TERMS_CONDITIONS: 'termsConditions',
|
||||||
TRIGGERS: 'triggersConfig'
|
TRIGGERS: 'triggersConfig',
|
||||||
|
MACHINE_SCREENS: 'machineScreens'
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapKeys = R.curry((fn, obj) =>
|
const mapKeys = R.curry((fn, obj) =>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue