Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update form state according to balance #1459

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/lib/form/use-form.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { chain } from '@react-aria/utils';
import { FieldInputProps, FormikConfig, FormikErrors as FormErrors, FormikValues, useFormik } from 'formik';
import { FocusEvent, Key, useCallback } from 'react';
import { FocusEvent, Key, useCallback, useEffect } from 'react';
import { useDebounce } from 'react-use';

import { useGetBalances } from '@/utils/hooks/api/tokens/use-get-balances';

const getFieldName = (nameOrOptions: any) => {
const isOptions = nameOrOptions !== null && typeof nameOrOptions === 'object';
return isOptions ? nameOrOptions.name : nameOrOptions;
Expand Down Expand Up @@ -33,6 +35,8 @@ const useForm = <Values extends FormikValues = FormikValues>({
onComplete,
...args
}: UseFormArgs<Values>) => {
const { data: balances } = useGetBalances();

const {
validateForm,
values,
Expand All @@ -55,6 +59,12 @@ const useForm = <Values extends FormikValues = FormikValues>({
onComplete ? [values] : []
);

useEffect(() => {
if (!balances) return;

validateForm();
}, [balances, validateForm]);

// Handles when field gets forced blur to focus on modal
// If so, we dont want to consider it as touched if it has not yet been touched on
const handleBlur = useCallback(
Expand Down