mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
fix min validation input bug (#195)
* fix min validation input bug * tweak pool transactions number output so 0.00001 shows up
This commit is contained in:
parent
be8307f34d
commit
79e76dddb0
@ -10,8 +10,8 @@ import { formatCurrency } from '@coingecko/cryptoformat'
|
|||||||
import { useUserPreferences } from '../../providers/UserPreferences'
|
import { useUserPreferences } from '../../providers/UserPreferences'
|
||||||
|
|
||||||
function formatNumber(number: number, locale: string) {
|
function formatNumber(number: number, locale: string) {
|
||||||
return formatCurrency(number, '', locale, false, {
|
return formatCurrency(number, '', locale, true, {
|
||||||
significantFigures: 4
|
significantFigures: 6
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,11 +43,21 @@ export default function FormAdd({
|
|||||||
const {
|
const {
|
||||||
touched,
|
touched,
|
||||||
setTouched,
|
setTouched,
|
||||||
handleChange,
|
|
||||||
setFieldValue,
|
setFieldValue,
|
||||||
|
validateField,
|
||||||
values
|
values
|
||||||
}: FormikContextType<FormAddLiquidity> = useFormikContext()
|
}: FormikContextType<FormAddLiquidity> = useFormikContext()
|
||||||
|
|
||||||
|
function handleFieldChange(e: ChangeEvent<HTMLInputElement>) {
|
||||||
|
// Workaround so validation kicks in on first touch
|
||||||
|
!touched?.amount && setTouched({ amount: true })
|
||||||
|
|
||||||
|
// Manually handle change events instead of using `handleChange` from Formik.
|
||||||
|
// Solves bug where 0.0 can't be typed.
|
||||||
|
validateField('amount')
|
||||||
|
setFieldValue('amount', e.target.value)
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function calculatePoolShares() {
|
async function calculatePoolShares() {
|
||||||
if (!values.amount) {
|
if (!values.amount) {
|
||||||
@ -104,15 +114,12 @@ export default function FormAdd({
|
|||||||
name="amount"
|
name="amount"
|
||||||
max={amountMax}
|
max={amountMax}
|
||||||
value={`${values.amount}`}
|
value={`${values.amount}`}
|
||||||
|
step="any"
|
||||||
prefix={<CoinSelect dtSymbol={dtSymbol} setCoin={setCoin} />}
|
prefix={<CoinSelect dtSymbol={dtSymbol} setCoin={setCoin} />}
|
||||||
placeholder="0"
|
placeholder="0"
|
||||||
field={field}
|
field={field}
|
||||||
form={form}
|
form={form}
|
||||||
onChange={(e: ChangeEvent<HTMLInputElement>) => {
|
onChange={handleFieldChange}
|
||||||
// Workaround so validation kicks in on first touch
|
|
||||||
!touched?.amount && setTouched({ amount: true })
|
|
||||||
handleChange(e)
|
|
||||||
}}
|
|
||||||
disabled={!ocean}
|
disabled={!ocean}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
@ -123,6 +130,7 @@ export default function FormAdd({
|
|||||||
className={styles.buttonMax}
|
className={styles.buttonMax}
|
||||||
style="text"
|
style="text"
|
||||||
size="small"
|
size="small"
|
||||||
|
disabled={!ocean}
|
||||||
onClick={() => setFieldValue('amount', amountMax)}
|
onClick={() => setFieldValue('amount', amountMax)}
|
||||||
>
|
>
|
||||||
Use Max
|
Use Max
|
||||||
|
@ -11,6 +11,7 @@ import FormAdd from './FormAdd'
|
|||||||
import styles from './index.module.css'
|
import styles from './index.module.css'
|
||||||
import Token from '../Token'
|
import Token from '../Token'
|
||||||
import Alert from '../../../../atoms/Alert'
|
import Alert from '../../../../atoms/Alert'
|
||||||
|
import { useUserPreferences } from '../../../../../providers/UserPreferences'
|
||||||
|
|
||||||
const contentQuery = graphql`
|
const contentQuery = graphql`
|
||||||
query PoolAddQuery {
|
query PoolAddQuery {
|
||||||
@ -67,6 +68,7 @@ export default function Add({
|
|||||||
const content = data.content.edges[0].node.childContentJson.pool.add
|
const content = data.content.edges[0].node.childContentJson.pool.add
|
||||||
|
|
||||||
const { ocean, accountId, balance } = useOcean()
|
const { ocean, accountId, balance } = useOcean()
|
||||||
|
const { debug } = useUserPreferences()
|
||||||
const [txId, setTxId] = useState<string>()
|
const [txId, setTxId] = useState<string>()
|
||||||
const [coin, setCoin] = useState('OCEAN')
|
const [coin, setCoin] = useState('OCEAN')
|
||||||
const [dtBalance, setDtBalance] = useState<string>()
|
const [dtBalance, setDtBalance] = useState<string>()
|
||||||
@ -79,7 +81,7 @@ export default function Add({
|
|||||||
// https://github.com/jquense/yup#number
|
// https://github.com/jquense/yup#number
|
||||||
const validationSchema = Yup.object().shape<FormAddLiquidity>({
|
const validationSchema = Yup.object().shape<FormAddLiquidity>({
|
||||||
amount: Yup.number()
|
amount: Yup.number()
|
||||||
.min(0.0001, 'Must be more or equal to 0.0001')
|
.min(0.00001, (param) => `Must be more or equal to ${param.min}`)
|
||||||
.max(
|
.max(
|
||||||
Number(amountMax),
|
Number(amountMax),
|
||||||
`Maximum you can add is ${Number(amountMax).toFixed(2)} ${coin}`
|
`Maximum you can add is ${Number(amountMax).toFixed(2)} ${coin}`
|
||||||
@ -154,7 +156,7 @@ export default function Add({
|
|||||||
setSubmitting(false)
|
setSubmitting(false)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{({ isSubmitting, submitForm }) => (
|
{({ isSubmitting, submitForm, values }) => (
|
||||||
<>
|
<>
|
||||||
<div className={styles.addInput}>
|
<div className={styles.addInput}>
|
||||||
{isWarningAccepted ? (
|
{isWarningAccepted ? (
|
||||||
@ -204,6 +206,11 @@ export default function Add({
|
|||||||
action={submitForm}
|
action={submitForm}
|
||||||
txId={txId}
|
txId={txId}
|
||||||
/>
|
/>
|
||||||
|
{debug && (
|
||||||
|
<pre>
|
||||||
|
<code>{JSON.stringify(values, null, 2)}</code>
|
||||||
|
</pre>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</Formik>
|
</Formik>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user