From b82050ba5bf2c7264ab354331ad5bbd47c8186c6 Mon Sep 17 00:00:00 2001 From: Carlos Juarez Date: Fri, 8 Mar 2024 16:26:35 +0100 Subject: [PATCH] chore: much cleaner refetch --- plugins/dualGovernance/hooks/useProposalVeto.tsx | 3 ++- plugins/dualGovernance/hooks/useUserCanVeto.tsx | 12 ++---------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/plugins/dualGovernance/hooks/useProposalVeto.tsx b/plugins/dualGovernance/hooks/useProposalVeto.tsx index 0807dceb..9eaa430f 100644 --- a/plugins/dualGovernance/hooks/useProposalVeto.tsx +++ b/plugins/dualGovernance/hooks/useProposalVeto.tsx @@ -36,7 +36,7 @@ export function useProposalVeto(proposalId: string) { } = useWriteContract(); const { isLoading: isConfirming, isSuccess: isConfirmed } = useWaitForTransactionReceipt({ hash: vetoTxHash }); - const canVeto = useUserCanVeto(BigInt(proposalId), isConfirmed) as boolean; + const { canVeto, canVetoRefetch } = useUserCanVeto(BigInt(proposalId)); useEffect(() => { if (vetoingStatus === "idle" || vetoingStatus === "pending") return; @@ -66,6 +66,7 @@ export function useProposalVeto(proposalId: string) { type: "success", txHash: vetoTxHash, }); + canVetoRefetch(); }, [vetoingStatus, vetoTxHash, isConfirming, isConfirmed]); const vetoProposal = () => { diff --git a/plugins/dualGovernance/hooks/useUserCanVeto.tsx b/plugins/dualGovernance/hooks/useUserCanVeto.tsx index 196b7d1c..9f96f51b 100644 --- a/plugins/dualGovernance/hooks/useUserCanVeto.tsx +++ b/plugins/dualGovernance/hooks/useUserCanVeto.tsx @@ -3,10 +3,9 @@ import { OptimisticTokenVotingPluginAbi } from "@/plugins/dualGovernance/artifac import { useEffect, useState } from "react"; import { PUB_CHAIN, PUB_DUAL_GOVERNANCE_PLUGIN_ADDRESS } from "@/constants"; -export function useUserCanVeto(proposalId: bigint, forceRefetch: boolean) { +export function useUserCanVeto(proposalId: bigint) { const { address } = useAccount(); const { data: blockNumber } = useBlockNumber({ watch: true }); - const [userVetoed, setUserVetoed] = useState(false) const { data: canVeto, refetch: canVetoRefetch } = useReadContract({ chainId: PUB_CHAIN.id, @@ -22,12 +21,5 @@ export function useUserCanVeto(proposalId: bigint, forceRefetch: boolean) { } }, [blockNumber]) - useEffect(() => { - if (forceRefetch && !userVetoed) { - canVetoRefetch(); - } - setUserVetoed(true) - }, [forceRefetch]) - - return canVeto; + return { canVeto, canVetoRefetch }; }