Skip to content

Commit

Permalink
Merge pull request #811 from nounsDAO/soli-fix-future-query-error
Browse files Browse the repository at this point in the history
Fix Future Block Query Issue
  • Loading branch information
solimander authored Nov 6, 2023
2 parents 31b2a95 + 36c350e commit b7bf7e9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
10 changes: 7 additions & 3 deletions packages/nouns-webapp/src/components/ProposalHeader/index.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -66,13 +66,17 @@ const ProposalHeader: React.FC<ProposalHeaderProps> = props => {
const [updatedTimestamp, setUpdatedTimestamp] = React.useState<number | null>(null);
const [createdTimestamp, setCreatedTimestamp] = React.useState<number | null>(null);
const isMobile = isMobileScreen();
const availableVotes = useUserVotesAsOfBlock(proposal?.createdBlock) ?? 0;
const currentBlock = useBlockNumber();
const currentOrSnapshotBlock = useMemo(() =>
Math.min(proposal?.voteSnapshotBlock, (currentBlock ? currentBlock - 1 : 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(() => {
Expand Down
10 changes: 7 additions & 3 deletions packages/nouns-webapp/src/pages/Vote/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 ? currentBlock - 1 : 0)) || undefined,
[proposal, currentBlock]
);
const userVotes = useUserVotesAsOfBlock(currentOrSnapshotBlock);

// Get user votes as of current block to use in vote signals
const userVotesNow = useUserVotes() || 0;
Expand Down

0 comments on commit b7bf7e9

Please sign in to comment.