From eb8221d104837ef9d96be61215e695b3e67444a0 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Mon, 21 Sep 2020 17:50:45 +0000 Subject: [PATCH] more fixes --- src/components/molecules/FormFields/Price/Coin.tsx | 6 ++---- src/components/molecules/FormFields/Price/Error.tsx | 13 +++++++++++++ src/components/molecules/FormFields/Price/Fees.tsx | 9 ++------- src/components/molecules/FormFields/Price/Fixed.tsx | 6 ++---- src/components/molecules/FormFields/Price/index.tsx | 2 +- src/models/FormPublish.ts | 4 +++- 6 files changed, 23 insertions(+), 17 deletions(-) create mode 100644 src/components/molecules/FormFields/Price/Error.tsx diff --git a/src/components/molecules/FormFields/Price/Coin.tsx b/src/components/molecules/FormFields/Price/Coin.tsx index f5bff2d2d..9e92b9f80 100644 --- a/src/components/molecules/FormFields/Price/Coin.tsx +++ b/src/components/molecules/FormFields/Price/Coin.tsx @@ -1,13 +1,13 @@ import React, { ReactElement } from 'react' import stylesIndex from './index.module.css' import styles from './Coin.module.css' -import stylesInput from '../../../atoms/Input/index.module.css' import InputElement from '../../../atoms/Input/InputElement' import { ReactComponent as Logo } from '../../../../images/logo.svg' import Conversion from '../../../atoms/Price/Conversion' import { DataTokenOptions } from '@oceanprotocol/react' import RefreshName from './RefreshName' import { useField } from 'formik' +import Error from './Error' export default function Coin({ datatokenOptions, @@ -51,9 +51,7 @@ export default function Coin({ {datatokenOptions?.symbol === 'OCEAN' && ( )} - {meta.error && meta.touched && ( -
{meta.error}
- )} + ) diff --git a/src/components/molecules/FormFields/Price/Error.tsx b/src/components/molecules/FormFields/Price/Error.tsx new file mode 100644 index 000000000..2d25d0816 --- /dev/null +++ b/src/components/molecules/FormFields/Price/Error.tsx @@ -0,0 +1,13 @@ +import { FieldMetaProps } from 'formik' +import React, { ReactElement } from 'react' +import stylesInput from '../../../atoms/Input/index.module.css' + +export default function Error({ + meta +}: { + meta: FieldMetaProps +}): ReactElement { + return meta.error ? ( +
{meta.error}
+ ) : null +} diff --git a/src/components/molecules/FormFields/Price/Fees.tsx b/src/components/molecules/FormFields/Price/Fees.tsx index 256f89872..2e19db493 100644 --- a/src/components/molecules/FormFields/Price/Fees.tsx +++ b/src/components/molecules/FormFields/Price/Fees.tsx @@ -1,10 +1,10 @@ import React, { ReactElement } from 'react' import Tooltip from '../../../atoms/Tooltip' import styles from './Fees.module.css' -import stylesInput from '../../../atoms/Input/index.module.css' import { useSiteMetadata } from '../../../../hooks/useSiteMetadata' import { useField } from 'formik' import Input from '../../../atoms/Input' +import Error from './Error' export default function Fees({ tooltips @@ -31,12 +31,7 @@ export default function Fees({ step="0.1" small {...field} - additionalComponent={ - meta.error && - meta.touched && ( -
{meta.error}
- ) - } + additionalComponent={} /> } /> - {meta.error && meta.touched && ( -
{meta.error}
- )} + {datatokenOptions && ( diff --git a/src/components/molecules/FormFields/Price/index.tsx b/src/components/molecules/FormFields/Price/index.tsx index 6e0e7395a..c5c938004 100644 --- a/src/components/molecules/FormFields/Price/index.tsx +++ b/src/components/molecules/FormFields/Price/index.tsx @@ -7,7 +7,7 @@ import Fixed from './Fixed' import Dynamic from './Dynamic' import { useField } from 'formik' import { useUserPreferences } from '../../../../providers/UserPreferences' -import { DataTokenOptions, PriceOptions, useOcean } from '@oceanprotocol/react' +import { DataTokenOptions, useOcean } from '@oceanprotocol/react' import { PriceOptionsMarket } from '../../../../@types/MetaData' const query = graphql` diff --git a/src/models/FormPublish.ts b/src/models/FormPublish.ts index b6fb6796a..7bc78a9f4 100644 --- a/src/models/FormPublish.ts +++ b/src/models/FormPublish.ts @@ -9,7 +9,9 @@ export const validationSchema = Yup.object().shape({ price: Yup.object() .shape({ price: Yup.number().min(1, 'Must be greater than 0').required('Required'), - tokensToMint: Yup.number().positive().required('Required'), + tokensToMint: Yup.number() + .min(1, 'Must be greater than 0') + .required('Required'), type: Yup.string() .matches(/fixed|dynamic/g) .required('Required'),