feat: add minimumTx boundaries based on config fiat currency
This commit is contained in:
parent
ac61601397
commit
ee330cd925
5 changed files with 60 additions and 45 deletions
|
|
@ -6,7 +6,7 @@ import Section from 'src/components/layout/Section'
|
||||||
import {
|
import {
|
||||||
mainFields,
|
mainFields,
|
||||||
overrides,
|
overrides,
|
||||||
schema,
|
getSchema,
|
||||||
getOverridesSchema,
|
getOverridesSchema,
|
||||||
defaults,
|
defaults,
|
||||||
overridesDefaults,
|
overridesDefaults,
|
||||||
|
|
@ -41,9 +41,9 @@ const CommissionsDetails = memo(
|
||||||
enableEdit
|
enableEdit
|
||||||
initialValues={commission}
|
initialValues={commission}
|
||||||
save={save}
|
save={save}
|
||||||
validationSchema={schema}
|
validationSchema={getSchema(locale)}
|
||||||
data={R.of(commission)}
|
data={R.of(commission)}
|
||||||
elements={mainFields(currency, locale, classes)}
|
elements={mainFields(currency)}
|
||||||
setEditing={onEditingDefault}
|
setEditing={onEditingDefault}
|
||||||
forceDisable={isEditingOverrides}
|
forceDisable={isEditingOverrides}
|
||||||
/>
|
/>
|
||||||
|
|
@ -62,16 +62,11 @@ const CommissionsDetails = memo(
|
||||||
save={saveOverrides}
|
save={saveOverrides}
|
||||||
validationSchema={getOverridesSchema(
|
validationSchema={getOverridesSchema(
|
||||||
orderedCommissionsOverrides,
|
orderedCommissionsOverrides,
|
||||||
data
|
data,
|
||||||
|
locale
|
||||||
)}
|
)}
|
||||||
data={orderedCommissionsOverrides}
|
data={orderedCommissionsOverrides}
|
||||||
elements={overrides(
|
elements={overrides(data, currency, orderedCommissionsOverrides)}
|
||||||
data,
|
|
||||||
currency,
|
|
||||||
orderedCommissionsOverrides,
|
|
||||||
locale,
|
|
||||||
classes
|
|
||||||
)}
|
|
||||||
setEditing={onEditingOverrides}
|
setEditing={onEditingOverrides}
|
||||||
forceDisable={isEditingDefault}
|
forceDisable={isEditingDefault}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -169,7 +169,7 @@ const CommissionsList = memo(
|
||||||
enableEdit
|
enableEdit
|
||||||
save={saveOverrides}
|
save={saveOverrides}
|
||||||
initialValues={overridesDefaults}
|
initialValues={overridesDefaults}
|
||||||
validationSchema={getListCommissionsSchema()}
|
validationSchema={getListCommissionsSchema(localeConfig)}
|
||||||
data={tableData}
|
data={tableData}
|
||||||
elements={commissionsList(data, currency)}
|
elements={commissionsList(data, currency)}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,8 @@ import { bold } from 'src/styling/helpers'
|
||||||
import { ReactComponent as TxInIcon } from 'src/styling/icons/direction/cash-in.svg'
|
import { ReactComponent as TxInIcon } from 'src/styling/icons/direction/cash-in.svg'
|
||||||
import { ReactComponent as TxOutIcon } from 'src/styling/icons/direction/cash-out.svg'
|
import { ReactComponent as TxOutIcon } from 'src/styling/icons/direction/cash-out.svg'
|
||||||
import { primaryColor, secondaryColorDark } from 'src/styling/variables'
|
import { primaryColor, secondaryColorDark } from 'src/styling/variables'
|
||||||
|
import denominations from 'src/utils/bill-denominations'
|
||||||
|
import { getBillOptions } from 'src/utils/bill-options'
|
||||||
import { CURRENCY_MAX } from 'src/utils/constants'
|
import { CURRENCY_MAX } from 'src/utils/constants'
|
||||||
|
|
||||||
const ALL_MACHINES = {
|
const ALL_MACHINES = {
|
||||||
|
|
@ -227,28 +229,35 @@ const overrides = (auxData, currency, auxElements) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const percentMax = 100
|
const percentMax = 100
|
||||||
const schema = Yup.object().shape({
|
const getSchema = locale => {
|
||||||
cashIn: Yup.number()
|
const bills = getBillOptions(locale, denominations).map(it =>
|
||||||
.label('Cash-in')
|
parseInt(it.code)
|
||||||
.min(0)
|
)
|
||||||
.max(percentMax)
|
const highestBill = R.isEmpty(bills) ? CURRENCY_MAX : Math.max(...bills)
|
||||||
.required(),
|
|
||||||
cashOut: Yup.number()
|
return Yup.object().shape({
|
||||||
.label('Cash-out')
|
cashIn: Yup.number()
|
||||||
.min(0)
|
.label('Cash-in')
|
||||||
.max(percentMax)
|
.min(0)
|
||||||
.required(),
|
.max(percentMax)
|
||||||
fixedFee: Yup.number()
|
.required(),
|
||||||
.label('Fixed Fee')
|
cashOut: Yup.number()
|
||||||
.min(0)
|
.label('Cash-out')
|
||||||
.max(CURRENCY_MAX)
|
.min(0)
|
||||||
.required(),
|
.max(percentMax)
|
||||||
minimumTx: Yup.number()
|
.required(),
|
||||||
.label('Minimum Tx')
|
fixedFee: Yup.number()
|
||||||
.min(0)
|
.label('Fixed Fee')
|
||||||
.max(CURRENCY_MAX)
|
.min(0)
|
||||||
.required()
|
.max(highestBill)
|
||||||
})
|
.required(),
|
||||||
|
minimumTx: Yup.number()
|
||||||
|
.label('Minimum Tx')
|
||||||
|
.min(0)
|
||||||
|
.max(highestBill)
|
||||||
|
.required()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const getAlreadyUsed = (id, machine, values) => {
|
const getAlreadyUsed = (id, machine, values) => {
|
||||||
const getCrypto = R.prop('cryptoCurrencies')
|
const getCrypto = R.prop('cryptoCurrencies')
|
||||||
|
|
@ -271,7 +280,7 @@ const getAlreadyUsed = (id, machine, values) => {
|
||||||
return R.difference(alreadyUsed, originalCryptos)
|
return R.difference(alreadyUsed, originalCryptos)
|
||||||
}
|
}
|
||||||
|
|
||||||
const getOverridesSchema = (values, rawData) => {
|
const getOverridesSchema = (values, rawData, locale) => {
|
||||||
const getData = R.path(R.__, rawData)
|
const getData = R.path(R.__, rawData)
|
||||||
const machineData = [ALL_MACHINES].concat(getData(['machines']))
|
const machineData = [ALL_MACHINES].concat(getData(['machines']))
|
||||||
const rawCryptos = getData(['cryptoCurrencies'])
|
const rawCryptos = getData(['cryptoCurrencies'])
|
||||||
|
|
@ -279,6 +288,11 @@ const getOverridesSchema = (values, rawData) => {
|
||||||
R.map(it => ({ display: it.code, code: it.code }))(rawCryptos ?? [])
|
R.map(it => ({ display: it.code, code: it.code }))(rawCryptos ?? [])
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const bills = getBillOptions(locale, denominations).map(it =>
|
||||||
|
parseInt(it.code)
|
||||||
|
)
|
||||||
|
const highestBill = R.isEmpty(bills) ? CURRENCY_MAX : Math.max(...bills)
|
||||||
|
|
||||||
return Yup.object().shape({
|
return Yup.object().shape({
|
||||||
machine: Yup.string()
|
machine: Yup.string()
|
||||||
.nullable()
|
.nullable()
|
||||||
|
|
@ -330,12 +344,12 @@ const getOverridesSchema = (values, rawData) => {
|
||||||
fixedFee: Yup.number()
|
fixedFee: Yup.number()
|
||||||
.label('Fixed Fee')
|
.label('Fixed Fee')
|
||||||
.min(0)
|
.min(0)
|
||||||
.max(CURRENCY_MAX)
|
.max(highestBill)
|
||||||
.required(),
|
.required(),
|
||||||
minimumTx: Yup.number()
|
minimumTx: Yup.number()
|
||||||
.label('Minimum Tx')
|
.label('Minimum Tx')
|
||||||
.min(0)
|
.min(0)
|
||||||
.max(CURRENCY_MAX)
|
.max(highestBill)
|
||||||
.required()
|
.required()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -414,7 +428,12 @@ const getCommissions = (cryptoCode, deviceId, config) => {
|
||||||
return createCommissions(cryptoCode, deviceId, true, config)
|
return createCommissions(cryptoCode, deviceId, true, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
const getListCommissionsSchema = () => {
|
const getListCommissionsSchema = locale => {
|
||||||
|
const bills = getBillOptions(locale, denominations).map(it =>
|
||||||
|
parseInt(it.code)
|
||||||
|
)
|
||||||
|
const highestBill = R.isEmpty(bills) ? CURRENCY_MAX : Math.max(...bills)
|
||||||
|
|
||||||
return Yup.object().shape({
|
return Yup.object().shape({
|
||||||
machine: Yup.string()
|
machine: Yup.string()
|
||||||
.label('Machine')
|
.label('Machine')
|
||||||
|
|
@ -436,12 +455,12 @@ const getListCommissionsSchema = () => {
|
||||||
fixedFee: Yup.number()
|
fixedFee: Yup.number()
|
||||||
.label('Fixed Fee')
|
.label('Fixed Fee')
|
||||||
.min(0)
|
.min(0)
|
||||||
.max(CURRENCY_MAX)
|
.max(highestBill)
|
||||||
.required(),
|
.required(),
|
||||||
minimumTx: Yup.number()
|
minimumTx: Yup.number()
|
||||||
.label('Minimum Tx')
|
.label('Minimum Tx')
|
||||||
.min(0)
|
.min(0)
|
||||||
.max(CURRENCY_MAX)
|
.max(highestBill)
|
||||||
.required()
|
.required()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -534,7 +553,7 @@ const getListCommissionsFields = (getData, currency, defaults) => {
|
||||||
export {
|
export {
|
||||||
mainFields,
|
mainFields,
|
||||||
overrides,
|
overrides,
|
||||||
schema,
|
getSchema,
|
||||||
getOverridesSchema,
|
getOverridesSchema,
|
||||||
defaults,
|
defaults,
|
||||||
overridesDefaults,
|
overridesDefaults,
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import { Table as EditableTable } from 'src/components/editableTable'
|
||||||
import Section from 'src/components/layout/Section'
|
import Section from 'src/components/layout/Section'
|
||||||
import TitleSection from 'src/components/layout/TitleSection'
|
import TitleSection from 'src/components/layout/TitleSection'
|
||||||
import styles from 'src/pages/AddMachine/styles'
|
import styles from 'src/pages/AddMachine/styles'
|
||||||
import { mainFields, defaults, schema } from 'src/pages/Commissions/helper'
|
import { mainFields, defaults, getSchema } from 'src/pages/Commissions/helper'
|
||||||
import { fromNamespace, toNamespace, namespaces } from 'src/utils/config'
|
import { fromNamespace, toNamespace, namespaces } from 'src/utils/config'
|
||||||
|
|
||||||
const useStyles = makeStyles(styles)
|
const useStyles = makeStyles(styles)
|
||||||
|
|
@ -62,7 +62,7 @@ function Commissions({ isActive, doContinue }) {
|
||||||
enableEdit
|
enableEdit
|
||||||
forceAdd={isActive}
|
forceAdd={isActive}
|
||||||
save={save}
|
save={save}
|
||||||
validationSchema={schema}
|
validationSchema={getSchema(locale)}
|
||||||
data={[]}
|
data={[]}
|
||||||
elements={mainFields(currency, locale, commissionClasses)}
|
elements={mainFields(currency, locale, commissionClasses)}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import * as R from 'ramda'
|
import * as R from 'ramda'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
|
||||||
import { schema as CommissionsSchema } from 'src/pages/Commissions/helper'
|
import { getSchema as CommissionsSchema } from 'src/pages/Commissions/helper'
|
||||||
import { LocaleSchema } from 'src/pages/Locales/helper'
|
import { LocaleSchema } from 'src/pages/Locales/helper'
|
||||||
import { WalletSchema } from 'src/pages/Wallet/helper'
|
import { WalletSchema } from 'src/pages/Wallet/helper'
|
||||||
import { fromNamespace, namespaces } from 'src/utils/config'
|
import { fromNamespace, namespaces } from 'src/utils/config'
|
||||||
|
|
@ -40,7 +40,8 @@ const hasValidLocale = config => {
|
||||||
|
|
||||||
const hasValidCommissions = config => {
|
const hasValidCommissions = config => {
|
||||||
const commission = fromNamespace(namespaces.COMMISSIONS, config)
|
const commission = fromNamespace(namespaces.COMMISSIONS, config)
|
||||||
return CommissionsSchema.isValidSync(commission)
|
const locale = fromNamespace(namespaces.LOCALE, config)
|
||||||
|
return CommissionsSchema(locale).isValidSync(commission)
|
||||||
}
|
}
|
||||||
|
|
||||||
const getWizardStep = (config, crypto) => {
|
const getWizardStep = (config, crypto) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue