Skip to content

Commit

Permalink
Skip validator query until it's needed
Browse files Browse the repository at this point in the history
  • Loading branch information
thesan committed Dec 28, 2023
1 parent ac96134 commit 6e750c4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ export const BuyMembershipForm = ({
const [formHandleMap, setFormHandleMap] = useState('')
const { isUploading, uploadAvatarAndSubmit } = useUploadAvatarAndSubmit(onSubmit)
const { data } = useGetMembersCountQuery({ variables: { where: { handle_eq: formHandleMap } } })
const { allValidators, allValidatorsWithCtrlAcc } = useValidators()

const form = useForm<MemberFormFields>({
resolver: useYupValidationResolver(CreateMemberSchema),
Expand All @@ -155,6 +154,7 @@ export const BuyMembershipForm = ({
'validatorAccountCandidate',
])

const { allValidators, allValidatorsWithCtrlAcc } = useValidators({ skip: isValidator ?? true })
const [validatorAccounts, setValidatorAccounts] = useState<Account[]>([])
const validatorAddresses = useMemo(() => {
if (!allValidatorsWithCtrlAcc || !allValidators) return
Expand Down
6 changes: 4 additions & 2 deletions packages/ui/src/validators/hooks/useValidators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import { useContext, useEffect } from 'react'

import { ValidatorsContext } from '../providers/context'

export const useValidators = () => {
type Props = { skip?: boolean }

export const useValidators = ({ skip = false }: Props = {}) => {
const { setShouldFetchValidators, allValidators, allValidatorsWithCtrlAcc, validatorsWithMembership } =
useContext(ValidatorsContext)

useEffect(() => {
setShouldFetchValidators(true)
if (!skip) setShouldFetchValidators(true)
}, [])

return { allValidators, allValidatorsWithCtrlAcc, validatorsWithMembership }
Expand Down

0 comments on commit 6e750c4

Please sign in to comment.