1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-11-15 09:44:53 +01:00

validation fixes

This commit is contained in:
Matthias Kretschmann 2020-09-21 14:41:38 +02:00
parent 2a13a760bd
commit 9008ad2018
Signed by: m
GPG Key ID: 606EEEF3C479A91F
6 changed files with 23 additions and 29 deletions

View File

@ -1,4 +1,4 @@
import React, { ReactElement, ChangeEvent } from 'react' import React, { ReactElement } from 'react'
import stylesIndex from './index.module.css' import stylesIndex from './index.module.css'
import styles from './Coin.module.css' import styles from './Coin.module.css'
import InputElement from '../../../atoms/Input/InputElement' import InputElement from '../../../atoms/Input/InputElement'
@ -21,7 +21,7 @@ export default function Coin({
generateName?: () => void generateName?: () => void
readOnly?: boolean readOnly?: boolean
}): ReactElement { }): ReactElement {
const [field, meta, helpers] = useField(name) const [field] = useField(name)
return ( return (
<div className={styles.coin}> <div className={styles.coin}>
@ -42,8 +42,6 @@ export default function Coin({
<div className={styles.data}> <div className={styles.data}>
<InputElement <InputElement
value={field.value}
name={name}
type="number" type="number"
readOnly={readOnly} readOnly={readOnly}
prefix={datatokenOptions?.symbol || 'DT'} prefix={datatokenOptions?.symbol || 'DT'}

View File

@ -18,7 +18,7 @@ export default function Dynamic({
generateName, generateName,
content content
}: { }: {
ocean: string ocean: number
priceOptions: PriceOptions priceOptions: PriceOptions
datatokenOptions: DataTokenOptions datatokenOptions: DataTokenOptions
generateName: () => void generateName: () => void

View File

@ -1,4 +1,4 @@
import React, { ChangeEvent, ReactElement } from 'react' import React, { ReactElement } from 'react'
import Tooltip from '../../../atoms/Tooltip' import Tooltip from '../../../atoms/Tooltip'
import styles from './Fees.module.css' import styles from './Fees.module.css'
import { useSiteMetadata } from '../../../../hooks/useSiteMetadata' import { useSiteMetadata } from '../../../../hooks/useSiteMetadata'
@ -11,14 +11,7 @@ export default function Fees({
tooltips: { [key: string]: string } tooltips: { [key: string]: string }
}): ReactElement { }): ReactElement {
const { appConfig } = useSiteMetadata() const { appConfig } = useSiteMetadata()
const [field, meta, helpers] = useField('price.liquidityProviderFee') const [field, meta] = useField('price.liquidityProviderFee')
// TODO: trigger Yup inline validation
function handleLiquidityProviderFeeChange(
event: ChangeEvent<HTMLInputElement>
) {
helpers.setValue(event.target.value)
}
return ( return (
<> <>
@ -31,15 +24,15 @@ export default function Fees({
</> </>
} }
type="number" type="number"
value={field.value}
name="price.liquidityProviderFee"
postfix="%" postfix="%"
onChange={handleLiquidityProviderFeeChange}
min="0.1" min="0.1"
max="0.9" max="0.9"
step="0.1" step="0.1"
small small
{...field} {...field}
additionalComponent={
meta.error && meta.touched && <div>{meta.error}</div>
}
/> />
<Input <Input
@ -70,7 +63,6 @@ export default function Fees({
small small
/> />
</div> </div>
{meta.error && meta.touched && <div>{meta.error}</div>}
</> </>
) )
} }

View File

@ -17,7 +17,7 @@ export default function Fixed({
generateName: () => void generateName: () => void
content: any content: any
}): ReactElement { }): ReactElement {
const [field, meta, helpers] = useField('price.price') const [field, meta] = useField('price.price')
return ( return (
<div className={styles.fixed}> <div className={styles.fixed}>

View File

@ -1,4 +1,4 @@
import React, { ReactElement, useState, ChangeEvent, useEffect } from 'react' import React, { ReactElement, useState, useEffect } from 'react'
import { graphql, useStaticQuery } from 'gatsby' import { graphql, useStaticQuery } from 'gatsby'
import { InputProps } from '../../../atoms/Input' import { InputProps } from '../../../atoms/Input'
import styles from './index.module.css' import styles from './index.module.css'
@ -45,7 +45,7 @@ export default function Price(props: InputProps): ReactElement {
const { ocean } = useOcean() const { ocean } = useOcean()
const [field, meta, helpers] = useField(props.name) const [field, meta, helpers] = useField(props.name)
const priceOptions: PriceOptions = field.value const { price }: PriceOptions = field.value
const [tokensToMint, setTokensToMint] = useState<number>() const [tokensToMint, setTokensToMint] = useState<number>()
const [datatokenOptions, setDatatokenOptions] = useState<DataTokenOptions>() const [datatokenOptions, setDatatokenOptions] = useState<DataTokenOptions>()
@ -63,11 +63,10 @@ export default function Price(props: InputProps): ReactElement {
// Always update everything when amountOcean changes // Always update everything when amountOcean changes
useEffect(() => { useEffect(() => {
const tokensToMint = const tokensToMint = Number(price) * Number(field.value.weightOnDataToken)
Number(field.value.price) * Number(priceOptions.weightOnDataToken)
setTokensToMint(tokensToMint) setTokensToMint(tokensToMint)
helpers.setValue({ ...field.value, tokensToMint }) helpers.setValue({ ...field.value, tokensToMint })
}, [field.value.price]) }, [price])
// Generate new DT name & symbol // Generate new DT name & symbol
useEffect(() => { useEffect(() => {
@ -89,8 +88,8 @@ export default function Price(props: InputProps): ReactElement {
title: content.dynamic.title, title: content.dynamic.title,
content: ( content: (
<Dynamic <Dynamic
ocean={field.value.price} ocean={price}
priceOptions={{ ...priceOptions, tokensToMint }} priceOptions={{ ...field.value, tokensToMint }}
datatokenOptions={datatokenOptions} datatokenOptions={datatokenOptions}
generateName={generateName} generateName={generateName}
content={content.dynamic} content={content.dynamic}

View File

@ -8,13 +8,18 @@ export const validationSchema = Yup.object().shape<MetadataPublishForm>({
author: Yup.string().required('Required'), author: Yup.string().required('Required'),
price: Yup.object() price: Yup.object()
.shape({ .shape({
price: Yup.number().min(1, 'Must be greater than 0').required('Required'), price: Yup.number()
tokensToMint: Yup.number().required('Required'), .min(1, 'Must be greater than 0')
.positive()
.required('Required'),
tokensToMint: Yup.number().positive().required('Required'),
type: Yup.string() type: Yup.string()
.matches(/fixed|dynamic/g) .matches(/fixed|dynamic/g)
.required('Required'), .required('Required'),
weightOnDataToken: Yup.string().required('Required'), weightOnDataToken: Yup.string().required('Required'),
liquidityProviderFee: Yup.string().min(0.1).max(0.9).required('Required') liquidityProviderFee: Yup.string()
.matches(/0.[0-9]/, 'Only values between 0.1 - 0.9 are allowed')
.required('Required')
}) })
.required('Required'), .required('Required'),
files: Yup.array<FileMetadata>().required('Required').nullable(), files: Yup.array<FileMetadata>().required('Required').nullable(),