Skip to content

Commit

Permalink
Don't use the intermediary useDelegateVote for delegating from the …
Browse files Browse the repository at this point in the history
…VotesERC20 contract address, also switch to using the viem contract
  • Loading branch information
adamgall committed May 5, 2024
1 parent c71f821 commit 087151c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
30 changes: 22 additions & 8 deletions src/components/ui/modals/DelegateModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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();
},
Expand Down Expand Up @@ -207,6 +219,7 @@ export function DelegateModal({ close }: { close: Function }) {
isDisabled={
!!errors.address ||
contractCallPending ||
contractCallPendingViem ||
!values.address ||
values.address === azoriusGovernance.votesToken?.delegatee
}
Expand All @@ -222,6 +235,7 @@ export function DelegateModal({ close }: { close: Function }) {
isDisabled={
!!errors.address ||
contractCallPending ||
contractCallPendingViem ||
!values.address ||
values.address === decentGovernance.lockedVotesToken.delegatee
}
Expand Down
3 changes: 1 addition & 2 deletions src/hooks/DAO/useDelegateVote.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -16,7 +15,7 @@ const useDelegateVote = () => {
successCallback,
}: {
delegatee: string;
votingTokenContract: VotesERC20 | LockRelease;
votingTokenContract: LockRelease;
successCallback?: () => void;
}) => {
contractCallDelegateVote({
Expand Down

0 comments on commit 087151c

Please sign in to comment.