1
0
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:
Matthias Kretschmann 2020-09-21 19:16:33 +00:00
parent d1e1c75f86
commit d85f6c0777
4 changed files with 20 additions and 28 deletions

View File

@ -4,7 +4,7 @@ import {
AdditionalInformation, AdditionalInformation,
ServiceMetadata ServiceMetadata
} from '@oceanprotocol/lib' } from '@oceanprotocol/lib'
import { PriceOptions } from '@oceanprotocol/react' import { PriceOptions, DataTokenOptions } from '@oceanprotocol/react'
export interface AdditionalInformationMarket extends AdditionalInformation { export interface AdditionalInformationMarket extends AdditionalInformation {
links?: File[] links?: File[]
@ -21,6 +21,7 @@ export interface MetadataMarket extends Metadata {
export interface PriceOptionsMarket extends PriceOptions { export interface PriceOptionsMarket extends PriceOptions {
liquidityProviderFee: number liquidityProviderFee: number
datatoken?: DataTokenOptions
} }
export interface MetadataPublishForm { export interface MetadataPublishForm {

View File

@ -7,7 +7,7 @@ import Fixed from './Fixed'
import Dynamic from './Dynamic' import Dynamic from './Dynamic'
import { useField } from 'formik' import { useField } from 'formik'
import { useUserPreferences } from '../../../../providers/UserPreferences' import { useUserPreferences } from '../../../../providers/UserPreferences'
import { DataTokenOptions, useOcean } from '@oceanprotocol/react' import { useOcean } from '@oceanprotocol/react'
import { PriceOptionsMarket } from '../../../../@types/MetaData' import { PriceOptionsMarket } from '../../../../@types/MetaData'
const query = graphql` const query = graphql`
@ -49,7 +49,6 @@ export default function Price(props: InputProps): ReactElement {
const { price }: PriceOptionsMarket = field.value const { price }: PriceOptionsMarket = field.value
const [tokensToMint, setTokensToMint] = useState<number>() const [tokensToMint, setTokensToMint] = useState<number>()
const [datatokenOptions, setDatatokenOptions] = useState<DataTokenOptions>()
function handleTabChange(tabName: string) { function handleTabChange(tabName: string) {
const type = tabName.toLowerCase() const type = tabName.toLowerCase()
@ -58,8 +57,8 @@ export default function Price(props: InputProps): ReactElement {
function generateName() { function generateName() {
if (!ocean) return if (!ocean) return
const newDatatokenOptions = ocean.datatokens.generateDtName() const datatoken = ocean.datatokens.generateDtName()
setDatatokenOptions(newDatatokenOptions) helpers.setValue({ ...field.value, datatoken })
} }
// Always update everything when amountOcean changes // Always update everything when amountOcean changes
@ -79,7 +78,7 @@ export default function Price(props: InputProps): ReactElement {
title: content.fixed.title, title: content.fixed.title,
content: ( content: (
<Fixed <Fixed
datatokenOptions={datatokenOptions} datatokenOptions={field.value.datatoken}
generateName={generateName} generateName={generateName}
content={content.fixed} content={content.fixed}
/> />
@ -91,7 +90,7 @@ export default function Price(props: InputProps): ReactElement {
<Dynamic <Dynamic
ocean={price} ocean={price}
priceOptions={{ ...field.value, tokensToMint }} priceOptions={{ ...field.value, tokensToMint }}
datatokenOptions={datatokenOptions} datatokenOptions={field.value.datatoken}
generateName={generateName} generateName={generateName}
content={content.dynamic} content={content.dynamic}
/> />

View File

@ -2,7 +2,7 @@ import React, { ReactElement } from 'react'
import { useNavigate } from '@reach/router' import { useNavigate } from '@reach/router'
import { toast } from 'react-toastify' import { toast } from 'react-toastify'
import { Formik } from 'formik' import { Formik } from 'formik'
import { usePublish, DataTokenOptions } from '@oceanprotocol/react' import { usePublish } from '@oceanprotocol/react'
import styles from './index.module.css' import styles from './index.module.css'
import PublishForm from './PublishForm' import PublishForm from './PublishForm'
import Web3Feedback from '../../molecules/Wallet/Feedback' import Web3Feedback from '../../molecules/Wallet/Feedback'
@ -27,39 +27,30 @@ export default function PublishPage({
values: Partial<MetadataPublishForm>, values: Partial<MetadataPublishForm>,
resetForm: () => void resetForm: () => void
): Promise<void> { ): Promise<void> {
const metadata = transformPublishFormToMetadata( const metadata = transformPublishFormToMetadata(values)
values as MetadataPublishForm const { price } = values
)
const priceOptions = values.price
const serviceType = values.access === 'Download' ? 'access' : 'compute' const serviceType = values.access === 'Download' ? 'access' : 'compute'
let datatokenOptions: DataTokenOptions
try { try {
Logger.log('Publish with ', priceOptions, serviceType, datatokenOptions) Logger.log('Publish with ', price, serviceType, price.datatoken)
const ddo = await publish( const ddo = await publish(
metadata as any, metadata as any,
{ {
...priceOptions, ...price,
liquidityProviderFee: `${priceOptions.liquidityProviderFee}` liquidityProviderFee: `${price.liquidityProviderFee}`
}, },
serviceType, serviceType,
datatokenOptions price.datatoken
) )
if (publishError) { if (publishError) {
toast.error(publishError) toast.error(publishError) && console.error(publishError)
console.error(publishError)
return null return null
} }
// User feedback and redirect to new asset detail page // User feedback and redirect to new asset detail page
ddo && toast.success('Asset created successfully.') ddo && toast.success('Asset created successfully.') && resetForm()
// reset form state
// TODO: verify persistent form in localStorage is cleared with it too
resetForm()
// Go to new asset detail page // Go to new asset detail page
navigate(`/asset/${ddo.id}`) navigate(`/asset/${ddo.id}`)
} catch (error) { } catch (error) {

View File

@ -5,10 +5,11 @@ const testFormData: MetadataPublishForm = {
files: [], files: [],
license: '', license: '',
price: { price: {
tokensToMint: 1, price: 1,
type: 'simple', tokensToMint: 9,
type: 'fixed',
weightOnDataToken: '1', weightOnDataToken: '1',
liquidityProviderFee: '0.1' liquidityProviderFee: 0.1
}, },
name: '', name: '',
description: 'description', description: 'description',