Skip to content

Commit b0857e1

Browse files
r4topunkclaude
andcommitted
fix(useVotes): skip getPastVotes when snapshot is still in the future
Viewing a freshly created proposal during its voting-delay window made the governor's proposalSnapshot() return a timestamp greater than clock(), which caused getPastVotes() to revert with ERC5805FutureLookup. Detect that case at mount and fall back to getVotes(), so the UI shows the signer's current voting power as a preview until the snapshot actually elapses. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent b08e53f commit b0857e1

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

src/hooks/useVotes.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useState } from "react";
12
import { Address } from "viem";
23
import { useReadContract, useReadContracts } from "wagmi";
34

@@ -117,7 +118,20 @@ export const useVotes = ({
117118
});
118119

119120
const effectiveSnapshot = snapshotTimestamp ?? snapshotBlock;
120-
const usingSnapshotQuery = Boolean(effectiveSnapshot && !hasSubgraphVoteWeight);
121+
122+
// OZ Votes.getPastVotes reverts when the queried timepoint is not strictly
123+
// in the past (e.g. during the voting-delay window before snapshot elapses).
124+
// In that case skip the snapshot path and fall back to getVotes so the UI
125+
// can preview the signer's current voting power instead of erroring.
126+
// Frozen at mount — if the user sits through the snapshot crossing,
127+
// a refresh will pick up the correct path.
128+
const [mountTime] = useState<bigint>(() => BigInt(Math.floor(Date.now() / 1000)));
129+
const snapshotInFuture = Boolean(
130+
snapshotTimestamp !== undefined && snapshotTimestamp > mountTime,
131+
);
132+
const usingSnapshotQuery = Boolean(
133+
effectiveSnapshot && !hasSubgraphVoteWeight && !snapshotInFuture,
134+
);
121135

122136
const { data, isLoading: contractsLoading, error } = useReadContracts({
123137
query: {

0 commit comments

Comments
 (0)