mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
Free pricing: added confirm checkbox (#1086)
* added confirm checkbox and connect logic to wizard * add 'accessDetails' to displayed asset * restore initial state * adding 'freeAgreement' option to constants * moved checkbox for free item aggreament * improvement on amountDataToken validation * change Field component with Input and improve UI * change `onChange` property with `useField` hook * switch back to Formik Field Co-authored-by: Matthias Kretschmann <m@kretschmann.io>
This commit is contained in:
parent
3a424bc44c
commit
6c7a474136
@ -28,7 +28,16 @@
|
|||||||
},
|
},
|
||||||
"free": {
|
"free": {
|
||||||
"title": "Free",
|
"title": "Free",
|
||||||
"info": "Set your data set as free. The datatoken for this data set will be given for free via creating a faucet."
|
"info": "Set your data set as free. The datatoken for this data set will be given for free via creating a faucet.",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"name": "freeAgreement",
|
||||||
|
"type": "checkbox",
|
||||||
|
"options": [
|
||||||
|
"I want this asset to be free. I understand network fees are still to be paid"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"pool": {
|
"pool": {
|
||||||
|
1
src/@types/Price.d.ts
vendored
1
src/@types/Price.d.ts
vendored
@ -60,4 +60,5 @@ interface PriceOptions {
|
|||||||
weightOnOcean: string
|
weightOnOcean: string
|
||||||
// easier to keep this as number for Yup input validation
|
// easier to keep this as number for Yup input validation
|
||||||
swapFee: number
|
swapFee: number
|
||||||
|
freeAgreement: boolean
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,31 @@
|
|||||||
import React, { ReactElement } from 'react'
|
import React, { ReactElement, useEffect } from 'react'
|
||||||
|
import { useFormikContext } from 'formik'
|
||||||
|
import { FormPublishData } from '../_types'
|
||||||
import FormHelp from '@shared/FormInput/Help'
|
import FormHelp from '@shared/FormInput/Help'
|
||||||
import Price from './Price'
|
import Price from './Price'
|
||||||
import styles from './Dynamic.module.css'
|
import styles from './Dynamic.module.css'
|
||||||
|
|
||||||
export default function Free({ content }: { content: any }): ReactElement {
|
export default function Free({ content }: { content: any }): ReactElement {
|
||||||
|
// connect with Form state, use for conditional field rendering
|
||||||
|
const { values, setFieldValue } = useFormikContext<FormPublishData>()
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// if the user has agreed, then set pricing to continue
|
||||||
|
if (values.pricing.freeAgreement) {
|
||||||
|
setFieldValue('pricing.price', 1)
|
||||||
|
setFieldValue('pricing.amountDataToken', 1000)
|
||||||
|
} else {
|
||||||
|
// disabled continue button if the user hasn't agree to the "free agreement"
|
||||||
|
setFieldValue('pricing.price', 0)
|
||||||
|
setFieldValue('pricing.amountDataToken', 0)
|
||||||
|
}
|
||||||
|
}, [setFieldValue, values])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<FormHelp>{content.info}</FormHelp>
|
<FormHelp>{content.info}</FormHelp>
|
||||||
<h4 className={styles.title}>Price</h4>
|
<h4 className={styles.title}>Price</h4>
|
||||||
<Price />
|
<Price content={content} />
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.free {
|
.free {
|
||||||
text-align: center;
|
text-align: left;
|
||||||
margin: calc(var(--spacer) / 2) 0;
|
margin: calc(var(--spacer) / 2);
|
||||||
font-size: var(--font-size-base);
|
font-size: var(--font-size-base);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.free [class*='FormInput_field'] {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
@ -1,16 +1,19 @@
|
|||||||
import Conversion from '@shared/Price/Conversion'
|
import Conversion from '@shared/Price/Conversion'
|
||||||
import { useField, useFormikContext } from 'formik'
|
import { Field, useField, useFormikContext } from 'formik'
|
||||||
import React, { ReactElement } from 'react'
|
import React, { ReactElement } from 'react'
|
||||||
import Input from '@shared/FormInput'
|
import Input from '@shared/FormInput'
|
||||||
import Error from './Error'
|
import Error from './Error'
|
||||||
import PriceUnit from '@shared/Price/PriceUnit'
|
import PriceUnit from '@shared/Price/PriceUnit'
|
||||||
import styles from './Price.module.css'
|
import styles from './Price.module.css'
|
||||||
import { FormPublishData } from '../_types'
|
import { FormPublishData } from '../_types'
|
||||||
|
import { getFieldContent } from '../_utils'
|
||||||
|
|
||||||
export default function Price({
|
export default function Price({
|
||||||
firstPrice
|
firstPrice,
|
||||||
|
content
|
||||||
}: {
|
}: {
|
||||||
firstPrice?: string
|
firstPrice?: string
|
||||||
|
content?: any
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const [field, meta] = useField('pricing.price')
|
const [field, meta] = useField('pricing.price')
|
||||||
|
|
||||||
@ -20,7 +23,13 @@ export default function Price({
|
|||||||
return (
|
return (
|
||||||
<div className={styles.price}>
|
<div className={styles.price}>
|
||||||
{values.pricing.type === 'free' ? (
|
{values.pricing.type === 'free' ? (
|
||||||
<h4 className={styles.free}>Free</h4>
|
<div className={styles.free}>
|
||||||
|
<Field
|
||||||
|
{...getFieldContent('freeAgreement', content.fields)}
|
||||||
|
component={Input}
|
||||||
|
name="pricing.freeAgreement"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<div className={styles.grid}>
|
<div className={styles.grid}>
|
||||||
|
@ -23,7 +23,9 @@ export default function PricingFields(): ReactElement {
|
|||||||
function handleTabChange(tabName: string) {
|
function handleTabChange(tabName: string) {
|
||||||
const type = tabName.toLowerCase()
|
const type = tabName.toLowerCase()
|
||||||
setFieldValue('pricing.type', type)
|
setFieldValue('pricing.type', type)
|
||||||
type === 'dynamic' && setFieldValue('pricing.amountDataToken', 1000)
|
setFieldValue('pricing.price', 0)
|
||||||
|
setFieldValue('pricing.freeAgreement', false)
|
||||||
|
type !== 'free' && setFieldValue('pricing.amountDataToken', 1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always update everything when price value changes
|
// Always update everything when price value changes
|
||||||
|
@ -96,7 +96,8 @@ export const initialValues: FormPublishData = {
|
|||||||
amountOcean: 50,
|
amountOcean: 50,
|
||||||
weightOnOcean: '5', // 50% on OCEAN
|
weightOnOcean: '5', // 50% on OCEAN
|
||||||
weightOnDataToken: '5', // 50% on datatoken
|
weightOnDataToken: '5', // 50% on datatoken
|
||||||
swapFee: 0.1 // in %
|
swapFee: 0.1, // in %
|
||||||
|
freeAgreement: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user