Skip to content

Commit

Permalink
Merge pull request #1764 from RafaelTaranto/backport/machine-rates
Browse files Browse the repository at this point in the history
LAM-481 backport: machine rates
  • Loading branch information
RafaelTaranto authored Nov 29, 2024
2 parents 0471d34 + 3a26e7e commit 620eaeb
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 5 deletions.
20 changes: 18 additions & 2 deletions lib/graphql/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ const addReceiptInfo = receiptInfo => ret => {
}


const addMachineScreenOpts = smth => _.update(
'screenOptions',
_.flow(
addSmthInfo(
'rates',
[
'active'
]
)(smth.rates)
)
)

/* TODO: Simplify this. */
const buildTriggers = allTriggers => {
const normalTriggers = []
Expand Down Expand Up @@ -103,7 +115,8 @@ const staticConfig = ({ currentConfigVersion, deviceId, deviceName, pq, settings
_.pick([
'coins',
'configVersion',
'timezone'
'timezone',
'screenOptions'
]),
_.update('coins', massageCoins),
_.set('serverVersion', VERSION),
Expand All @@ -117,6 +130,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)
Expand All @@ -129,6 +143,7 @@ const staticConfig = ({ currentConfigVersion, deviceId, deviceName, pq, settings
localeInfo,
operatorInfo,
receiptInfo,
machineScreenOpts,
twoWayMode,
{ numberOfCassettes, numberOfRecyclers },
customerAuthentication,
Expand All @@ -153,7 +168,8 @@ const staticConfig = ({ currentConfigVersion, deviceId, deviceName, pq, settings
urlsToPing,
}),
addOperatorInfo(operatorInfo),
addReceiptInfo(receiptInfo)
addReceiptInfo(receiptInfo),
addMachineScreenOpts(machineScreenOpts)
)(staticConf))
}

Expand Down
9 changes: 9 additions & 0 deletions lib/graphql/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ type ReceiptInfo {
addressQRCode: Boolean!
}
type MachineScreenOptions {
rates: RateScreenOptions!
}
type RateScreenOptions {
active: Boolean!
}
type SpeedtestFile {
url: String!
size: Int!
Expand Down Expand Up @@ -147,6 +155,7 @@ type StaticConfig {
operatorInfo: OperatorInfo
machineInfo: MachineInfo!
receiptInfo: ReceiptInfo
screenOptions: MachineScreenOptions
speedtestFiles: [SpeedtestFile!]!
urlsToPing: [String!]!
Expand Down
11 changes: 10 additions & 1 deletion lib/new-config-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -180,6 +187,8 @@ module.exports = {
getWalletSettings,
getCashInSettings,
getOperatorInfo,
getMachineScreenOpts,
getAllMachineScreenOpts,
getNotifications,
getGlobalNotifications,
getLocale,
Expand Down
4 changes: 3 additions & 1 deletion lib/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -327,7 +328,8 @@ function plugins (settings, deviceId) {
coins,
configVersion,
areThereAvailablePromoCodes: numberOfAvailablePromoCodes > 0,
timezone
timezone,
screenOptions: machineScreenOpts
}
})
}
Expand Down
20 changes: 20 additions & 0 deletions migrations/1732881659436-rates-screen.js
Original file line number Diff line number Diff line change
@@ -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 changes: 80 additions & 0 deletions new-lamassu-admin/src/pages/OperatorInfo/MachineScreens.js
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions new-lamassu-admin/src/routing/lamassu.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import MachineStatus from 'src/pages/Maintenance/MachineStatus'
import Notifications from 'src/pages/Notifications/Notifications'
import CoinAtmRadar from 'src/pages/OperatorInfo/CoinATMRadar'
import ContactInfo from 'src/pages/OperatorInfo/ContactInfo'
import MachineScreens from 'src/pages/OperatorInfo/MachineScreens'
import ReceiptPrinting from 'src/pages/OperatorInfo/ReceiptPrinting'
import SMSNotices from 'src/pages/OperatorInfo/SMSNotices/SMSNotices'
import TermsConditions from 'src/pages/OperatorInfo/TermsConditions'
Expand Down Expand Up @@ -193,6 +194,13 @@ const getLamassuRoutes = () => [
route: '/settings/operator-info/terms-conditions',
allowedRoles: [ROLES.USER, ROLES.SUPERUSER],
component: TermsConditions
},
{
key: 'machine-screens',
label: 'Machine screens',
route: '/settings/operator-info/machine-screens',
allowedRoles: [ROLES.USER, ROLES.SUPERUSER],
component: MachineScreens
}
]
}
Expand Down
8 changes: 8 additions & 0 deletions new-lamassu-admin/src/routing/pazuz.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import MachineStatus from 'src/pages/Maintenance/MachineStatus'
import Notifications from 'src/pages/Notifications/Notifications'
import CoinAtmRadar from 'src/pages/OperatorInfo/CoinATMRadar'
import ContactInfo from 'src/pages/OperatorInfo/ContactInfo'
import MachineScreens from 'src/pages/OperatorInfo/MachineScreens'
import ReceiptPrinting from 'src/pages/OperatorInfo/ReceiptPrinting'
import SMSNotices from 'src/pages/OperatorInfo/SMSNotices/SMSNotices'
import TermsConditions from 'src/pages/OperatorInfo/TermsConditions'
Expand Down Expand Up @@ -172,6 +173,13 @@ const getPazuzRoutes = () => [
route: '/settings/operator-info/terms-conditions',
allowedRoles: [ROLES.USER, ROLES.SUPERUSER],
component: TermsConditions
},
{
key: 'machine-screens',
label: 'Machine screens',
route: '/settings/operator-info/machine-screens',
allowedRoles: [ROLES.USER, ROLES.SUPERUSER],
component: MachineScreens
}
]
}
Expand Down
3 changes: 2 additions & 1 deletion new-lamassu-admin/src/utils/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const namespaces = {
RECEIPT: 'receipt',
COIN_ATM_RADAR: 'coinAtmRadar',
TERMS_CONDITIONS: 'termsConditions',
TRIGGERS: 'triggersConfig'
TRIGGERS: 'triggersConfig',
MACHINE_SCREENS: 'machineScreens'
}

const mapKeys = R.curry((fn, obj) =>
Expand Down

0 comments on commit 620eaeb

Please sign in to comment.