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

collect cost & tokensToMint in form state

This commit is contained in:
Matthias Kretschmann 2020-07-21 11:56:53 +02:00
parent 5d10f25978
commit 5bb3744dc3
Signed by: m
GPG Key ID: 606EEEF3C479A91F
8 changed files with 36 additions and 15 deletions

View File

@ -35,11 +35,10 @@
"required": true "required": true
}, },
{ {
"name": "cost", "name": "price",
"label": "Price", "label": "Price",
"help": "Set your price for accessing this data set in Ocean Tokens.", "help": "Set your price for accessing this data set in Ocean Tokens.",
"type": "price", "type": "price",
"min": 1,
"required": true "required": true
}, },
{ {

View File

@ -24,7 +24,10 @@ export interface MetadataPublishForm {
files: string | File[] files: string | File[]
author: string author: string
license: string license: string
price: {
cost: string cost: string
tokensToMint: string
}
access: 'Download' | 'Compute' | string access: 'Download' | 'Compute' | string
termsAndConditions: boolean termsAndConditions: boolean
// ---- optional fields ---- // ---- optional fields ----

View File

@ -68,7 +68,6 @@ export default function InputElement(props: InputProps): ReactElement {
className={styles.input} className={styles.input}
name={name} name={name}
{...props} {...props}
value={value || ''}
type={type || 'text'} type={type || 'text'}
/> />
) )

View File

@ -3,17 +3,31 @@ import { InputProps } from '../../../atoms/Input'
import InputElement from '../../../atoms/Input/InputElement' import InputElement from '../../../atoms/Input/InputElement'
import styles from './index.module.css' import styles from './index.module.css'
import Label from '../../../atoms/Input/Label' import Label from '../../../atoms/Input/Label'
import { useFormikContext } from 'formik'
import { MetadataPublishForm } from '../../../../@types/MetaData'
export default function Price(props: InputProps): ReactElement { export default function Price(props: InputProps): ReactElement {
const { values } = useFormikContext()
return ( return (
<div className={styles.price}> <div className={styles.price}>
<div> <div>
<Label htmlFor="cost">Cost</Label> <Label htmlFor="price.cost">Cost</Label>
<InputElement {...props} type="number" /> <InputElement
{...props.field}
value={(values as MetadataPublishForm).price.cost}
name="price.cost"
type="number"
/>
</div> </div>
<div> <div>
<Label htmlFor="tokensToMint">Tokens to Mint</Label> <Label htmlFor="price.tokensToMint">Tokens to Mint</Label>
<InputElement name="tokensToMint" type="number" min="1" /> <InputElement
{...props.field}
value={(values as MetadataPublishForm).price.tokensToMint}
name="price.tokensToMint"
type="number"
/>
</div> </div>
</div> </div>
) )

View File

@ -38,6 +38,7 @@ export default function Preview({
key.includes('tags') || key.includes('tags') ||
key.includes('files') || key.includes('files') ||
key.includes('termsAndConditions') || key.includes('termsAndConditions') ||
key.includes('price') ||
value === undefined || value === undefined ||
value === '' value === ''
) )

View File

@ -8,7 +8,7 @@ import PublishForm from './PublishForm'
import Web3Feedback from '../../molecules/Wallet/Feedback' import Web3Feedback from '../../molecules/Wallet/Feedback'
import { FormContent } from '../../../@types/Form' import { FormContent } from '../../../@types/Form'
import { initialValues, validationSchema } from './validation' import { initialValues, validationSchema } from './validation'
import { MetadataPublishForm } from '../../../@types/Metadata' import { MetadataPublishForm, MetadataMarket } from '../../../@types/Metadata'
import { transformPublishFormToMetadata } from './utils' import { transformPublishFormToMetadata } from './utils'
import Preview from './Preview' import Preview from './Preview'
@ -28,20 +28,20 @@ export default function PublishPage({
`) `)
const metadata = transformPublishFormToMetadata(values) const metadata = transformPublishFormToMetadata(values)
const tokensToMint = '4' // how to know this? const { cost, tokensToMint } = values.price
const serviceType = values.access === 'Download' ? 'access' : 'compute' const serviceType = values.access === 'Download' ? 'access' : 'compute'
console.log(` console.log(`
Transformed metadata values: Transformed metadata values:
---------------------- ----------------------
${JSON.stringify(metadata, null, 2)} ${JSON.stringify(metadata, null, 2)}
Cost: 1 Cost: ${cost}
Tokens to mint: ${tokensToMint} Tokens to mint: ${tokensToMint}
`) `)
try { try {
const ddo = await publish(metadata as any, tokensToMint, [ const ddo = await publish(metadata as any, tokensToMint, [
{ serviceType, cost: '1' } { serviceType, cost }
]) ])
if (publishError) { if (publishError) {

View File

@ -6,7 +6,10 @@ export const validationSchema = Yup.object().shape<MetadataPublishForm>({
// ---- required fields ---- // ---- required fields ----
name: Yup.string().required('Required'), name: Yup.string().required('Required'),
author: Yup.string().required('Required'), author: Yup.string().required('Required'),
price: Yup.object().shape({
cost: Yup.string().required('Required'), cost: Yup.string().required('Required'),
tokensToMint: Yup.string().required('Required')
}),
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'),
@ -24,7 +27,10 @@ export const validationSchema = Yup.object().shape<MetadataPublishForm>({
export const initialValues: MetadataPublishForm = { export const initialValues: MetadataPublishForm = {
name: '', name: '',
author: '', author: '',
price: {
cost: '', cost: '',
tokensToMint: ''
},
files: '', files: '',
description: '', description: '',
license: '', license: '',

View File

@ -32,7 +32,6 @@ export const contentQuery = graphql`
type type
required required
options options
min
} }
success success
} }