mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
publish updates
This commit is contained in:
parent
4ed606cf4a
commit
8bfa030bed
2
src/@types/MetaData.d.ts
vendored
2
src/@types/MetaData.d.ts
vendored
@ -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
|
||||||
|
@ -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} />
|
||||||
))}
|
))}
|
||||||
|
|
||||||
|
{isLoading ? (
|
||||||
|
<Loader message={publishStepText} />
|
||||||
|
) : publishError ? (
|
||||||
|
<Alert text={publishError} state="error" />
|
||||||
|
) : (
|
||||||
<Button
|
<Button
|
||||||
style="primary"
|
style="primary"
|
||||||
type="submit"
|
type="submit"
|
||||||
disabled={
|
disabled={!ocean || !account || !isValid || status === 'empty'}
|
||||||
!ocean ||
|
|
||||||
!account ||
|
|
||||||
isSubmitting ||
|
|
||||||
!isValid ||
|
|
||||||
status === 'empty'
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
Submit
|
Submit
|
||||||
</Button>
|
</Button>
|
||||||
|
)}
|
||||||
<Persist name="ocean-publish-form" />
|
<Persist name="ocean-publish-form" />
|
||||||
</FormFormik>
|
</FormFormik>
|
||||||
)}
|
)}
|
||||||
|
Loading…
Reference in New Issue
Block a user