import { useEffect } from 'react' import { useAccount, useContractRead, useNetwork } from 'wagmi' import { Checkbox } from '@/components/ui/checkbox' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select' import { GOVERNANCE_CONTRACTS, GovernanceContract } from '@/config/site' import { UNI_ABI } from '@/lib/abis/UNI' import { FormItems } from '@/lib/types/types' import FormWrapper from '../FormWrapper' const GovernanceContractSelect = ({ errors, setGovContract, }: { errors: Record setGovContract: (govContact: GovernanceContract) => void contract: GovernanceContract }) => (
{errors.governanceContract &&

{errors.governanceContract}

}
) const WalletDetails = ({ walletAddress }: { walletAddress: string }) => (

Please connect your wallet to interact with the governance contract.

) const EligibilitySection = ({ govContract, walletAddress, errors, hasWalletConnected, isOnEthereum, }: { govContract: GovernanceContract walletAddress: string errors: Record hasWalletConnected: boolean isOnEthereum: boolean }) => { const { data: govData, isError, isLoading, } = useContractRead({ abi: UNI_ABI, address: govContract ? govContract.token : '', functionName: 'getCurrentVotes', args: [walletAddress], }) // tokens has 18 decimals, compare using BigInt const hasVotingPower = govData && BigInt(govData as bigint) >= BigInt('2500000000000000000000000') return (
{errors.loggedInChecked &&

{errors.loggedInChecked}

} {hasVotingPower !== undefined ? ( ) : (
)}
) } const CheckboxWithCondition = ({ id, condition, label, description }: { id: string; condition: boolean; label: string; description: string }) => (

{description}

) type GovernanceFormProps = { formData: FormItems errors: Record updateForm: (fieldToUpdate: Partial) => void } const ContractSelectionForm = ({ formData, errors, updateForm }: GovernanceFormProps) => { const { address, isConnected } = useAccount() const network = useNetwork().chain const hasWalletConnected = !!address && isConnected console.log('🚀 ~ file: ContractSelectionForm.tsx:182 ~ hasWalletConnected:', hasWalletConnected) const isOnEthereum = network?.id === 1 console.log('🚀 ~ file: ContractSelectionForm.tsx:183 ~ isOnEthereum:', isOnEthereum) useEffect(() => { updateForm({ walletAddress: address, loggedInChecked: hasWalletConnected, ethereumChecked: isOnEthereum, }) console.log('effect', formData) }, [address, hasWalletConnected, isOnEthereum]) const handleSetGovContract = (contract: GovernanceContract) => { updateForm({ governanceContract: contract, loggedInChecked: hasWalletConnected, ethereumChecked: isOnEthereum, // You can add any other fields from the contract that need to be set in formData here }) } return (
{address && ( )}
) } export default ContractSelectionForm