mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
Fix No error message for swapping more than max tokens (#1230)
* moved Error (field) component in shared components - moved Error.tsx from Pricing - change paths to Error.tsx in publish * added Error component with field validation * change setTimeout with lodash.debounce
This commit is contained in:
parent
69c3db2caa
commit
926838862a
@ -4,10 +4,13 @@ import {
|
|||||||
Field,
|
Field,
|
||||||
FieldInputProps,
|
FieldInputProps,
|
||||||
FormikContextType,
|
FormikContextType,
|
||||||
useFormikContext
|
useFormikContext,
|
||||||
|
useField
|
||||||
} from 'formik'
|
} from 'formik'
|
||||||
import Input from '@shared/FormInput'
|
import debounce from 'lodash.debounce'
|
||||||
import Button from '@shared/atoms/Button'
|
import Button from '@shared/atoms/Button'
|
||||||
|
import Input from '@shared/FormInput'
|
||||||
|
import Error from '@shared/FormInput/Error'
|
||||||
import { FormTradeData, TradeItem } from './_types'
|
import { FormTradeData, TradeItem } from './_types'
|
||||||
import UserLiquidity from '../UserLiquidity'
|
import UserLiquidity from '../UserLiquidity'
|
||||||
import { useWeb3 } from '@context/Web3'
|
import { useWeb3 } from '@context/Web3'
|
||||||
@ -28,11 +31,10 @@ export default function TradeInput({
|
|||||||
// Connect with form
|
// Connect with form
|
||||||
const {
|
const {
|
||||||
handleChange,
|
handleChange,
|
||||||
setFieldValue,
|
|
||||||
validateForm,
|
validateForm,
|
||||||
values
|
values
|
||||||
}: FormikContextType<FormTradeData> = useFormikContext()
|
}: FormikContextType<FormTradeData> = useFormikContext()
|
||||||
|
const [field, meta] = useField(name)
|
||||||
const isTopField =
|
const isTopField =
|
||||||
(name === 'baseToken' && values.type === 'buy') ||
|
(name === 'baseToken' && values.type === 'buy') ||
|
||||||
(name === 'datatoken' && values.type === 'sell')
|
(name === 'datatoken' && values.type === 'sell')
|
||||||
@ -61,11 +63,13 @@ export default function TradeInput({
|
|||||||
form={form}
|
form={form}
|
||||||
value={`${field.value}`}
|
value={`${field.value}`}
|
||||||
onChange={(e: ChangeEvent<HTMLInputElement>) => {
|
onChange={(e: ChangeEvent<HTMLInputElement>) => {
|
||||||
handleValueChange(name, Number(e.target.value))
|
|
||||||
validateForm()
|
|
||||||
handleChange(e)
|
handleChange(e)
|
||||||
|
handleValueChange(name, Number(e.target.value))
|
||||||
|
// debounce needed to avoid validating the wrong (pass) value
|
||||||
|
debounce(() => validateForm(), 100)
|
||||||
}}
|
}}
|
||||||
disabled={!accountId || disabled}
|
disabled={!accountId || disabled}
|
||||||
|
additionalComponent={<Error meta={meta} />}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</Field>
|
</Field>
|
||||||
|
@ -4,7 +4,7 @@ import InputElement from '@shared/FormInput/InputElement'
|
|||||||
import Logo from '@images/logo.svg'
|
import Logo from '@images/logo.svg'
|
||||||
import Conversion from '@shared/Price/Conversion'
|
import Conversion from '@shared/Price/Conversion'
|
||||||
import { useField } from 'formik'
|
import { useField } from 'formik'
|
||||||
import Error from './Error'
|
import Error from '@shared/FormInput/Error'
|
||||||
|
|
||||||
export default function Coin({
|
export default function Coin({
|
||||||
datatokenOptions,
|
datatokenOptions,
|
||||||
|
@ -3,7 +3,7 @@ import Tooltip from '@shared/atoms/Tooltip'
|
|||||||
import styles from './Fees.module.css'
|
import styles from './Fees.module.css'
|
||||||
import { useField } from 'formik'
|
import { useField } from 'formik'
|
||||||
import Input from '@shared/FormInput'
|
import Input from '@shared/FormInput'
|
||||||
import Error from './Error'
|
import Error from '@shared/FormInput/Error'
|
||||||
import { getOpcFees } from '../../../@utils/subgraph'
|
import { getOpcFees } from '../../../@utils/subgraph'
|
||||||
import { OpcFeesQuery_opc as OpcFeesData } from '../../../@types/subgraph/OpcFeesQuery'
|
import { OpcFeesQuery_opc as OpcFeesData } from '../../../@types/subgraph/OpcFeesQuery'
|
||||||
import { useWeb3 } from '@context/Web3'
|
import { useWeb3 } from '@context/Web3'
|
||||||
|
@ -2,7 +2,7 @@ import Conversion from '@shared/Price/Conversion'
|
|||||||
import { Field, 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 '@shared/FormInput/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'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user