1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00

publish updates

This commit is contained in:
Matthias Kretschmann 2020-07-17 13:01:52 +02:00
parent 4ed606cf4a
commit 8bfa030bed
Signed by: m
GPG Key ID: 606EEEF3C479A91F
2 changed files with 26 additions and 24 deletions

View File

@ -23,7 +23,7 @@ export interface MetadataPublishForm {
author: string author: string
license: string license: string
cost: string cost: string
access: string access: 'Download' | 'Compute' | string
termsAndConditions: boolean termsAndConditions: boolean
// ---- optional fields ---- // ---- optional fields ----
copyrightHolder?: string copyrightHolder?: string

View File

@ -13,6 +13,8 @@ import { MetadataPublishForm } from '../../../@types/Metadata'
import { File as FileMetadata } from '@oceanprotocol/lib/dist/node/ddo/interfaces/File' import { File as FileMetadata } from '@oceanprotocol/lib/dist/node/ddo/interfaces/File'
import { useSiteMetadata } from '../../../hooks/useSiteMetadata' import { useSiteMetadata } from '../../../hooks/useSiteMetadata'
import { Persist } from 'formik-persist' import { Persist } from 'formik-persist'
import Loader from '../../atoms/Loader'
import Alert from '../../atoms/Alert'
const validationSchema = Yup.object().shape<MetadataPublishForm>({ const validationSchema = Yup.object().shape<MetadataPublishForm>({
// ---- required fields ---- // ---- required fields ----
@ -22,7 +24,9 @@ const validationSchema = Yup.object().shape<MetadataPublishForm>({
files: Yup.array<FileMetadata>().required('Required').nullable(), files: Yup.array<FileMetadata>().required('Required').nullable(),
description: Yup.string().required('Required'), description: Yup.string().required('Required'),
license: Yup.string().required('Required'), license: Yup.string().required('Required'),
access: Yup.string().min(4).required('Required'), access: Yup.string()
.matches(/Compute|Download/g)
.required('Required'),
termsAndConditions: Yup.boolean().required('Required'), termsAndConditions: Yup.boolean().required('Required'),
// ---- optional fields ---- // ---- optional fields ----
@ -51,7 +55,7 @@ export default function PublishForm({
content: FormContent content: FormContent
}): ReactElement { }): ReactElement {
const { ocean, account } = useOcean() const { ocean, account } = useOcean()
const { publish } = usePublish() const { publish, publishStepText, isLoading, publishError } = usePublish()
const navigate = useNavigate() const navigate = useNavigate()
const { marketAddress } = useSiteMetadata() const { marketAddress } = useSiteMetadata()
@ -66,22 +70,20 @@ export default function PublishForm({
const metadata = transformPublishFormToMetadata(values) const metadata = transformPublishFormToMetadata(values)
const tokensToMint = '4' // how to know this? const tokensToMint = '4' // how to know this?
const serviceType = values.access === 'Download' ? 'access' : 'compute'
console.log(` console.log(`
Transformed metadata values: Transformed metadata values:
---------------------- ----------------------
${JSON.stringify(metadata)} ${JSON.stringify(metadata)}
Cost: ${values.cost} Cost: 1
Tokens to mint: ${tokensToMint} Tokens to mint: ${tokensToMint}
`) `)
try { try {
const ddo = await publish( const ddo = await publish(metadata as any, tokensToMint, marketAddress, [
metadata as any, { serviceType, cost: '1' }
tokensToMint, ])
marketAddress,
values.cost
)
// User feedback and redirect to new asset detail page // User feedback and redirect to new asset detail page
toast.success('asset created successfully') toast.success('asset created successfully')
@ -105,7 +107,7 @@ export default function PublishForm({
setSubmitting(false) setSubmitting(false)
}} }}
> >
{({ isSubmitting, isValid, status, setStatus }) => ( {({ isValid, status, setStatus }) => (
<FormFormik <FormFormik
className={styles.form} className={styles.form}
onChange={() => status === 'empty' && setStatus(null)} onChange={() => status === 'empty' && setStatus(null)}
@ -114,19 +116,19 @@ export default function PublishForm({
<Field key={field.name} {...field} component={Input} /> <Field key={field.name} {...field} component={Input} />
))} ))}
<Button {isLoading ? (
style="primary" <Loader message={publishStepText} />
type="submit" ) : publishError ? (
disabled={ <Alert text={publishError} state="error" />
!ocean || ) : (
!account || <Button
isSubmitting || style="primary"
!isValid || type="submit"
status === 'empty' disabled={!ocean || !account || !isValid || status === 'empty'}
} >
> Submit
Submit </Button>
</Button> )}
<Persist name="ocean-publish-form" /> <Persist name="ocean-publish-form" />
</FormFormik> </FormFormik>
)} )}