From fb13fe6957d44310cff5cc81c3891830bce44a7f Mon Sep 17 00:00:00 2001 From: jordan Date: Wed, 11 Oct 2023 19:23:00 -0700 Subject: [PATCH 01/11] write votes query, pass data to HasVoted component --- .../subgraph/queries/proposalVotes.graphql | 7 +++ apps/web/src/data/subgraph/sdk.generated.ts | 42 ++++++++++++++++ .../src/modules/dashboard/DaoProposalCard.tsx | 48 ++++++++++++++++++- .../src/modules/dashboard/DaoProposals.tsx | 5 +- apps/web/src/modules/dashboard/Dashboard.tsx | 10 +++- .../ProposalActions/VoteStatus/VoteStatus.tsx | 1 + 6 files changed, 109 insertions(+), 4 deletions(-) create mode 100644 apps/web/src/data/subgraph/queries/proposalVotes.graphql diff --git a/apps/web/src/data/subgraph/queries/proposalVotes.graphql b/apps/web/src/data/subgraph/queries/proposalVotes.graphql new file mode 100644 index 00000000..39fb4b1e --- /dev/null +++ b/apps/web/src/data/subgraph/queries/proposalVotes.graphql @@ -0,0 +1,7 @@ +query proposalVotes($proposalId: ID!) { + proposal(id: $proposalId) { + votes { + ...ProposalVote + } + } +} diff --git a/apps/web/src/data/subgraph/sdk.generated.ts b/apps/web/src/data/subgraph/sdk.generated.ts index ac83a9fc..b41e91a6 100644 --- a/apps/web/src/data/subgraph/sdk.generated.ts +++ b/apps/web/src/data/subgraph/sdk.generated.ts @@ -2230,6 +2230,24 @@ export type ProposalOgMetadataQuery = { }> } +export type ProposalVotesQueryVariables = Exact<{ + proposalId: Scalars['ID'] +}> + +export type ProposalVotesQuery = { + __typename?: 'Query' + proposal?: { + __typename?: 'Proposal' + votes: Array<{ + __typename?: 'ProposalVote' + voter: any + support: ProposalVoteSupport + weight: number + reason?: string | null + }> + } | null +} + export type ProposalsQueryVariables = Exact<{ where?: InputMaybe first: Scalars['Int'] @@ -2646,6 +2664,16 @@ export const ProposalOgMetadataDocument = gql` ${ProposalFragmentDoc} ${ProposalVoteFragmentDoc} ` +export const ProposalVotesDocument = gql` + query proposalVotes($proposalId: ID!) { + proposal(id: $proposalId) { + votes { + ...ProposalVote + } + } + } + ${ProposalVoteFragmentDoc} +` export const ProposalsDocument = gql` query proposals($where: Proposal_filter, $first: Int!, $skip: Int) { proposals( @@ -2906,6 +2934,20 @@ export function getSdk( 'query' ) }, + proposalVotes( + variables: ProposalVotesQueryVariables, + requestHeaders?: Dom.RequestInit['headers'] + ): Promise { + return withWrapper( + (wrappedRequestHeaders) => + client.request(ProposalVotesDocument, variables, { + ...requestHeaders, + ...wrappedRequestHeaders, + }), + 'proposalVotes', + 'query' + ) + }, proposals( variables: ProposalsQueryVariables, requestHeaders?: Dom.RequestInit['headers'] diff --git a/apps/web/src/modules/dashboard/DaoProposalCard.tsx b/apps/web/src/modules/dashboard/DaoProposalCard.tsx index a73abe0b..5be89701 100644 --- a/apps/web/src/modules/dashboard/DaoProposalCard.tsx +++ b/apps/web/src/modules/dashboard/DaoProposalCard.tsx @@ -1,6 +1,8 @@ import { Flex, Text } from '@zoralabs/zord' import Link from 'next/link' +import { useContractReads } from 'wagmi' +import { governorAbi } from 'src/data/contract/abis' import { ProposalState } from 'src/data/contract/requests/getProposalState' import { ProposalFragment } from 'src/data/subgraph/sdk.generated' import { AddressType, CHAIN_ID } from 'src/typings' @@ -12,18 +14,23 @@ type DaoProposalCardProps = ProposalFragment & { tokenAddress: AddressType proposalState: ProposalState currentChainSlug?: string + userAddress?: AddressType } export const DaoProposalCard = ({ title, proposalNumber, tokenAddress, - chainId, proposalState, voteEnd, voteStart, expiresAt, currentChainSlug, + userAddress, + chainId, + timeCreated, + dao, + ...rest }: DaoProposalCardProps) => { return ( + {userAddress && ( + + )} ) } + +type NeedsVoteProps = { + userAddress: AddressType + chainId: CHAIN_ID + timeCreated: string + governorAddress: AddressType +} +const NeedsVote = ({ + userAddress, + chainId, + timeCreated, + governorAddress, +}: NeedsVoteProps) => { + const { data } = useContractReads({ + enabled: !!userAddress, + allowFailure: false, + contracts: [ + { + abi: governorAbi, + address: governorAddress, + chainId, + functionName: 'getVotes', + args: [userAddress as AddressType, BigInt(timeCreated)], + }, + ], + }) + + console.log('data', data) + + return null +} diff --git a/apps/web/src/modules/dashboard/DaoProposals.tsx b/apps/web/src/modules/dashboard/DaoProposals.tsx index b65fe993..98107b72 100644 --- a/apps/web/src/modules/dashboard/DaoProposals.tsx +++ b/apps/web/src/modules/dashboard/DaoProposals.tsx @@ -7,6 +7,7 @@ import React from 'react' import { Avatar } from 'src/components/Avatar' import { PUBLIC_ALL_CHAINS } from 'src/constants/defaultChains' +import { AddressType } from 'src/typings' import { DaoProposalCard } from './DaoProposalCard' import { DashboardDaoProps } from './Dashboard' @@ -18,7 +19,8 @@ export const DaoProposals = ({ name, proposals, chainId, -}: DashboardDaoProps) => { + userAddress, +}: DashboardDaoProps & { userAddress?: AddressType }) => { const daoImageSrc = React.useMemo(() => { return daoImage ? getFetchableUrl(daoImage) : null }, [daoImage]) @@ -75,6 +77,7 @@ export const DaoProposals = ({ currentChainSlug={currentChainSlug} tokenAddress={tokenAddress} proposalState={proposal.proposalState} + userAddress={userAddress} /> ))} diff --git a/apps/web/src/modules/dashboard/Dashboard.tsx b/apps/web/src/modules/dashboard/Dashboard.tsx index 7c7f583b..a973ebc8 100644 --- a/apps/web/src/modules/dashboard/Dashboard.tsx +++ b/apps/web/src/modules/dashboard/Dashboard.tsx @@ -15,7 +15,7 @@ import { DaoFragment, ProposalFragment, } from 'src/data/subgraph/sdk.generated' -import { CHAIN_ID } from 'src/typings' +import { AddressType, CHAIN_ID } from 'src/typings' import { DaoFeed } from '../dao' import { DaoAuctionCard } from './DaoAuctionCard' @@ -111,7 +111,13 @@ const Dashboard = () => { return data .filter((dao) => dao.proposals.length) - .map((dao) => ) + .map((dao) => ( + + )) }, [data]) if (error) { diff --git a/apps/web/src/modules/proposal/components/ProposalActions/VoteStatus/VoteStatus.tsx b/apps/web/src/modules/proposal/components/ProposalActions/VoteStatus/VoteStatus.tsx index 9b3e7a7d..5f26fda5 100644 --- a/apps/web/src/modules/proposal/components/ProposalActions/VoteStatus/VoteStatus.tsx +++ b/apps/web/src/modules/proposal/components/ProposalActions/VoteStatus/VoteStatus.tsx @@ -71,6 +71,7 @@ export const VoteStatus: React.FC = ({ abi: governorAbi, eventName: 'VoteCast', listener: async (logs) => { + console.log('LISTENER FIRED') const { voter, proposalId: id, support, weight, reason } = logs[0].args if (id === proposalId && voter && getAddress(voter) === getAddress(userAddress!)) { const eventVote: ProposalVote = { From d646ba18799115bb17b7bb8b008dbc9b9711a72c Mon Sep 17 00:00:00 2001 From: jordan Date: Wed, 11 Oct 2023 20:09:57 -0700 Subject: [PATCH 02/11] hasVoted query, display only on Active --- .../data/subgraph/requests/proposalVotes.ts | 27 ++++++++++++ .../src/modules/dashboard/DaoProposalCard.tsx | 44 +++++++++---------- apps/web/src/modules/dashboard/Dashboard.tsx | 2 +- 3 files changed, 49 insertions(+), 24 deletions(-) create mode 100644 apps/web/src/data/subgraph/requests/proposalVotes.ts diff --git a/apps/web/src/data/subgraph/requests/proposalVotes.ts b/apps/web/src/data/subgraph/requests/proposalVotes.ts new file mode 100644 index 00000000..eca76f67 --- /dev/null +++ b/apps/web/src/data/subgraph/requests/proposalVotes.ts @@ -0,0 +1,27 @@ +import { AddressType, CHAIN_ID } from 'src/typings' + +import { SDK } from '../client' + +export const getProposalVotes = async (proposalId: string, chainId: CHAIN_ID) => { + try { + const res = await SDK.connect(chainId).proposalVotes({ proposalId }) + + return res?.proposal?.votes + } catch (error: any) { + throw new Error((error?.message as string) || 'Error fetching proposal votes') + } +} + +export const hasUserVoted = async ( + proposalId: string, + userAddress: AddressType, + chainId: CHAIN_ID +) => { + try { + const votes = await getProposalVotes(proposalId, chainId) + + return votes?.some?.((vote) => vote.voter === userAddress.toLowerCase()) + } catch (error: any) { + throw new Error((error?.message as string) || 'Error fetching proposal votes') + } +} diff --git a/apps/web/src/modules/dashboard/DaoProposalCard.tsx b/apps/web/src/modules/dashboard/DaoProposalCard.tsx index 5be89701..cae7c89c 100644 --- a/apps/web/src/modules/dashboard/DaoProposalCard.tsx +++ b/apps/web/src/modules/dashboard/DaoProposalCard.tsx @@ -1,9 +1,9 @@ import { Flex, Text } from '@zoralabs/zord' import Link from 'next/link' -import { useContractReads } from 'wagmi' +import useSWR from 'swr' -import { governorAbi } from 'src/data/contract/abis' import { ProposalState } from 'src/data/contract/requests/getProposalState' +import { hasUserVoted } from 'src/data/subgraph/requests/proposalVotes' import { ProposalFragment } from 'src/data/subgraph/sdk.generated' import { AddressType, CHAIN_ID } from 'src/typings' @@ -29,6 +29,7 @@ export const DaoProposalCard = ({ userAddress, chainId, timeCreated, + proposalId, dao, ...rest }: DaoProposalCardProps) => { @@ -91,8 +92,8 @@ export const DaoProposalCard = ({ )} @@ -104,30 +105,27 @@ export const DaoProposalCard = ({ type NeedsVoteProps = { userAddress: AddressType chainId: CHAIN_ID - timeCreated: string - governorAddress: AddressType + proposalId: string + proposalState: ProposalState } const NeedsVote = ({ userAddress, chainId, - timeCreated, - governorAddress, + proposalState, + proposalId, }: NeedsVoteProps) => { - const { data } = useContractReads({ - enabled: !!userAddress, - allowFailure: false, - contracts: [ - { - abi: governorAbi, - address: governorAddress, - chainId, - functionName: 'getVotes', - args: [userAddress as AddressType, BigInt(timeCreated)], - }, - ], - }) + const { data: hasVoted } = useSWR( + [proposalId, userAddress, chainId], + + async () => { + if (proposalState !== ProposalState.Active) return null + const hasVoted = await hasUserVoted(proposalId, userAddress, chainId) + return hasVoted + }, + { revalidateOnFocus: false } + ) - console.log('data', data) + if (hasVoted === true || hasVoted === null) return null - return null + return 'no vote' } diff --git a/apps/web/src/modules/dashboard/Dashboard.tsx b/apps/web/src/modules/dashboard/Dashboard.tsx index a973ebc8..a617808b 100644 --- a/apps/web/src/modules/dashboard/Dashboard.tsx +++ b/apps/web/src/modules/dashboard/Dashboard.tsx @@ -118,7 +118,7 @@ const Dashboard = () => { userAddress={address as AddressType} /> )) - }, [data]) + }, [data, address]) if (error) { return ( From d5658b87c6fd6baf1115fc0b8d4e30ebba90ddab Mon Sep 17 00:00:00 2001 From: jordan Date: Wed, 11 Oct 2023 20:55:38 -0700 Subject: [PATCH 03/11] tooltip and icon displays needsvote --- .../src/modules/dashboard/DaoProposalCard.tsx | 63 ++++++++++++------- 1 file changed, 40 insertions(+), 23 deletions(-) diff --git a/apps/web/src/modules/dashboard/DaoProposalCard.tsx b/apps/web/src/modules/dashboard/DaoProposalCard.tsx index cae7c89c..c0cb7936 100644 --- a/apps/web/src/modules/dashboard/DaoProposalCard.tsx +++ b/apps/web/src/modules/dashboard/DaoProposalCard.tsx @@ -1,7 +1,9 @@ -import { Flex, Text } from '@zoralabs/zord' +import { Box, Flex, PopUp, Text } from '@zoralabs/zord' import Link from 'next/link' +import { useState } from 'react' import useSWR from 'swr' +import { Icon } from 'src/components/Icon' import { ProposalState } from 'src/data/contract/requests/getProposalState' import { hasUserVoted } from 'src/data/subgraph/requests/proposalVotes' import { ProposalFragment } from 'src/data/subgraph/sdk.generated' @@ -50,6 +52,7 @@ export const DaoProposalCard = ({ cursor={'pointer'} py={{ '@initial': 'x3', '@768': 'x6' }} px={{ '@initial': 'x6', '@768': 'x3' }} + position={'relative'} > {proposalNumber} - - - {title} - + + + {title} + + + - {userAddress && ( - - )} @@ -103,7 +105,7 @@ export const DaoProposalCard = ({ } type NeedsVoteProps = { - userAddress: AddressType + userAddress?: AddressType chainId: CHAIN_ID proposalId: string proposalState: ProposalState @@ -114,18 +116,33 @@ const NeedsVote = ({ proposalState, proposalId, }: NeedsVoteProps) => { + const [showTooltip, setShowTooltip] = useState(false) const { data: hasVoted } = useSWR( [proposalId, userAddress, chainId], - async () => { if (proposalState !== ProposalState.Active) return null - const hasVoted = await hasUserVoted(proposalId, userAddress, chainId) + const hasVoted = await hasUserVoted(proposalId, userAddress as AddressType, chainId) return hasVoted }, { revalidateOnFocus: false } ) - if (hasVoted === true || hasVoted === null) return null + if (hasVoted === true || hasVoted == null) return null - return 'no vote' + return ( + + setShowTooltip(true)} + onMouseLeave={() => setShowTooltip(false)} + > + + + + } placement="right"> + Vote Needed + + + ) } From 2d17a6ca5337ea20d856ab601eb48ff3cf761b62 Mon Sep 17 00:00:00 2001 From: jordan Date: Wed, 11 Oct 2023 21:32:20 -0700 Subject: [PATCH 04/11] display check for voted proposals --- .../web/src/modules/dashboard/DaoProposalCard.tsx | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/apps/web/src/modules/dashboard/DaoProposalCard.tsx b/apps/web/src/modules/dashboard/DaoProposalCard.tsx index c0cb7936..a09985e9 100644 --- a/apps/web/src/modules/dashboard/DaoProposalCard.tsx +++ b/apps/web/src/modules/dashboard/DaoProposalCard.tsx @@ -33,7 +33,6 @@ export const DaoProposalCard = ({ timeCreated, proposalId, dao, - ...rest }: DaoProposalCardProps) => { return ( { if (proposalState !== ProposalState.Active) return null const hasVoted = await hasUserVoted(proposalId, userAddress as AddressType, chainId) + return hasVoted }, { revalidateOnFocus: false } ) - if (hasVoted === true || hasVoted == null) return null + if (hasVoted == null) return null return ( @@ -137,11 +137,18 @@ const NeedsVote = ({ onMouseOver={() => setShowTooltip(true)} onMouseLeave={() => setShowTooltip(false)} > - + } placement="right"> - Vote Needed + {hasVoted ? 'Vote Submitted' : 'Vote Needed'} ) From ff9bebe101333a343eb665eb15ce4cdfe5094206 Mon Sep 17 00:00:00 2001 From: jordan Date: Wed, 11 Oct 2023 21:33:45 -0700 Subject: [PATCH 05/11] clean --- .../components/ProposalActions/VoteStatus/VoteStatus.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/web/src/modules/proposal/components/ProposalActions/VoteStatus/VoteStatus.tsx b/apps/web/src/modules/proposal/components/ProposalActions/VoteStatus/VoteStatus.tsx index 5f26fda5..9b3e7a7d 100644 --- a/apps/web/src/modules/proposal/components/ProposalActions/VoteStatus/VoteStatus.tsx +++ b/apps/web/src/modules/proposal/components/ProposalActions/VoteStatus/VoteStatus.tsx @@ -71,7 +71,6 @@ export const VoteStatus: React.FC = ({ abi: governorAbi, eventName: 'VoteCast', listener: async (logs) => { - console.log('LISTENER FIRED') const { voter, proposalId: id, support, weight, reason } = logs[0].args if (id === proposalId && voter && getAddress(voter) === getAddress(userAddress!)) { const eventVote: ProposalVote = { From 5b7304e147e171b98451709cbbe15964a181c611 Mon Sep 17 00:00:00 2001 From: jordan Date: Sat, 14 Oct 2023 11:57:29 -0700 Subject: [PATCH 06/11] fix icon alignment issue on mobile --- apps/web/src/modules/dashboard/DaoProposalCard.tsx | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/apps/web/src/modules/dashboard/DaoProposalCard.tsx b/apps/web/src/modules/dashboard/DaoProposalCard.tsx index a09985e9..be5494d3 100644 --- a/apps/web/src/modules/dashboard/DaoProposalCard.tsx +++ b/apps/web/src/modules/dashboard/DaoProposalCard.tsx @@ -30,9 +30,7 @@ export const DaoProposalCard = ({ currentChainSlug, userAddress, chainId, - timeCreated, proposalId, - dao, }: DaoProposalCardProps) => { return ( {proposalNumber} - - + + {title} Date: Mon, 16 Oct 2023 21:15:17 -0700 Subject: [PATCH 07/11] include votes at high-level fetch --- .../subgraph/queries/dashboardQuery.graphql | 3 +++ apps/web/src/data/subgraph/sdk.generated.ts | 4 +++ .../src/modules/dashboard/DaoProposalCard.tsx | 25 ++++++++++--------- apps/web/src/modules/dashboard/Dashboard.tsx | 9 +++++-- 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/apps/web/src/data/subgraph/queries/dashboardQuery.graphql b/apps/web/src/data/subgraph/queries/dashboardQuery.graphql index 86f124a8..a15330a7 100644 --- a/apps/web/src/data/subgraph/queries/dashboardQuery.graphql +++ b/apps/web/src/data/subgraph/queries/dashboardQuery.graphql @@ -18,6 +18,9 @@ query dashboard($where: DAOTokenOwner_filter, $first: Int, $skip: Int) { voteEnd voteStart expiresAt + votes { + voter + } } currentAuction { ...CurrentAuction diff --git a/apps/web/src/data/subgraph/sdk.generated.ts b/apps/web/src/data/subgraph/sdk.generated.ts index b41e91a6..b11ebce0 100644 --- a/apps/web/src/data/subgraph/sdk.generated.ts +++ b/apps/web/src/data/subgraph/sdk.generated.ts @@ -2092,6 +2092,7 @@ export type DashboardQuery = { values: Array snapshotBlockNumber: any transactionHash: any + votes: Array<{ __typename?: 'ProposalVote'; voter: any }> dao: { __typename?: 'DAO'; governorAddress: any; tokenAddress: any } }> currentAuction?: { @@ -2586,6 +2587,9 @@ export const DashboardDocument = gql` voteEnd voteStart expiresAt + votes { + voter + } } currentAuction { ...CurrentAuction diff --git a/apps/web/src/modules/dashboard/DaoProposalCard.tsx b/apps/web/src/modules/dashboard/DaoProposalCard.tsx index be5494d3..ed861c71 100644 --- a/apps/web/src/modules/dashboard/DaoProposalCard.tsx +++ b/apps/web/src/modules/dashboard/DaoProposalCard.tsx @@ -1,11 +1,9 @@ import { Box, Flex, PopUp, Text } from '@zoralabs/zord' import Link from 'next/link' -import { useState } from 'react' -import useSWR from 'swr' +import { useMemo, useState } from 'react' import { Icon } from 'src/components/Icon' import { ProposalState } from 'src/data/contract/requests/getProposalState' -import { hasUserVoted } from 'src/data/subgraph/requests/proposalVotes' import { ProposalFragment } from 'src/data/subgraph/sdk.generated' import { AddressType, CHAIN_ID } from 'src/typings' @@ -17,6 +15,9 @@ type DaoProposalCardProps = ProposalFragment & { proposalState: ProposalState currentChainSlug?: string userAddress?: AddressType + votes: { + voter: string + }[] } export const DaoProposalCard = ({ @@ -31,6 +32,7 @@ export const DaoProposalCard = ({ userAddress, chainId, proposalId, + votes, }: DaoProposalCardProps) => { return ( { const [showTooltip, setShowTooltip] = useState(false) - const { data: hasVoted } = useSWR( - [proposalId, userAddress, chainId], - async () => { - if (proposalState !== ProposalState.Active) return null - const hasVoted = await hasUserVoted(proposalId, userAddress as AddressType, chainId) - return hasVoted - }, - { revalidateOnFocus: false } - ) + const hasVoted = useMemo(() => { + if (proposalState !== ProposalState.Active) return undefined + + return votes.some((vote) => vote.voter === userAddress?.toLowerCase()) + }, [proposalState, votes]) if (hasVoted == null) return null diff --git a/apps/web/src/modules/dashboard/Dashboard.tsx b/apps/web/src/modules/dashboard/Dashboard.tsx index a617808b..0edeed8a 100644 --- a/apps/web/src/modules/dashboard/Dashboard.tsx +++ b/apps/web/src/modules/dashboard/Dashboard.tsx @@ -37,7 +37,12 @@ export type DashboardDaoProps = DaoFragment & { minimumBidIncrement: string reservePrice: string } - proposals: (ProposalFragment & { proposalState: ProposalState })[] + proposals: (ProposalFragment & { + proposalState: ProposalState + votes: { + voter: string + }[] + })[] currentAuction?: CurrentAuctionFragment | null } @@ -79,7 +84,7 @@ const Dashboard = () => { address ? () => fetchDashboardData(address) : null, { revalidateOnFocus: false } ) - + console.log('data', data) const [mutating, setMutating] = useState(false) const proposalList = useMemo(() => { From f88aea7885783dcbb21228ee4513d19aea488e79 Mon Sep 17 00:00:00 2001 From: jordan Date: Mon, 16 Oct 2023 21:19:42 -0700 Subject: [PATCH 08/11] clean --- .../subgraph/queries/proposalVotes.graphql | 7 ----- .../data/subgraph/requests/proposalVotes.ts | 27 ------------------- .../src/modules/dashboard/DaoProposalCard.tsx | 8 +----- 3 files changed, 1 insertion(+), 41 deletions(-) delete mode 100644 apps/web/src/data/subgraph/queries/proposalVotes.graphql delete mode 100644 apps/web/src/data/subgraph/requests/proposalVotes.ts diff --git a/apps/web/src/data/subgraph/queries/proposalVotes.graphql b/apps/web/src/data/subgraph/queries/proposalVotes.graphql deleted file mode 100644 index 39fb4b1e..00000000 --- a/apps/web/src/data/subgraph/queries/proposalVotes.graphql +++ /dev/null @@ -1,7 +0,0 @@ -query proposalVotes($proposalId: ID!) { - proposal(id: $proposalId) { - votes { - ...ProposalVote - } - } -} diff --git a/apps/web/src/data/subgraph/requests/proposalVotes.ts b/apps/web/src/data/subgraph/requests/proposalVotes.ts deleted file mode 100644 index eca76f67..00000000 --- a/apps/web/src/data/subgraph/requests/proposalVotes.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { AddressType, CHAIN_ID } from 'src/typings' - -import { SDK } from '../client' - -export const getProposalVotes = async (proposalId: string, chainId: CHAIN_ID) => { - try { - const res = await SDK.connect(chainId).proposalVotes({ proposalId }) - - return res?.proposal?.votes - } catch (error: any) { - throw new Error((error?.message as string) || 'Error fetching proposal votes') - } -} - -export const hasUserVoted = async ( - proposalId: string, - userAddress: AddressType, - chainId: CHAIN_ID -) => { - try { - const votes = await getProposalVotes(proposalId, chainId) - - return votes?.some?.((vote) => vote.voter === userAddress.toLowerCase()) - } catch (error: any) { - throw new Error((error?.message as string) || 'Error fetching proposal votes') - } -} diff --git a/apps/web/src/modules/dashboard/DaoProposalCard.tsx b/apps/web/src/modules/dashboard/DaoProposalCard.tsx index ed861c71..1e498d59 100644 --- a/apps/web/src/modules/dashboard/DaoProposalCard.tsx +++ b/apps/web/src/modules/dashboard/DaoProposalCard.tsx @@ -106,13 +106,7 @@ type NeedsVoteProps = { proposalState: ProposalState votes: { voter: string }[] } -const NeedsVote = ({ - userAddress, - chainId, - proposalState, - proposalId, - votes, -}: NeedsVoteProps) => { +const NeedsVote = ({ userAddress, proposalState, votes }: NeedsVoteProps) => { const [showTooltip, setShowTooltip] = useState(false) const hasVoted = useMemo(() => { From 2a1553983568ad4d9814f9963ad5744b08379659 Mon Sep 17 00:00:00 2001 From: jordan Date: Mon, 16 Oct 2023 21:20:42 -0700 Subject: [PATCH 09/11] update useMemo dep --- apps/web/src/modules/dashboard/DaoProposalCard.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/web/src/modules/dashboard/DaoProposalCard.tsx b/apps/web/src/modules/dashboard/DaoProposalCard.tsx index 1e498d59..f74308ee 100644 --- a/apps/web/src/modules/dashboard/DaoProposalCard.tsx +++ b/apps/web/src/modules/dashboard/DaoProposalCard.tsx @@ -113,7 +113,7 @@ const NeedsVote = ({ userAddress, proposalState, votes }: NeedsVoteProps) => { if (proposalState !== ProposalState.Active) return undefined return votes.some((vote) => vote.voter === userAddress?.toLowerCase()) - }, [proposalState, votes]) + }, [proposalState, votes, userAddress]) if (hasVoted == null) return null From 1ff43d32b5af4b61d07e4c9b9601c11530426652 Mon Sep 17 00:00:00 2001 From: jordan Date: Mon, 16 Oct 2023 21:23:59 -0700 Subject: [PATCH 10/11] remove extra log --- apps/web/src/modules/dashboard/Dashboard.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/web/src/modules/dashboard/Dashboard.tsx b/apps/web/src/modules/dashboard/Dashboard.tsx index 0edeed8a..af22b0f7 100644 --- a/apps/web/src/modules/dashboard/Dashboard.tsx +++ b/apps/web/src/modules/dashboard/Dashboard.tsx @@ -84,7 +84,7 @@ const Dashboard = () => { address ? () => fetchDashboardData(address) : null, { revalidateOnFocus: false } ) - console.log('data', data) + const [mutating, setMutating] = useState(false) const proposalList = useMemo(() => { From 15bace34dc4d7e405b63bc37c626f44e2176f50b Mon Sep 17 00:00:00 2001 From: jordan Date: Mon, 16 Oct 2023 21:45:13 -0700 Subject: [PATCH 11/11] remove unused props --- apps/web/src/modules/dashboard/DaoProposalCard.tsx | 4 ---- 1 file changed, 4 deletions(-) diff --git a/apps/web/src/modules/dashboard/DaoProposalCard.tsx b/apps/web/src/modules/dashboard/DaoProposalCard.tsx index f74308ee..56a1d3ea 100644 --- a/apps/web/src/modules/dashboard/DaoProposalCard.tsx +++ b/apps/web/src/modules/dashboard/DaoProposalCard.tsx @@ -68,8 +68,6 @@ export const DaoProposalCard = ({ @@ -101,8 +99,6 @@ export const DaoProposalCard = ({ type NeedsVoteProps = { userAddress?: AddressType - chainId: CHAIN_ID - proposalId: string proposalState: ProposalState votes: { voter: string }[] }