From 087151cf8366f42364e905d0bed7d9255691705b Mon Sep 17 00:00:00 2001 From: Adam Gall Date: Sun, 5 May 2024 15:01:16 -0400 Subject: [PATCH] Don't use the intermediary `useDelegateVote` for delegating from the VotesERC20 contract address, also switch to using the viem contract --- src/components/ui/modals/DelegateModal.tsx | 30 ++++++++++++++++------ src/hooks/DAO/useDelegateVote.ts | 3 +-- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/components/ui/modals/DelegateModal.tsx b/src/components/ui/modals/DelegateModal.tsx index 1dd792877d..abe4b5924f 100644 --- a/src/components/ui/modals/DelegateModal.tsx +++ b/src/components/ui/modals/DelegateModal.tsx @@ -2,13 +2,16 @@ import { Box, Button, Divider, Flex, SimpleGrid, Spacer, Text } from '@chakra-ui import { LabelWrapper } from '@decent-org/fractal-ui'; import { Field, FieldAttributes, Formik } from 'formik'; import { useTranslation } from 'react-i18next'; -import { zeroAddress, getAddress } from 'viem'; +import { zeroAddress, getAddress, getContract } from 'viem'; +import { useWalletClient } from 'wagmi'; import * as Yup from 'yup'; +import VotesERC20Abi from '../../../assets/abi/VotesERC20'; import { LockRelease__factory } from '../../../assets/typechain-types/dcnt'; import useDelegateVote from '../../../hooks/DAO/useDelegateVote'; import useSafeContracts from '../../../hooks/safe/useSafeContracts'; import { useValidationAddress } from '../../../hooks/schemas/common/useValidationAddress'; import useDisplayName from '../../../hooks/utils/useDisplayName'; +import { useTransaction } from '../../../hooks/utils/useTransaction'; import { useFractal } from '../../../providers/App/AppProvider'; import { useEthersSigner } from '../../../providers/Ethers/hooks/useEthersSigner'; import { AzoriusGovernance, DecentGovernance } from '../../../types'; @@ -35,19 +38,28 @@ export function DelegateModal({ close }: { close: Function }) { const delegateeDisplayName = useDisplayName(azoriusGovernance?.votesToken?.delegatee); const lockedDelegateeDisplayName = useDisplayName(decentGovernance?.lockedVotesToken?.delegatee); const { delegateVote, contractCallPending } = useDelegateVote(); + const [, contractCallPendingViem, contractCallViem] = useTransaction(); const { addressValidationTest } = useValidationAddress(); + const { data: walletClient } = useWalletClient(); const submitDelegation = async (values: { address: string }) => { - if (!votesTokenContractAddress || !baseContracts) return; - let validAddress = values.address; + if (!votesTokenContractAddress || !baseContracts || !walletClient) return; + let validAddress = getAddress(values.address); if (couldBeENS(validAddress) && signer) { validAddress = getAddress(await signer.resolveName(values.address)); } - const votingTokenContract = - baseContracts.votesTokenMasterCopyContract.asSigner.attach(votesTokenContractAddress); - delegateVote({ - delegatee: validAddress, - votingTokenContract, + + const votingTokenContract = getContract({ + abi: VotesERC20Abi, + address: getAddress(votesTokenContractAddress), + client: walletClient, + }); + + contractCallViem({ + contractFn: () => votingTokenContract.write.delegate([validAddress]), + pendingMessage: t('pendingDelegateVote'), + failedMessage: t('failedDelegateVote'), + successMessage: t('successDelegateVote'), successCallback: () => { close(); }, @@ -207,6 +219,7 @@ export function DelegateModal({ close }: { close: Function }) { isDisabled={ !!errors.address || contractCallPending || + contractCallPendingViem || !values.address || values.address === azoriusGovernance.votesToken?.delegatee } @@ -222,6 +235,7 @@ export function DelegateModal({ close }: { close: Function }) { isDisabled={ !!errors.address || contractCallPending || + contractCallPendingViem || !values.address || values.address === decentGovernance.lockedVotesToken.delegatee } diff --git a/src/hooks/DAO/useDelegateVote.ts b/src/hooks/DAO/useDelegateVote.ts index eb80711927..f53b1c5f03 100644 --- a/src/hooks/DAO/useDelegateVote.ts +++ b/src/hooks/DAO/useDelegateVote.ts @@ -1,4 +1,3 @@ -import { VotesERC20 } from '@fractal-framework/fractal-contracts'; import { useCallback } from 'react'; import { useTranslation } from 'react-i18next'; import { LockRelease } from '../../assets/typechain-types/dcnt'; @@ -16,7 +15,7 @@ const useDelegateVote = () => { successCallback, }: { delegatee: string; - votingTokenContract: VotesERC20 | LockRelease; + votingTokenContract: LockRelease; successCallback?: () => void; }) => { contractCallDelegateVote({