diff --git a/src/features/swap/SwapForm.tsx b/src/features/swap/SwapForm.tsx index 3da54fd..cde9e59 100644 --- a/src/features/swap/SwapForm.tsx +++ b/src/features/swap/SwapForm.tsx @@ -60,7 +60,7 @@ export function SwapFormCard() { } function SwapForm() { - const balances = useAppSelector((s) => s.account.balances) + const { balances, lastUpdated } = useAppSelector((s) => s.account) const { showSlippage } = useAppSelector((s) => s.swap) const dispatch = useAppDispatch() @@ -68,7 +68,7 @@ function SwapForm() { dispatch(setFormValues(values)) dispatch(setConfirmView(true)) // Switch to confirm view } - const validateForm = useFormValidator(balances) + const validateForm = useFormValidator(balances, lastUpdated) const storedFormValues = useAppSelector((s) => s.swap.formValues) // Get stored form values const initialFormValues = storedFormValues || initialValues // Use stored values if they exist diff --git a/src/features/swap/useFormValidator.ts b/src/features/swap/useFormValidator.ts index 410731f..4f26f1a 100644 --- a/src/features/swap/useFormValidator.ts +++ b/src/features/swap/useFormValidator.ts @@ -9,11 +9,12 @@ import { areAmountsNearlyEqual, parseAmount, toWei } from 'src/utils/amount' import { logger } from 'src/utils/logger' import { useChainId } from 'wagmi' -export function useFormValidator(balances: AccountBalances) { +export function useFormValidator(balances: AccountBalances, lastUpdated: number | null) { const chainId = useChainId() return useCallback( (values?: SwapFormValues): Promise> => { return (async () => { + if (!lastUpdated) return { fromTokenId: 'Balance still loading' } if (!values || !values.amount) return { amount: 'Amount Required' } const parsedAmount = parseAmount(values.amount) if (!parsedAmount) return { amount: 'Amount is Invalid' } @@ -33,7 +34,7 @@ export function useFormValidator(balances: AccountBalances) { return {} }) }, - [balances, chainId] + [balances, chainId, lastUpdated] ) }