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

fix rerender loop, properly populate chainId in form values

This commit is contained in:
Matthias Kretschmann 2021-11-11 08:46:52 +00:00
parent 03073d6f16
commit 51891f9b9f
Signed by: m
GPG Key ID: 606EEEF3C479A91F
3 changed files with 27 additions and 15 deletions

View File

@ -0,0 +1,22 @@
import { ReactElement, useEffect } from 'react'
import { useFormikContext } from 'formik'
import { wizardSteps } from './_constants'
import { useWeb3 } from '@context/Web3'
import { FormPublishData } from './_types'
export function Steps({ step }: { step: number }): ReactElement {
const { chainId } = useWeb3()
const { setFieldValue } = useFormikContext<FormPublishData>()
useEffect(() => {
if (!chainId) return
setFieldValue('chainId', chainId)
}, [chainId, setFieldValue])
const { component } = wizardSteps.filter(
(stepContent) => stepContent.step === step
)[0]
return component
}

View File

@ -33,7 +33,6 @@ export function transformPublishFormToDdo(data: Partial<FormPublishData>): DDO {
} = data.services[0] } = data.services[0]
const fileUrl = typeof files !== 'string' && files[0].url const fileUrl = typeof files !== 'string' && files[0].url
const filesEncrypted = encryptMe(files) const filesEncrypted = encryptMe(files)
const service: Service = { const service: Service = {
@ -49,6 +48,7 @@ export function transformPublishFormToDdo(data: Partial<FormPublishData>): DDO {
id: '', id: '',
version: '4.0.0', version: '4.0.0',
created: currentTime, created: currentTime,
updated: currentTime,
chainId: data.chainId, chainId: data.chainId,
metadata: { metadata: {
type, type,

View File

@ -1,12 +1,11 @@
import React, { ReactElement, useState, useEffect, useRef } from 'react' import React, { ReactElement, useState, useRef } from 'react'
import { Form, Formik, FormikState } from 'formik' import { Form, Formik, FormikState } from 'formik'
import { usePublish } from '@hooks/usePublish' import { usePublish } from '@hooks/usePublish'
import { initialValues, validationSchema, wizardSteps } from './_constants' import { initialValues, validationSchema } from './_constants'
import { validateDockerImage } from '@utils/docker' import { validateDockerImage } from '@utils/docker'
import { Logger, Metadata } from '@oceanprotocol/lib' import { Logger, Metadata } from '@oceanprotocol/lib'
import { useAccountPurgatory } from '@hooks/useAccountPurgatory' import { useAccountPurgatory } from '@hooks/useAccountPurgatory'
import { useWeb3 } from '@context/Web3' import { useWeb3 } from '@context/Web3'
import { FormPublishData } from './_types'
import { transformPublishFormToDdo } from './_utils' import { transformPublishFormToDdo } from './_utils'
import PageHeader from '@shared/Page/PageHeader' import PageHeader from '@shared/Page/PageHeader'
import Title from './Title' import Title from './Title'
@ -14,17 +13,10 @@ import styles from './index.module.css'
import Actions from './Actions' import Actions from './Actions'
import Debug from './Debug' import Debug from './Debug'
import Navigation from './Navigation' import Navigation from './Navigation'
import { Steps } from './Steps'
const formName = 'ocean-publish-form' const formName = 'ocean-publish-form'
function Steps({ step }: { step: number }) {
const { component } = wizardSteps.filter(
(stepContent) => stepContent.step === step
)[0]
return component
}
export default function PublishPage({ export default function PublishPage({
content content
}: { }: {
@ -101,9 +93,7 @@ export default function PublishPage({
// await handleSubmit(values, resetForm) // await handleSubmit(values, resetForm)
}} }}
> >
{({ values, setFieldValue }) => { {({ values }) => {
setFieldValue('chainId', chainId)
return ( return (
<> <>
<Form className={styles.form} ref={scrollToRef}> <Form className={styles.form} ref={scrollToRef}>