mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
Price length and decimals number validation (#1225)
* price length and decimals number validation * undefined parameter fix * fixes * use the decimals constant in regex * validation added for moire fields * cleanup * swap fee decimals fixes * constant fix * use max 6 decimals for swap fee * remove unused code Co-authored-by: ClaudiaHolhos <claudia@oceanprotocol.com>
This commit is contained in:
parent
47144d80b5
commit
65f0c5c675
@ -1 +1 @@
|
||||
export const MAX_DECIMALS = 5
|
||||
export const MAX_DECIMALS = 6
|
||||
|
@ -34,7 +34,13 @@ export default function Price({
|
||||
<>
|
||||
<div className={styles.grid}>
|
||||
<div className={styles.form}>
|
||||
<Input type="number" prefix="OCEAN" {...field} />
|
||||
<Input
|
||||
type="number"
|
||||
min="1"
|
||||
placeholder="0"
|
||||
prefix="OCEAN"
|
||||
{...field}
|
||||
/>
|
||||
<Error meta={meta} />
|
||||
</div>
|
||||
<div className={styles.datatoken}>
|
||||
|
@ -1,8 +1,10 @@
|
||||
import { MAX_DECIMALS } from '@utils/constants'
|
||||
import * as Yup from 'yup'
|
||||
|
||||
// TODO: conditional validation
|
||||
// e.g. when algo is selected, Docker image is required
|
||||
// hint, hint: https://github.com/jquense/yup#mixedwhenkeys-string--arraystring-builder-object--value-schema-schema-schema
|
||||
|
||||
const validationMetadata = {
|
||||
type: Yup.string()
|
||||
.matches(/dataset|algorithm/g, { excludeEmptyString: true })
|
||||
@ -54,25 +56,53 @@ const validationService = {
|
||||
})
|
||||
}
|
||||
|
||||
const maxDecimalsValidation = new RegExp(
|
||||
'^\\d+(\\.\\d{1,' + MAX_DECIMALS + '})?$'
|
||||
)
|
||||
|
||||
const validationPricing = {
|
||||
type: Yup.string()
|
||||
.matches(/fixed|dynamic|free/g, { excludeEmptyString: true })
|
||||
.required('Required'),
|
||||
// https://github.com/jquense/yup#mixedwhenkeys-string--arraystring-builder-object--value-schema-schema-schema
|
||||
|
||||
price: Yup.number()
|
||||
.min(1, (param: { min: number }) => `Must be more or equal to ${param.min}`)
|
||||
.max(
|
||||
1000000,
|
||||
(param: { max: number }) => `Must be less than or equal to ${param.max}`
|
||||
)
|
||||
.test(
|
||||
'maxDigitsAfterDecimal',
|
||||
`Must have maximum ${MAX_DECIMALS} decimal digits`,
|
||||
(param) => maxDecimalsValidation.test(param?.toString())
|
||||
)
|
||||
.required('Required'),
|
||||
amountDataToken: Yup.number()
|
||||
.min(50, (param) => `Must be more or equal to ${param.min}`)
|
||||
.required('Required'),
|
||||
amountOcean: Yup.number()
|
||||
.min(50, (param) => `Must be more or equal to ${param.min}`)
|
||||
.max(
|
||||
1000000,
|
||||
(param: { max: number }) => `Must be less than or equal to ${param.max}`
|
||||
)
|
||||
.test(
|
||||
'maxDigitsAfterDecimal',
|
||||
`Must have maximum ${MAX_DECIMALS} decimal digits`,
|
||||
(param) => maxDecimalsValidation.test(param?.toString())
|
||||
)
|
||||
.required('Required'),
|
||||
weightOnDataToken: Yup.string().required('Required'),
|
||||
weightOnOcean: Yup.string().required('Required'),
|
||||
swapFee: Yup.number()
|
||||
.min(0.1, (param) => `Must be more or equal to ${param.min}`)
|
||||
.max(10, 'Maximum is 10%')
|
||||
.test(
|
||||
'maxDigitsAfterDecimal',
|
||||
`Must have maximum ${MAX_DECIMALS} decimal digits`,
|
||||
(param) => maxDecimalsValidation.test(param?.toString())
|
||||
)
|
||||
.required('Required')
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user