lamassu-server/new-lamassu-admin/src/pages/Commissions/helper.js
Liordino Neto 27da8cc025 feat: created a number input component (base and formik)
fix: replace numeric TextInput fields on the Cashout, Commissions,
Cashboxes, Notifications, Operator Info and Terms & Conditions pages

fix: change the way the number format is defined on the component

fix: parameterize the number of decimal places in the in the number
input and set it's value for the current number inputs on the admin
2020-09-02 12:32:40 +02:00

206 lines
4 KiB
JavaScript

import * as R from 'ramda'
import * as Yup from 'yup'
import { NumberInput } from 'src/components/inputs/formik'
import Autocomplete from 'src/components/inputs/formik/Autocomplete.js'
const getOverridesFields = (getData, currency) => {
const getView = (data, code, compare) => it => {
if (!data) return ''
return R.compose(
R.prop(code),
R.find(R.propEq(compare ?? 'code', it))
)(data)
}
const displayCodeArray = data => it => {
if (!it) return it
return R.compose(R.join(', '), R.map(getView(data, 'code')))(it)
}
const machineData = getData(['machines'])
const cryptoData = getData(['cryptoCurrencies'])
return [
{
name: 'machine',
width: 196,
size: 'sm',
view: getView(machineData, 'name', 'deviceId'),
input: Autocomplete,
inputProps: {
options: machineData,
valueProp: 'deviceId',
getLabel: R.path(['name']),
limit: null
}
},
{
name: 'cryptoCurrencies',
width: 250,
size: 'sm',
view: displayCodeArray(cryptoData),
input: Autocomplete,
inputProps: {
options: cryptoData,
valueProp: 'code',
getLabel: R.path(['code']),
multiple: true
}
},
{
name: 'cashIn',
display: 'Cash-in',
width: 140,
input: NumberInput,
textAlign: 'right',
suffix: '%',
inputProps: {
decimalPlaces: 0
}
},
{
name: 'cashOut',
display: 'Cash-out',
width: 140,
input: NumberInput,
textAlign: 'right',
suffix: '%',
inputProps: {
decimalPlaces: 0
}
},
{
name: 'fixedFee',
display: 'Fixed fee',
width: 140,
input: NumberInput,
doubleHeader: 'Cash-in only',
textAlign: 'right',
suffix: currency,
inputProps: {
decimalPlaces: 2
}
},
{
name: 'minimumTx',
display: 'Minimun Tx',
width: 140,
input: NumberInput,
doubleHeader: 'Cash-in only',
textAlign: 'right',
suffix: currency,
inputProps: {
decimalPlaces: 2
}
}
]
}
const mainFields = currency => [
{
name: 'cashIn',
display: 'Cash-in',
width: 169,
size: 'lg',
input: NumberInput,
suffix: '%',
inputProps: {
decimalPlaces: 0
}
},
{
name: 'cashOut',
display: 'Cash-out',
width: 169,
size: 'lg',
input: NumberInput,
suffix: '%',
inputProps: {
decimalPlaces: 0
}
},
{
name: 'fixedFee',
display: 'Fixed fee',
width: 169,
size: 'lg',
doubleHeader: 'Cash-in only',
textAlign: 'center',
input: NumberInput,
suffix: currency,
inputProps: {
decimalPlaces: 2
}
},
{
name: 'minimumTx',
display: 'Minimun Tx',
width: 169,
size: 'lg',
doubleHeader: 'Cash-in only',
textAlign: 'center',
input: NumberInput,
suffix: currency,
inputProps: {
decimalPlaces: 2
}
}
]
const overrides = (auxData, currency) => {
const getData = R.path(R.__, auxData)
return getOverridesFields(getData, currency)
}
const schema = Yup.object().shape({
cashIn: Yup.number()
.max(100)
.required('Required'),
cashOut: Yup.number()
.max(100)
.required('Required'),
fixedFee: Yup.number().required('Required'),
minimumTx: Yup.number().required('Required')
})
const OverridesSchema = Yup.object().shape({
machine: Yup.string().required('Required'),
cryptoCurrencies: Yup.array().required('Required'),
cashIn: Yup.number()
.max(100)
.required('Required'),
cashOut: Yup.number()
.max(100)
.required('Required'),
fixedFee: Yup.number().required('Required'),
minimumTx: Yup.number().required('Required')
})
const defaults = {
cashIn: '',
cashOut: '',
fixedFee: '',
minimumTx: ''
}
const overridesDefaults = {
machine: '',
cryptoCurrencies: [],
cashIn: '',
cashOut: '',
fixedFee: '',
minimumTx: ''
}
export {
mainFields,
overrides,
schema,
OverridesSchema,
defaults,
overridesDefaults
}