mirror of
https://github.com/oceanprotocol/market.git
synced 2024-11-14 17:24:51 +01:00
remove cost, capture price type
This commit is contained in:
parent
91802e7a51
commit
19ccb80a48
2
src/@types/MetaData.d.ts
vendored
2
src/@types/MetaData.d.ts
vendored
@ -22,8 +22,8 @@ export interface MetadataPublishForm {
|
||||
author: string
|
||||
license: string
|
||||
price: {
|
||||
cost: number
|
||||
tokensToMint: number
|
||||
type: 'simple' | 'advanced' | string
|
||||
}
|
||||
access: 'Download' | 'Compute' | string
|
||||
termsAndConditions: boolean
|
||||
|
@ -9,16 +9,22 @@ interface TabsItem {
|
||||
|
||||
export default function Tabs({
|
||||
items,
|
||||
className
|
||||
className,
|
||||
handleTabChange
|
||||
}: {
|
||||
items: TabsItem[]
|
||||
className?: string
|
||||
handleTabChange?: (tabName: string) => void
|
||||
}): ReactElement {
|
||||
return (
|
||||
<ReactTabs className={`${className && className}`}>
|
||||
<TabList className={styles.tabList}>
|
||||
{items.map((item) => (
|
||||
<Tab className={styles.tab} key={item.title}>
|
||||
<Tab
|
||||
className={styles.tab}
|
||||
key={item.title}
|
||||
onClick={() => handleTabChange(item.title)}
|
||||
>
|
||||
{item.title}
|
||||
</Tab>
|
||||
))}
|
||||
|
@ -9,7 +9,6 @@ import { useField } from 'formik'
|
||||
export default function Price(props: InputProps): ReactElement {
|
||||
const [field, meta, helpers] = useField(props)
|
||||
|
||||
const cost = 1
|
||||
const weightOnDataToken = '90' // in %
|
||||
const [ocean, setOcean] = useState('1')
|
||||
const [tokensToMint, setTokensToMint] = useState<number>()
|
||||
@ -18,11 +17,17 @@ export default function Price(props: InputProps): ReactElement {
|
||||
setOcean(event.target.value)
|
||||
}
|
||||
|
||||
function handleTabChange(tabName: string) {
|
||||
const type = tabName.startsWith('Simple') ? 'simple' : 'advanced'
|
||||
helpers.setValue({ ...field.value, type })
|
||||
}
|
||||
|
||||
// Always update everything when ocean changes
|
||||
useEffect(() => {
|
||||
const tokensToMint = Number(ocean) * (Number(weightOnDataToken) / 10)
|
||||
setTokensToMint(tokensToMint)
|
||||
helpers.setValue({ cost, tokensToMint })
|
||||
console.log(field.value)
|
||||
helpers.setValue({ ...field.value, tokensToMint })
|
||||
}, [ocean])
|
||||
|
||||
const tabs = [
|
||||
@ -45,7 +50,7 @@ export default function Price(props: InputProps): ReactElement {
|
||||
|
||||
return (
|
||||
<div className={styles.price}>
|
||||
<Tabs items={tabs} />
|
||||
<Tabs items={tabs} handleTabChange={handleTabChange} />
|
||||
<pre>
|
||||
<code>{JSON.stringify(field.value)}</code>
|
||||
</pre>
|
||||
|
@ -28,20 +28,19 @@ export default function PublishPage({
|
||||
`)
|
||||
|
||||
const metadata = transformPublishFormToMetadata(values)
|
||||
const { cost, tokensToMint } = values.price
|
||||
const { tokensToMint, type } = values.price
|
||||
const serviceType = values.access === 'Download' ? 'access' : 'compute'
|
||||
|
||||
console.log(`
|
||||
Transformed metadata values:
|
||||
----------------------
|
||||
${JSON.stringify(metadata, null, 2)}
|
||||
Cost: ${cost}
|
||||
Tokens to mint: ${tokensToMint}
|
||||
`)
|
||||
|
||||
try {
|
||||
const ddo = await publish(metadata as any, tokensToMint.toString(), [
|
||||
{ serviceType, cost: cost.toString() }
|
||||
{ serviceType }
|
||||
])
|
||||
|
||||
if (publishError) {
|
||||
|
@ -7,8 +7,10 @@ export const validationSchema = Yup.object().shape<MetadataPublishForm>({
|
||||
name: Yup.string().required('Required'),
|
||||
author: Yup.string().required('Required'),
|
||||
price: Yup.object().shape({
|
||||
cost: Yup.number().required('Required'),
|
||||
tokensToMint: Yup.number().required('Required')
|
||||
tokensToMint: Yup.number().required('Required'),
|
||||
type: Yup.string()
|
||||
.matches(/simple|advanced/g)
|
||||
.required('Required')
|
||||
}),
|
||||
files: Yup.array<FileMetadata>().required('Required').nullable(),
|
||||
description: Yup.string().required('Required'),
|
||||
@ -28,7 +30,7 @@ export const initialValues: MetadataPublishForm = {
|
||||
name: undefined,
|
||||
author: undefined,
|
||||
price: {
|
||||
cost: 1,
|
||||
type: 'simple',
|
||||
tokensToMint: 1
|
||||
},
|
||||
files: undefined,
|
||||
|
Loading…
Reference in New Issue
Block a user