mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
fix passing generated datatoken options
This commit is contained in:
parent
d1e1c75f86
commit
d85f6c0777
3
src/@types/MetaData.d.ts
vendored
3
src/@types/MetaData.d.ts
vendored
@ -4,7 +4,7 @@ import {
|
||||
AdditionalInformation,
|
||||
ServiceMetadata
|
||||
} from '@oceanprotocol/lib'
|
||||
import { PriceOptions } from '@oceanprotocol/react'
|
||||
import { PriceOptions, DataTokenOptions } from '@oceanprotocol/react'
|
||||
|
||||
export interface AdditionalInformationMarket extends AdditionalInformation {
|
||||
links?: File[]
|
||||
@ -21,6 +21,7 @@ export interface MetadataMarket extends Metadata {
|
||||
|
||||
export interface PriceOptionsMarket extends PriceOptions {
|
||||
liquidityProviderFee: number
|
||||
datatoken?: DataTokenOptions
|
||||
}
|
||||
|
||||
export interface MetadataPublishForm {
|
||||
|
@ -7,7 +7,7 @@ import Fixed from './Fixed'
|
||||
import Dynamic from './Dynamic'
|
||||
import { useField } from 'formik'
|
||||
import { useUserPreferences } from '../../../../providers/UserPreferences'
|
||||
import { DataTokenOptions, useOcean } from '@oceanprotocol/react'
|
||||
import { useOcean } from '@oceanprotocol/react'
|
||||
import { PriceOptionsMarket } from '../../../../@types/MetaData'
|
||||
|
||||
const query = graphql`
|
||||
@ -49,7 +49,6 @@ export default function Price(props: InputProps): ReactElement {
|
||||
const { price }: PriceOptionsMarket = field.value
|
||||
|
||||
const [tokensToMint, setTokensToMint] = useState<number>()
|
||||
const [datatokenOptions, setDatatokenOptions] = useState<DataTokenOptions>()
|
||||
|
||||
function handleTabChange(tabName: string) {
|
||||
const type = tabName.toLowerCase()
|
||||
@ -58,8 +57,8 @@ export default function Price(props: InputProps): ReactElement {
|
||||
|
||||
function generateName() {
|
||||
if (!ocean) return
|
||||
const newDatatokenOptions = ocean.datatokens.generateDtName()
|
||||
setDatatokenOptions(newDatatokenOptions)
|
||||
const datatoken = ocean.datatokens.generateDtName()
|
||||
helpers.setValue({ ...field.value, datatoken })
|
||||
}
|
||||
|
||||
// Always update everything when amountOcean changes
|
||||
@ -79,7 +78,7 @@ export default function Price(props: InputProps): ReactElement {
|
||||
title: content.fixed.title,
|
||||
content: (
|
||||
<Fixed
|
||||
datatokenOptions={datatokenOptions}
|
||||
datatokenOptions={field.value.datatoken}
|
||||
generateName={generateName}
|
||||
content={content.fixed}
|
||||
/>
|
||||
@ -91,7 +90,7 @@ export default function Price(props: InputProps): ReactElement {
|
||||
<Dynamic
|
||||
ocean={price}
|
||||
priceOptions={{ ...field.value, tokensToMint }}
|
||||
datatokenOptions={datatokenOptions}
|
||||
datatokenOptions={field.value.datatoken}
|
||||
generateName={generateName}
|
||||
content={content.dynamic}
|
||||
/>
|
||||
|
@ -2,7 +2,7 @@ import React, { ReactElement } from 'react'
|
||||
import { useNavigate } from '@reach/router'
|
||||
import { toast } from 'react-toastify'
|
||||
import { Formik } from 'formik'
|
||||
import { usePublish, DataTokenOptions } from '@oceanprotocol/react'
|
||||
import { usePublish } from '@oceanprotocol/react'
|
||||
import styles from './index.module.css'
|
||||
import PublishForm from './PublishForm'
|
||||
import Web3Feedback from '../../molecules/Wallet/Feedback'
|
||||
@ -27,39 +27,30 @@ export default function PublishPage({
|
||||
values: Partial<MetadataPublishForm>,
|
||||
resetForm: () => void
|
||||
): Promise<void> {
|
||||
const metadata = transformPublishFormToMetadata(
|
||||
values as MetadataPublishForm
|
||||
)
|
||||
const priceOptions = values.price
|
||||
const metadata = transformPublishFormToMetadata(values)
|
||||
const { price } = values
|
||||
const serviceType = values.access === 'Download' ? 'access' : 'compute'
|
||||
let datatokenOptions: DataTokenOptions
|
||||
|
||||
try {
|
||||
Logger.log('Publish with ', priceOptions, serviceType, datatokenOptions)
|
||||
Logger.log('Publish with ', price, serviceType, price.datatoken)
|
||||
|
||||
const ddo = await publish(
|
||||
metadata as any,
|
||||
{
|
||||
...priceOptions,
|
||||
liquidityProviderFee: `${priceOptions.liquidityProviderFee}`
|
||||
...price,
|
||||
liquidityProviderFee: `${price.liquidityProviderFee}`
|
||||
},
|
||||
serviceType,
|
||||
datatokenOptions
|
||||
price.datatoken
|
||||
)
|
||||
|
||||
if (publishError) {
|
||||
toast.error(publishError)
|
||||
console.error(publishError)
|
||||
toast.error(publishError) && console.error(publishError)
|
||||
return null
|
||||
}
|
||||
|
||||
// User feedback and redirect to new asset detail page
|
||||
ddo && toast.success('Asset created successfully.')
|
||||
|
||||
// reset form state
|
||||
// TODO: verify persistent form in localStorage is cleared with it too
|
||||
resetForm()
|
||||
|
||||
ddo && toast.success('Asset created successfully.') && resetForm()
|
||||
// Go to new asset detail page
|
||||
navigate(`/asset/${ddo.id}`)
|
||||
} catch (error) {
|
||||
|
@ -5,10 +5,11 @@ const testFormData: MetadataPublishForm = {
|
||||
files: [],
|
||||
license: '',
|
||||
price: {
|
||||
tokensToMint: 1,
|
||||
type: 'simple',
|
||||
price: 1,
|
||||
tokensToMint: 9,
|
||||
type: 'fixed',
|
||||
weightOnDataToken: '1',
|
||||
liquidityProviderFee: '0.1'
|
||||
liquidityProviderFee: 0.1
|
||||
},
|
||||
name: '',
|
||||
description: 'description',
|
||||
|
Loading…
Reference in New Issue
Block a user