From 20b0b9a3caa4f712e3315d2b54652b2a852df825 Mon Sep 17 00:00:00 2001 From: solimander Date: Fri, 3 Nov 2023 08:51:07 -0600 Subject: [PATCH 1/2] Fix future block query issue --- .../src/components/ProposalHeader/index.tsx | 10 +++++++--- packages/nouns-webapp/src/pages/Vote/index.tsx | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/nouns-webapp/src/components/ProposalHeader/index.tsx b/packages/nouns-webapp/src/components/ProposalHeader/index.tsx index 680fc10fe7..7b6b3cd589 100644 --- a/packages/nouns-webapp/src/components/ProposalHeader/index.tsx +++ b/packages/nouns-webapp/src/components/ProposalHeader/index.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useMemo } from 'react'; import { useEffect } from 'react'; import { useBlockNumber } from '@usedapp/core'; import { Alert, Button } from 'react-bootstrap'; @@ -66,13 +66,17 @@ const ProposalHeader: React.FC = props => { const [updatedTimestamp, setUpdatedTimestamp] = React.useState(null); const [createdTimestamp, setCreatedTimestamp] = React.useState(null); const isMobile = isMobileScreen(); - const availableVotes = useUserVotesAsOfBlock(proposal?.createdBlock) ?? 0; + const currentBlock = useBlockNumber(); + const currentOrSnapshotBlock = useMemo(() => + Math.min(proposal?.voteSnapshotBlock, currentBlock ?? 0) || undefined, + [proposal, currentBlock] + ); + const availableVotes = useUserVotesAsOfBlock(currentOrSnapshotBlock) ?? 0; const hasVoted = useHasVotedOnProposal(proposal?.id); const proposalVote = useProposalVote(proposal?.id); const proposalCreationTimestamp = useBlockTimestamp(proposal?.createdBlock); const disableVoteButton = !isWalletConnected || !availableVotes || hasVoted; const activeLocale = useActiveLocale(); - const currentBlock = useBlockNumber(); const hasManyVersions = props.proposalVersions && props.proposalVersions.length > 1; const isDaoGteV3 = useIsDaoGteV3(); useEffect(() => { diff --git a/packages/nouns-webapp/src/pages/Vote/index.tsx b/packages/nouns-webapp/src/pages/Vote/index.tsx index 1cf2d4932c..fc7527d569 100644 --- a/packages/nouns-webapp/src/pages/Vote/index.tsx +++ b/packages/nouns-webapp/src/pages/Vote/index.tsx @@ -26,7 +26,7 @@ import timezone from 'dayjs/plugin/timezone'; import advanced from 'dayjs/plugin/advancedFormat'; import en from 'dayjs/locale/en'; import VoteModal from '../../components/VoteModal'; -import { useCallback, useEffect, useState } from 'react'; +import { useCallback, useEffect, useMemo, useState } from 'react'; import { useAppDispatch, useAppSelector } from '../../hooks'; import clsx from 'clsx'; import ProposalHeader from '../../components/ProposalHeader'; @@ -160,8 +160,12 @@ const VotePage = ({ const againstPercentage = proposal && totalVotes ? (proposal.againstCount * 100) / totalVotes : 0; const abstainPercentage = proposal && totalVotes ? (proposal.abstainCount * 100) / totalVotes : 0; - // Use user votes as of proposal snapshot block pulled from subgraph - const userVotes = useUserVotesAsOfBlock(proposal?.voteSnapshotBlock); + // Use user votes as of the current or proposal snapshot block + const currentOrSnapshotBlock = useMemo(() => + Math.min(proposal?.voteSnapshotBlock ?? 0, currentBlock ?? 0) || undefined, + [proposal, currentBlock] + ); + const userVotes = useUserVotesAsOfBlock(currentOrSnapshotBlock); // Get user votes as of current block to use in vote signals const userVotesNow = useUserVotes() || 0; From 36c350eb9ccc01c8094f0e503110f67a6e1df8dc Mon Sep 17 00:00:00 2001 From: solimander Date: Fri, 3 Nov 2023 09:33:30 -0600 Subject: [PATCH 2/2] Use block - 1 --- packages/nouns-webapp/src/components/ProposalHeader/index.tsx | 2 +- packages/nouns-webapp/src/pages/Vote/index.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/nouns-webapp/src/components/ProposalHeader/index.tsx b/packages/nouns-webapp/src/components/ProposalHeader/index.tsx index 7b6b3cd589..f742102ad3 100644 --- a/packages/nouns-webapp/src/components/ProposalHeader/index.tsx +++ b/packages/nouns-webapp/src/components/ProposalHeader/index.tsx @@ -68,7 +68,7 @@ const ProposalHeader: React.FC = props => { const isMobile = isMobileScreen(); const currentBlock = useBlockNumber(); const currentOrSnapshotBlock = useMemo(() => - Math.min(proposal?.voteSnapshotBlock, currentBlock ?? 0) || undefined, + Math.min(proposal?.voteSnapshotBlock, (currentBlock ? currentBlock - 1 : 0)) || undefined, [proposal, currentBlock] ); const availableVotes = useUserVotesAsOfBlock(currentOrSnapshotBlock) ?? 0; diff --git a/packages/nouns-webapp/src/pages/Vote/index.tsx b/packages/nouns-webapp/src/pages/Vote/index.tsx index fc7527d569..b51f77ffd5 100644 --- a/packages/nouns-webapp/src/pages/Vote/index.tsx +++ b/packages/nouns-webapp/src/pages/Vote/index.tsx @@ -162,7 +162,7 @@ const VotePage = ({ // Use user votes as of the current or proposal snapshot block const currentOrSnapshotBlock = useMemo(() => - Math.min(proposal?.voteSnapshotBlock ?? 0, currentBlock ?? 0) || undefined, + Math.min(proposal?.voteSnapshotBlock ?? 0, (currentBlock ? currentBlock - 1 : 0)) || undefined, [proposal, currentBlock] ); const userVotes = useUserVotesAsOfBlock(currentOrSnapshotBlock);