diff --git a/src/components/atoms/Alert.tsx b/src/components/atoms/Alert.tsx index 1610d6001..996900c50 100644 --- a/src/components/atoms/Alert.tsx +++ b/src/components/atoms/Alert.tsx @@ -1,4 +1,4 @@ -import React, { ReactElement } from 'react' +import React, { ReactElement, FormEvent } from 'react' import styles from './Alert.module.css' import Button from './Button' @@ -11,7 +11,10 @@ export default function Alert({ title?: string text: string state: 'error' | 'warning' | 'info' | 'success' - action?: { name: string; handleAction: () => void } + action?: { + name: string + handleAction: (e: FormEvent) => void + } }): ReactElement { return (
diff --git a/src/components/organisms/AssetContent/Price/Coin.module.css b/src/components/organisms/AssetContent/FormPricing/Coin.module.css similarity index 100% rename from src/components/organisms/AssetContent/Price/Coin.module.css rename to src/components/organisms/AssetContent/FormPricing/Coin.module.css diff --git a/src/components/organisms/AssetContent/Price/Coin.tsx b/src/components/organisms/AssetContent/FormPricing/Coin.tsx similarity index 100% rename from src/components/organisms/AssetContent/Price/Coin.tsx rename to src/components/organisms/AssetContent/FormPricing/Coin.tsx diff --git a/src/components/organisms/AssetContent/Price/Dynamic.module.css b/src/components/organisms/AssetContent/FormPricing/Dynamic.module.css similarity index 100% rename from src/components/organisms/AssetContent/Price/Dynamic.module.css rename to src/components/organisms/AssetContent/FormPricing/Dynamic.module.css diff --git a/src/components/organisms/AssetContent/Price/Dynamic.tsx b/src/components/organisms/AssetContent/FormPricing/Dynamic.tsx similarity index 85% rename from src/components/organisms/AssetContent/Price/Dynamic.tsx rename to src/components/organisms/AssetContent/FormPricing/Dynamic.tsx index 63d065700..d443f5bd1 100644 --- a/src/components/organisms/AssetContent/Price/Dynamic.tsx +++ b/src/components/organisms/AssetContent/FormPricing/Dynamic.tsx @@ -12,6 +12,7 @@ import styles from './Dynamic.module.css' import Fees from './Fees' import stylesIndex from './index.module.css' import { useFormikContext } from 'formik' +import { PriceOptionsMarket } from '../../../../@types/MetaData' export default function Dynamic({ datatokenOptions, @@ -22,7 +23,10 @@ export default function Dynamic({ }): ReactElement { const { appConfig } = useSiteMetadata() const { account, balance, networkId, refreshBalance } = useOcean() + + // Connect with form const { values } = useFormikContext() + const { price, weightOnDataToken } = values as PriceOptionsMarket const [error, setError] = useState() const correctNetwork = isCorrectNetwork(networkId) @@ -36,19 +40,12 @@ export default function Dynamic({ setError(`No account connected. Please connect your Web3 wallet.`) } else if (!correctNetwork) { setError(`Wrong Network. Please connect to ${desiredNetworkName}.`) - } else if (Number(balance.ocean) < Number(values.price)) { - setError(`Insufficient balance. You need at least ${values.price} OCEAN`) + } else if (Number(balance.ocean) < Number(price)) { + setError(`Insufficient balance. You need at least ${price} OCEAN`) } else { setError(undefined) } - }, [ - values.price, - networkId, - account, - balance, - correctNetwork, - desiredNetworkName - ]) + }, [price, networkId, account, balance, correctNetwork, desiredNetworkName]) // refetch balance periodically useEffect(() => { @@ -86,12 +83,12 @@ export default function Dynamic({
diff --git a/src/components/organisms/AssetContent/Price/Error.tsx b/src/components/organisms/AssetContent/FormPricing/Error.tsx similarity index 100% rename from src/components/organisms/AssetContent/Price/Error.tsx rename to src/components/organisms/AssetContent/FormPricing/Error.tsx diff --git a/src/components/organisms/AssetContent/Price/Fees.module.css b/src/components/organisms/AssetContent/FormPricing/Fees.module.css similarity index 87% rename from src/components/organisms/AssetContent/Price/Fees.module.css rename to src/components/organisms/AssetContent/FormPricing/Fees.module.css index 5564da7ca..e4cc6f044 100644 --- a/src/components/organisms/AssetContent/Price/Fees.module.css +++ b/src/components/organisms/AssetContent/FormPricing/Fees.module.css @@ -1,7 +1,7 @@ .fees { display: grid; gap: var(--spacer); - grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); + grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr)); margin-left: -2rem; margin-right: -2rem; border-bottom: 1px solid var(--brand-grey-lighter); diff --git a/src/components/organisms/AssetContent/Price/Fees.tsx b/src/components/organisms/AssetContent/FormPricing/Fees.tsx similarity index 100% rename from src/components/organisms/AssetContent/Price/Fees.tsx rename to src/components/organisms/AssetContent/FormPricing/Fees.tsx diff --git a/src/components/organisms/AssetContent/Price/Fixed.module.css b/src/components/organisms/AssetContent/FormPricing/Fixed.module.css similarity index 100% rename from src/components/organisms/AssetContent/Price/Fixed.module.css rename to src/components/organisms/AssetContent/FormPricing/Fixed.module.css diff --git a/src/components/organisms/AssetContent/Price/Fixed.tsx b/src/components/organisms/AssetContent/FormPricing/Fixed.tsx similarity index 100% rename from src/components/organisms/AssetContent/Price/Fixed.tsx rename to src/components/organisms/AssetContent/FormPricing/Fixed.tsx diff --git a/src/components/organisms/AssetContent/Price/index.module.css b/src/components/organisms/AssetContent/FormPricing/index.module.css similarity index 100% rename from src/components/organisms/AssetContent/Price/index.module.css rename to src/components/organisms/AssetContent/FormPricing/index.module.css diff --git a/src/components/organisms/AssetContent/Price/index.tsx b/src/components/organisms/AssetContent/FormPricing/index.tsx similarity index 92% rename from src/components/organisms/AssetContent/Price/index.tsx rename to src/components/organisms/AssetContent/FormPricing/index.tsx index 9d67094b0..b37f0736c 100644 --- a/src/components/organisms/AssetContent/Price/index.tsx +++ b/src/components/organisms/AssetContent/FormPricing/index.tsx @@ -38,20 +38,23 @@ const query = graphql` } ` -export default function Price(): ReactElement { +export default function FormPricing(): ReactElement { const { debug } = useUserPreferences() + // Get content const data = useStaticQuery(query) const content = data.content.edges[0].node.childPagesJson.price + // Connect with form const { values, setFieldValue } = useFormikContext() const { price, weightOnDataToken, type } = values as PriceOptionsMarket + // Switch type value upon tab change function handleTabChange(tabName: string) { const type = tabName.toLowerCase() setFieldValue('type', type) } - // Always update everything when price changes + // Always update everything when price value changes useEffect(() => { const dtAmount = Number(price) * Number(weightOnDataToken) setFieldValue('dtAmount', dtAmount) diff --git a/src/components/organisms/AssetContent/Pricing.tsx b/src/components/organisms/AssetContent/Pricing.tsx index f779f6fc1..2a3537485 100644 --- a/src/components/organisms/AssetContent/Pricing.tsx +++ b/src/components/organisms/AssetContent/Pricing.tsx @@ -1,13 +1,12 @@ -import React, { ReactElement, useState } from 'react' -import { Field, FieldInputProps, Formik } from 'formik' -import Input from '../../atoms/Input' +import React, { FormEvent, ReactElement, useState } from 'react' +import { Formik } from 'formik' import { initialValues, validationSchema } from '../../../models/FormPricing' import { DDO } from '@oceanprotocol/lib' import { usePricing } from '@oceanprotocol/react' import { PriceOptionsMarket } from '../../../@types/MetaData' import Alert from '../../atoms/Alert' import styles from './Pricing.module.css' -import Price from './Price' +import FormPricing from './FormPricing' export default function Pricing({ ddo }: { ddo: DDO }): ReactElement { const { createPricing } = usePricing(ddo) @@ -24,28 +23,33 @@ export default function Pricing({ ddo }: { ddo: DDO }): ReactElement { return (
- {showPricing ? ( - { - await handleCreatePricing(values) - setSubmitting(false) - }} - > - {(props) => } - - ) : ( - setShowPricing(true) - }} - /> - )} + { + await handleCreatePricing(values) + setSubmitting(false) + }} + > + {() => + showPricing ? ( + + ) : ( + ) => { + e.preventDefault() + setShowPricing(true) + } + }} + /> + ) + } +
) } diff --git a/src/components/pages/Publish/PublishForm.module.css b/src/components/pages/Publish/FormPublish.module.css similarity index 100% rename from src/components/pages/Publish/PublishForm.module.css rename to src/components/pages/Publish/FormPublish.module.css diff --git a/src/components/pages/Publish/PublishForm.tsx b/src/components/pages/Publish/FormPublish.tsx similarity index 94% rename from src/components/pages/Publish/PublishForm.tsx rename to src/components/pages/Publish/FormPublish.tsx index 56121f1ce..0e19aafbc 100644 --- a/src/components/pages/Publish/PublishForm.tsx +++ b/src/components/pages/Publish/FormPublish.tsx @@ -1,12 +1,12 @@ import React, { ReactElement, useEffect, FormEvent } from 'react' -import styles from './PublishForm.module.css' +import styles from './FormPublish.module.css' import { useOcean } from '@oceanprotocol/react' import { useFormikContext, Field } from 'formik' import Input from '../../atoms/Input' import Button from '../../atoms/Button' import { FormContent, FormFieldProps } from '../../../@types/Form' -export default function PublishForm({ +export default function FormPublish({ content }: { content: FormContent diff --git a/src/components/pages/Publish/index.tsx b/src/components/pages/Publish/index.tsx index 178f03496..a4af765f1 100644 --- a/src/components/pages/Publish/index.tsx +++ b/src/components/pages/Publish/index.tsx @@ -1,8 +1,8 @@ import React, { ReactElement, useState } from 'react' import { Formik } from 'formik' -import { usePublish, usePricing } from '@oceanprotocol/react' +import { usePublish } from '@oceanprotocol/react' import styles from './index.module.css' -import PublishForm from './PublishForm' +import FormPublish from './FormPublish' import Web3Feedback from '../../molecules/Wallet/Feedback' import { FormContent } from '../../../@types/Form' import { initialValues, validationSchema } from '../../../models/FormPublish' @@ -101,7 +101,7 @@ export default function PublishPage({ /> ) : (
- +