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

more publish data flow changes

This commit is contained in:
Matthias Kretschmann 2020-10-19 15:04:57 +02:00
parent 95e72ae108
commit 8ce53714a4
Signed by: m
GPG Key ID: 606EEEF3C479A91F
4 changed files with 49 additions and 55 deletions

View File

@ -4,17 +4,18 @@ import Loader from '../../atoms/Loader'
import React, { ReactElement } from 'react' import React, { ReactElement } from 'react'
import styles from './Feedback.module.css' import styles from './Feedback.module.css'
import SuccessConfetti from '../../atoms/SuccessConfetti' import SuccessConfetti from '../../atoms/SuccessConfetti'
import { DDO } from '@oceanprotocol/lib'
export default function Feedback({ export default function Feedback({
error, error,
success, success,
did, ddo,
publishStepText, publishStepText,
setError setError
}: { }: {
error: string error: string
success: string success: string
did: string ddo: DDO
publishStepText: string publishStepText: string
setError: (error: string) => void setError: (error: string) => void
}): ReactElement { }): ReactElement {
@ -22,7 +23,7 @@ export default function Feedback({
<Button <Button
style="primary" style="primary"
size="small" size="small"
href={`/asset/${did}`} href={`/asset/${ddo.id}`}
className={styles.action} className={styles.action}
> >
Go to data set Go to data set

View File

@ -1,34 +1,42 @@
import React, { ReactElement, useState, useEffect } from 'react' import React, { ReactElement } from 'react'
import { Field, FieldInputProps, Formik } from 'formik' import { Field, FieldInputProps, Formik } from 'formik'
import Input from '../../atoms/Input' import Input from '../../atoms/Input'
import { FormPricing } from 'models/FormPricing' import { initialValues, validationSchema } from 'models/FormPricing'
import { DDO } from '@oceanprotocol/lib'
import { usePricing } from '@oceanprotocol/react'
import { PriceOptionsMarket } from '../../../@types/MetaData'
export default function Pricing({ ddo }: { ddo: DDO }): ReactElement {
const { createPricing } = usePricing(ddo)
async function handleCreatePricing(values: Partial<PriceOptionsMarket>) {
const priceOptions = {
price: values.price,
tokensToMint: values.tokensToMint,
type: values.type,
weightOnDataToken: values.weightOnDataToken,
swapFee: values.swapFee
}
const tx = await createPricing(priceOptions)
}
export default function Pricing(): ReactElement {
return ( return (
<Formik <Formik
initialValues={initialValues} initialValues={initialValues}
validationSchema={validationSchema} validationSchema={validationSchema}
onSubmit={async (values, { setSubmitting, resetForm }) => { onSubmit={async (values, { setSubmitting, resetForm }) => {
await handlePricing(values.amount, resetForm) await handleCreatePricing(values)
setSubmitting(false) setSubmitting(false)
}} }}
> >
{({ {() => (
values,
touched,
setTouched,
isSubmitting,
setFieldValue,
submitForm,
handleChange
}) => (
<> <>
<Field name="price"> <Field name="price">
{({ {({
field, field,
form form
}: { }: {
field: FieldInputProps<FormPricing> field: FieldInputProps<PriceOptionsMarket>
form: any form: any
}) => ( }) => (
<Input <Input

View File

@ -10,7 +10,7 @@ import { transformPublishFormToMetadata } from './utils'
import Preview from './Preview' import Preview from './Preview'
import { MetadataPublishForm } from '../../../@types/MetaData' import { MetadataPublishForm } from '../../../@types/MetaData'
import { useUserPreferences } from '../../../providers/UserPreferences' import { useUserPreferences } from '../../../providers/UserPreferences'
import { Logger, Metadata } from '@oceanprotocol/lib' import { DDO, Logger, Metadata } from '@oceanprotocol/lib'
import { Persist } from '../../atoms/FormikPersist' import { Persist } from '../../atoms/FormikPersist'
import Debug from './Debug' import Debug from './Debug'
import Feedback from './Feedback' import Feedback from './Feedback'
@ -27,7 +27,7 @@ export default function PublishPage({
const [success, setSuccess] = useState<string>() const [success, setSuccess] = useState<string>()
const [error, setError] = useState<string>() const [error, setError] = useState<string>()
const [did, setDid] = useState<string>() const [ddo, setDdo] = useState<DDO>()
const hasFeedback = isLoading || error || success const hasFeedback = isLoading || error || success
@ -61,7 +61,7 @@ export default function PublishPage({
// Publish succeeded // Publish succeeded
if (ddo) { if (ddo) {
setDid(ddo.id) setDdo(ddo)
setSuccess('🎉 Successfully published your data set. 🎉') setSuccess('🎉 Successfully published your data set. 🎉')
resetForm() resetForm()
} }
@ -93,7 +93,7 @@ export default function PublishPage({
error={error} error={error}
success={success} success={success}
publishStepText={publishStepText} publishStepText={publishStepText}
did={did} ddo={ddo}
setError={setError} setError={setError}
/> />
) : ( ) : (

View File

@ -1,13 +1,7 @@
import { PriceOptionsMarket } from '../@types/MetaData' import { PriceOptionsMarket } from '../@types/MetaData'
import * as Yup from 'yup' import * as Yup from 'yup'
export interface FormPricing { export const validationSchema = Yup.object().shape<PriceOptionsMarket>({
price: PriceOptionsMarket
}
export const validationSchema = Yup.object().shape<FormPricing>({
price: Yup.object()
.shape({
price: Yup.number().min(1, 'Must be greater than 0').required('Required'), price: Yup.number().min(1, 'Must be greater than 0').required('Required'),
tokensToMint: Yup.number() tokensToMint: Yup.number()
.min(1, 'Must be greater than 0') .min(1, 'Must be greater than 0')
@ -19,23 +13,14 @@ export const validationSchema = Yup.object().shape<FormPricing>({
swapFee: Yup.number() swapFee: Yup.number()
.min(0.1, 'Must be more or equal to 0.1') .min(0.1, 'Must be more or equal to 0.1')
.max(0.9, 'Must be less or equal to 0.9') .max(0.9, 'Must be less or equal to 0.9')
.required('Required'), .required('Required')
datatoken: Yup.object()
.shape({
name: Yup.string(),
symbol: Yup.string()
})
.nullable() .nullable()
}) })
.required('Required')
})
export const initialValues: Partial<FormPricing> = { export const initialValues: Partial<PriceOptionsMarket> = {
price: {
price: 1, price: 1,
type: 'dynamic', type: 'dynamic',
tokensToMint: 1, tokensToMint: 1,
weightOnDataToken: '9', // 90% on data token weightOnDataToken: '9', // 90% on data token
swapFee: 0.1 // in % swapFee: 0.1 // in %
} }
}