Skip to content

Commit

Permalink
Revert "feat: added balance updated check"
Browse files Browse the repository at this point in the history
This reverts commit 3dfd732.
  • Loading branch information
RyRy79261 committed Dec 13, 2024
1 parent 3dfd732 commit dad87b8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/features/swap/SwapForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ export function SwapFormCard() {
}

function SwapForm() {
const { balances, lastUpdated } = useAppSelector((s) => s.account)
const balances = useAppSelector((s) => s.account.balances)
const { showSlippage } = useAppSelector((s) => s.swap)

const dispatch = useAppDispatch()
const onSubmit = (values: SwapFormValues) => {
dispatch(setFormValues(values))
dispatch(setConfirmView(true)) // Switch to confirm view
}
const validateForm = useFormValidator(balances, lastUpdated)
const validateForm = useFormValidator(balances)
const storedFormValues = useAppSelector((s) => s.swap.formValues) // Get stored form values
const initialFormValues = storedFormValues || initialValues // Use stored values if they exist

Expand Down
5 changes: 2 additions & 3 deletions src/features/swap/useFormValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ import { areAmountsNearlyEqual, parseAmount, toWei } from 'src/utils/amount'
import { logger } from 'src/utils/logger'
import { useChainId } from 'wagmi'

export function useFormValidator(balances: AccountBalances, lastUpdated: number | null) {
export function useFormValidator(balances: AccountBalances) {
const chainId = useChainId()
return useCallback(
(values?: SwapFormValues): Promise<FormikErrors<SwapFormValues>> => {
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' }
Expand All @@ -34,7 +33,7 @@ export function useFormValidator(balances: AccountBalances, lastUpdated: number
return {}
})
},
[balances, chainId, lastUpdated]
[balances, chainId]
)
}

Expand Down

0 comments on commit dad87b8

Please sign in to comment.