diff --git a/src/@types/MetaData.d.ts b/src/@types/MetaData.d.ts index 8d75484ee..855973144 100644 --- a/src/@types/MetaData.d.ts +++ b/src/@types/MetaData.d.ts @@ -22,8 +22,8 @@ export interface MetadataPublishForm { author: string license: string price: { - cost: number tokensToMint: number + type: 'simple' | 'advanced' | string } access: 'Download' | 'Compute' | string termsAndConditions: boolean diff --git a/src/components/atoms/Tabs.tsx b/src/components/atoms/Tabs.tsx index 88f2f0878..62abb6012 100644 --- a/src/components/atoms/Tabs.tsx +++ b/src/components/atoms/Tabs.tsx @@ -9,16 +9,22 @@ interface TabsItem { export default function Tabs({ items, - className + className, + handleTabChange }: { items: TabsItem[] className?: string + handleTabChange?: (tabName: string) => void }): ReactElement { return ( {items.map((item) => ( - + handleTabChange(item.title)} + > {item.title} ))} diff --git a/src/components/molecules/FormFields/Price/index.tsx b/src/components/molecules/FormFields/Price/index.tsx index c07761eb9..9a0a264ce 100644 --- a/src/components/molecules/FormFields/Price/index.tsx +++ b/src/components/molecules/FormFields/Price/index.tsx @@ -9,7 +9,6 @@ import { useField } from 'formik' export default function Price(props: InputProps): ReactElement { const [field, meta, helpers] = useField(props) - const cost = 1 const weightOnDataToken = '90' // in % const [ocean, setOcean] = useState('1') const [tokensToMint, setTokensToMint] = useState() @@ -18,11 +17,17 @@ export default function Price(props: InputProps): ReactElement { setOcean(event.target.value) } + function handleTabChange(tabName: string) { + const type = tabName.startsWith('Simple') ? 'simple' : 'advanced' + helpers.setValue({ ...field.value, type }) + } + // Always update everything when ocean changes useEffect(() => { const tokensToMint = Number(ocean) * (Number(weightOnDataToken) / 10) setTokensToMint(tokensToMint) - helpers.setValue({ cost, tokensToMint }) + console.log(field.value) + helpers.setValue({ ...field.value, tokensToMint }) }, [ocean]) const tabs = [ @@ -45,7 +50,7 @@ export default function Price(props: InputProps): ReactElement { return (
- +
         {JSON.stringify(field.value)}
       
diff --git a/src/components/pages/Publish/index.tsx b/src/components/pages/Publish/index.tsx index eac998386..887b690f5 100644 --- a/src/components/pages/Publish/index.tsx +++ b/src/components/pages/Publish/index.tsx @@ -28,20 +28,19 @@ export default function PublishPage({ `) const metadata = transformPublishFormToMetadata(values) - const { cost, tokensToMint } = values.price + const { tokensToMint, type } = values.price const serviceType = values.access === 'Download' ? 'access' : 'compute' console.log(` Transformed metadata values: ---------------------- ${JSON.stringify(metadata, null, 2)} - Cost: ${cost} Tokens to mint: ${tokensToMint} `) try { const ddo = await publish(metadata as any, tokensToMint.toString(), [ - { serviceType, cost: cost.toString() } + { serviceType } ]) if (publishError) { diff --git a/src/models/FormPublish.ts b/src/models/FormPublish.ts index d4cfc3a9f..5f4c5d1e0 100644 --- a/src/models/FormPublish.ts +++ b/src/models/FormPublish.ts @@ -7,8 +7,10 @@ export const validationSchema = Yup.object().shape({ name: Yup.string().required('Required'), author: Yup.string().required('Required'), price: Yup.object().shape({ - cost: Yup.number().required('Required'), - tokensToMint: Yup.number().required('Required') + tokensToMint: Yup.number().required('Required'), + type: Yup.string() + .matches(/simple|advanced/g) + .required('Required') }), files: Yup.array().required('Required').nullable(), description: Yup.string().required('Required'), @@ -28,7 +30,7 @@ export const initialValues: MetadataPublishForm = { name: undefined, author: undefined, price: { - cost: 1, + type: 'simple', tokensToMint: 1 }, files: undefined,