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

Default weight change to 70/30 (#211)

* dt weight tests

* update weights

* validation and defaults tweaks
This commit is contained in:
Matthias Kretschmann 2020-11-10 13:52:02 +01:00 committed by GitHub
parent eabb696f49
commit a19e7bca04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 13 deletions

View File

@ -71,7 +71,7 @@ export default function Input(props: Partial<InputProps>): ReactElement {
</Label> </Label>
<InputElement size={size} {...field} {...props} /> <InputElement size={size} {...field} {...props} />
{field && field.name !== 'price' && hasError && ( {field && hasError && (
<div className={styles.error}> <div className={styles.error}>
<ErrorMessage name={field.name} /> <ErrorMessage name={field.name} />
</div> </div>

View File

@ -1,4 +1,4 @@
import React, { ReactElement } from 'react' import React, { ChangeEvent, ReactElement } from 'react'
import stylesIndex from './index.module.css' import stylesIndex from './index.module.css'
import styles from './Coin.module.css' import styles from './Coin.module.css'
import InputElement from '../../../../atoms/Input/InputElement' import InputElement from '../../../../atoms/Input/InputElement'

View File

@ -9,7 +9,7 @@ import Coin from './Coin'
import styles from './Dynamic.module.css' import styles from './Dynamic.module.css'
import Fees from './Fees' import Fees from './Fees'
import stylesIndex from './index.module.css' import stylesIndex from './index.module.css'
import { useFormikContext } from 'formik' import { FormikContextType, useFormikContext } from 'formik'
import { PriceOptionsMarket } from '../../../../../@types/MetaData' import { PriceOptionsMarket } from '../../../../../@types/MetaData'
import { DDO } from '@oceanprotocol/lib' import { DDO } from '@oceanprotocol/lib'
import Price from './Price' import Price from './Price'
@ -28,7 +28,8 @@ export default function Dynamic({
const [firstPrice, setFirstPrice] = useState<string>() const [firstPrice, setFirstPrice] = useState<string>()
// Connect with form // Connect with form
const { values } = useFormikContext() const { values }: FormikContextType<PriceOptionsMarket> = useFormikContext()
const { const {
price, price,
weightOnDataToken, weightOnDataToken,
@ -36,7 +37,7 @@ export default function Dynamic({
swapFee, swapFee,
dtAmount, dtAmount,
oceanAmount oceanAmount
} = values as PriceOptionsMarket } = values
const [error, setError] = useState<string>() const [error, setError] = useState<string>()

View File

@ -104,6 +104,7 @@ export default function Pricing({ ddo }: { ddo: DDO }): ReactElement {
<Formik <Formik
initialValues={initialValues} initialValues={initialValues}
validationSchema={validationSchema} validationSchema={validationSchema}
validateOnChange
onSubmit={async (values, { setSubmitting }) => { onSubmit={async (values, { setSubmitting }) => {
// move user's focus to top of screen // move user's focus to top of screen
window.scrollTo({ top: 0, left: 0, behavior: 'smooth' }) window.scrollTo({ top: 0, left: 0, behavior: 'smooth' })

View File

@ -2,10 +2,14 @@ import { PriceOptionsMarket } from '../@types/MetaData'
import * as Yup from 'yup' import * as Yup from 'yup'
export const validationSchema = Yup.object().shape<PriceOptionsMarket>({ export const validationSchema = Yup.object().shape<PriceOptionsMarket>({
price: Yup.number().min(1, 'Must be greater than 1').required('Required'), price: Yup.number()
dtAmount: Yup.number().min(9, 'Must be greater than 9').required('Required'), .min(1, (param) => `Must be more or equal to ${param.min}`)
.required('Required'),
dtAmount: Yup.number()
.min(9, (param) => `Must be more or equal to ${param.min}`)
.required('Required'),
oceanAmount: Yup.number() oceanAmount: Yup.number()
.min(1, 'Must be greater than 0') .min(21, (param) => `Must be more or equal to ${param.min}`)
.required('Required'), .required('Required'),
type: Yup.string() type: Yup.string()
.matches(/fixed|dynamic/g) .matches(/fixed|dynamic/g)
@ -13,7 +17,7 @@ export const validationSchema = Yup.object().shape<PriceOptionsMarket>({
weightOnDataToken: Yup.string().required('Required'), weightOnDataToken: Yup.string().required('Required'),
weightOnOcean: Yup.string().required('Required'), weightOnOcean: Yup.string().required('Required'),
swapFee: Yup.number() swapFee: Yup.number()
.min(0.1, 'Must be more or equal to 0.1') .min(0.1, (param) => `Must be more or equal to ${param.min}`)
.max(10, 'Maximum is 10%') .max(10, 'Maximum is 10%')
.required('Required') .required('Required')
.nullable() .nullable()
@ -22,9 +26,9 @@ export const validationSchema = Yup.object().shape<PriceOptionsMarket>({
export const initialValues: PriceOptionsMarket = { export const initialValues: PriceOptionsMarket = {
price: 1, price: 1,
type: 'dynamic', type: 'dynamic',
dtAmount: 10, dtAmount: 9,
oceanAmount: 10, oceanAmount: 21,
weightOnOcean: '5', // 50% on OCEAN weightOnOcean: '7', // 70% on OCEAN
weightOnDataToken: '5', // 50% on datatoken weightOnDataToken: '3', // 30% on datatoken
swapFee: 0.1 // in % swapFee: 0.1 // in %
} }