1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-11-15 01:34:57 +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 styles from './Feedback.module.css'
import SuccessConfetti from '../../atoms/SuccessConfetti'
import { DDO } from '@oceanprotocol/lib'
export default function Feedback({
error,
success,
did,
ddo,
publishStepText,
setError
}: {
error: string
success: string
did: string
ddo: DDO
publishStepText: string
setError: (error: string) => void
}): ReactElement {
@ -22,7 +23,7 @@ export default function Feedback({
<Button
style="primary"
size="small"
href={`/asset/${did}`}
href={`/asset/${ddo.id}`}
className={styles.action}
>
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 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 (
<Formik
initialValues={initialValues}
validationSchema={validationSchema}
onSubmit={async (values, { setSubmitting, resetForm }) => {
await handlePricing(values.amount, resetForm)
await handleCreatePricing(values)
setSubmitting(false)
}}
>
{({
values,
touched,
setTouched,
isSubmitting,
setFieldValue,
submitForm,
handleChange
}) => (
{() => (
<>
<Field name="price">
{({
field,
form
}: {
field: FieldInputProps<FormPricing>
field: FieldInputProps<PriceOptionsMarket>
form: any
}) => (
<Input

View File

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

View File

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