Skip to content

Commit

Permalink
chore: much cleaner refetch
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosgj94 committed Mar 8, 2024
1 parent db3fecb commit b82050b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
3 changes: 2 additions & 1 deletion plugins/dualGovernance/hooks/useProposalVeto.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -66,6 +66,7 @@ export function useProposalVeto(proposalId: string) {
type: "success",
txHash: vetoTxHash,
});
canVetoRefetch();
}, [vetoingStatus, vetoTxHash, isConfirming, isConfirmed]);

const vetoProposal = () => {
Expand Down
12 changes: 2 additions & 10 deletions plugins/dualGovernance/hooks/useUserCanVeto.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>(false)

const { data: canVeto, refetch: canVetoRefetch } = useReadContract({
chainId: PUB_CHAIN.id,
Expand All @@ -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 };
}

0 comments on commit b82050b

Please sign in to comment.