Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface ProposalHeaderProps {
daoId: string;
setIsVotingModalOpen: (isOpen: boolean) => void;
votingPower: string;
votes: GetAccountPowerQuery["votes"] | null;
votes: GetAccountPowerQuery["votesByProposalId"] | null;
address: string | undefined;
proposalStatus: string;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const VotesTabContent = ({
>
Voted
<div className="text-secondary font-inter hidden text-[12px] font-medium not-italic leading-[16px] lg:block">
{data?.votes?.totalCount} voters / {totalVotes} VP
{data?.votesByProposalId?.totalCount} voters / {totalVotes} VP
</div>
</div>
<div
Expand Down
6 changes: 3 additions & 3 deletions apps/dashboard/features/governance/hooks/useAccountPower.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { formatUnits } from "viem";
export interface UseAccountPowerResult {
accountPower: GetAccountPowerQuery["votingPowerByAccountId"] | null;
votingPower: string;
votes: GetAccountPowerQuery["votes"] | null;
votes: GetAccountPowerQuery["votesByProposalId"] | null;
hasVoted: boolean;
loading: boolean;
error: ApolloError | undefined;
Expand Down Expand Up @@ -64,8 +64,8 @@ export const useVoterInfo = ({
formatUnits(BigInt(data.votingPowerByAccountId.votingPower), decimals),
),
),
votes: data.votes || null,
hasVoted: !!data.votes,
votes: data.votesByProposalId || null,
hasVoted: !!data.votesByProposalId,
loading,
error,
refetch,
Expand Down
41 changes: 25 additions & 16 deletions apps/dashboard/features/governance/hooks/useVotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
useGetVotingPowerChangeLazyQuery,
} from "@anticapture/graphql-client/hooks";
import {
QueryInput_Votes_OrderBy,
QueryInput_Votes_OrderDirection,
QueryInput_VotesByProposalId_OrderBy,
QueryInput_VotesByProposalId_OrderDirection,
} from "@anticapture/graphql-client";

import { DAYS_IN_SECONDS } from "@/shared/constants/time-related";
Expand All @@ -22,7 +22,7 @@ type VotingPowerVariation = {

// Enhanced vote type with historical voting power
export type VoteWithHistoricalPower = NonNullable<
NonNullable<GetVotesQuery["votes"]>["items"][number]
NonNullable<GetVotesQuery["votesByProposalId"]>["items"][number]
> & {
votingPowerVariation?: VotingPowerVariation;
isSubRow?: boolean;
Expand Down Expand Up @@ -66,8 +66,9 @@ export const useVotes = ({
proposalId: proposalId!,
limit,
skip: 0, // Always fetch from beginning, we'll handle append in fetchMore
orderBy: orderBy as QueryInput_Votes_OrderBy,
orderDirection: orderDirection as QueryInput_Votes_OrderDirection,
orderBy: orderBy as QueryInput_VotesByProposalId_OrderBy,
orderDirection:
orderDirection as QueryInput_VotesByProposalId_OrderDirection,
};
}, [proposalId, limit, orderBy, orderDirection]);

Expand Down Expand Up @@ -160,21 +161,26 @@ export const useVotes = ({

// Initialize allVotes on first load or when data changes after reset
useEffect(() => {
if (data?.votes?.items && allVotes.length === 0) {
const initialVotes = data.votes.items as VoteWithHistoricalPower[];
if (data?.votesByProposalId?.items && allVotes.length === 0) {
const initialVotes = data.votesByProposalId
.items as VoteWithHistoricalPower[];
setAllVotes(initialVotes);
// Fetch voting power for initial votes
fetchVotingPowerForVotes(initialVotes);
}
}, [data?.votes?.items, allVotes.length, fetchVotingPowerForVotes]);
}, [
data?.votesByProposalId?.items,
allVotes.length,
fetchVotingPowerForVotes,
]);

// Use accumulated votes for infinite scroll
const votes = allVotes;

// Extract total count
const totalCount = useMemo(() => {
return data?.votes?.totalCount || 0;
}, [data?.votes?.totalCount]);
return data?.votesByProposalId?.totalCount || 0;
}, [data?.votesByProposalId?.totalCount]);

// Calculate if there are more pages
const hasNextPage = useMemo(() => {
Expand All @@ -195,10 +201,10 @@ export const useVotes = ({
skip: allVotes.length, // Skip already loaded votes
},
updateQuery: (previousResult, { fetchMoreResult }) => {
if (!fetchMoreResult?.votes?.items) return previousResult;
if (!fetchMoreResult?.votesByProposalId?.items) return previousResult;

// Append new votes to existing ones in the GraphQL cache
const newVotes = fetchMoreResult.votes
const newVotes = fetchMoreResult.votesByProposalId
.items as VoteWithHistoricalPower[];
setAllVotes((prev) => [...prev, ...newVotes]);

Expand All @@ -207,10 +213,13 @@ export const useVotes = ({

// Return the merged result for the cache
return {
votes: {
...fetchMoreResult.votes,
items: [...(previousResult.votes?.items || []), ...newVotes],
totalCount: fetchMoreResult.votes.totalCount || 0,
votesByProposalId: {
...fetchMoreResult.votesByProposalId,
items: [
...(previousResult.votesByProposalId?.items || []),
...newVotes,
],
totalCount: fetchMoreResult.votesByProposalId.totalCount || 0,
},
};
},
Expand Down
4 changes: 2 additions & 2 deletions apps/dashboard/shared/constants/pages-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ export const PAGES_CONSTANTS = {
},
governanceImplementation: {
title: "",
titleAbbreviation: "Gov Implementation",
page: "governance-implementation",
titleAbbreviation: "Governance",
page: "governance",
description: undefined,
subTitle: "Governance Implementation",
subDescription:
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react-jsx",
"jsx": "preserve",
"incremental": true,
"plugins": [
{
Expand Down
10 changes: 5 additions & 5 deletions apps/dashboard/widgets/HeaderNavMobile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ export const HeaderNavMobile = () => {
title: PAGES_CONSTANTS.riskAnalysis.title,
enabled: !!daoConfig.riskAnalysis,
},
// {
// page: PAGES_CONSTANTS.governanceImplementation.page,
// title: PAGES_CONSTANTS.governanceImplementation.titleAbbreviation,
// enabled: !!daoConfig.governanceImplementation,
// },
{
page: PAGES_CONSTANTS.resilienceStages.page,
title: PAGES_CONSTANTS.resilienceStages.title,
Expand All @@ -50,6 +45,11 @@ export const HeaderNavMobile = () => {
title: PAGES_CONSTANTS.holdersAndDelegates.title,
enabled: true,
},
{
page: PAGES_CONSTANTS.governanceImplementation.page,
title: PAGES_CONSTANTS.governanceImplementation.titleAbbreviation,
enabled: !!daoConfig.governanceImplementation,
},
];

return (
Expand Down
23 changes: 20 additions & 3 deletions packages/graphql-client/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@ export type Scalars = {
Int: { input: number; output: number; }
Float: { input: number; output: number; }
BigInt: { input: any; output: any; }
/** The `JSON` scalar type represents JSON values as specified by [ECMA-404](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf). */
JSON: { input: any; output: any; }
/** Integers that will have a value of 0 or more. */
NonNegativeInt: { input: any; output: any; }
ObjMap: { input: any; output: any; }
/** Integers that will have a value greater than 0. */
PositiveInt: { input: any; output: any; }
};

Expand Down Expand Up @@ -498,6 +495,7 @@ export type QueryVotesOnchainsArgs = {
after?: InputMaybe<Scalars['String']['input']>;
before?: InputMaybe<Scalars['String']['input']>;
limit?: InputMaybe<Scalars['Int']['input']>;
offset?: InputMaybe<Scalars['Int']['input']>;
orderBy?: InputMaybe<Scalars['String']['input']>;
orderDirection?: InputMaybe<Scalars['String']['input']>;
where?: InputMaybe<VotesOnchainFilter>;
Expand All @@ -513,6 +511,7 @@ export type QueryVotingPowerHistorysArgs = {
after?: InputMaybe<Scalars['String']['input']>;
before?: InputMaybe<Scalars['String']['input']>;
limit?: InputMaybe<Scalars['Int']['input']>;
offset?: InputMaybe<Scalars['Int']['input']>;
orderBy?: InputMaybe<Scalars['String']['input']>;
orderDirection?: InputMaybe<Scalars['String']['input']>;
where?: InputMaybe<VotingPowerHistoryFilter>;
Expand Down Expand Up @@ -546,6 +545,12 @@ export type QueryVotingPowersArgs = {
toValue?: InputMaybe<Scalars['String']['input']>;
};

export type ViewPageInfo = {
__typename?: 'ViewPageInfo';
hasNextPage: Scalars['Boolean']['output'];
hasPreviousPage: Scalars['Boolean']['output'];
};

export type Account = {
__typename?: 'account';
balances?: Maybe<AccountBalancePage>;
Expand All @@ -565,6 +570,7 @@ export type AccountBalancesArgs = {
after?: InputMaybe<Scalars['String']['input']>;
before?: InputMaybe<Scalars['String']['input']>;
limit?: InputMaybe<Scalars['Int']['input']>;
offset?: InputMaybe<Scalars['Int']['input']>;
orderBy?: InputMaybe<Scalars['String']['input']>;
orderDirection?: InputMaybe<Scalars['String']['input']>;
where?: InputMaybe<AccountBalanceFilter>;
Expand All @@ -575,6 +581,7 @@ export type AccountDelegatedFromBalancesArgs = {
after?: InputMaybe<Scalars['String']['input']>;
before?: InputMaybe<Scalars['String']['input']>;
limit?: InputMaybe<Scalars['Int']['input']>;
offset?: InputMaybe<Scalars['Int']['input']>;
orderBy?: InputMaybe<Scalars['String']['input']>;
orderDirection?: InputMaybe<Scalars['String']['input']>;
where?: InputMaybe<AccountBalanceFilter>;
Expand All @@ -585,6 +592,7 @@ export type AccountDelegationsFromArgs = {
after?: InputMaybe<Scalars['String']['input']>;
before?: InputMaybe<Scalars['String']['input']>;
limit?: InputMaybe<Scalars['Int']['input']>;
offset?: InputMaybe<Scalars['Int']['input']>;
orderBy?: InputMaybe<Scalars['String']['input']>;
orderDirection?: InputMaybe<Scalars['String']['input']>;
where?: InputMaybe<DelegationFilter>;
Expand All @@ -595,6 +603,7 @@ export type AccountDelegationsToArgs = {
after?: InputMaybe<Scalars['String']['input']>;
before?: InputMaybe<Scalars['String']['input']>;
limit?: InputMaybe<Scalars['Int']['input']>;
offset?: InputMaybe<Scalars['Int']['input']>;
orderBy?: InputMaybe<Scalars['String']['input']>;
orderDirection?: InputMaybe<Scalars['String']['input']>;
where?: InputMaybe<DelegationFilter>;
Expand All @@ -605,6 +614,7 @@ export type AccountPowersArgs = {
after?: InputMaybe<Scalars['String']['input']>;
before?: InputMaybe<Scalars['String']['input']>;
limit?: InputMaybe<Scalars['Int']['input']>;
offset?: InputMaybe<Scalars['Int']['input']>;
orderBy?: InputMaybe<Scalars['String']['input']>;
orderDirection?: InputMaybe<Scalars['String']['input']>;
where?: InputMaybe<AccountPowerFilter>;
Expand All @@ -615,6 +625,7 @@ export type AccountProposalsArgs = {
after?: InputMaybe<Scalars['String']['input']>;
before?: InputMaybe<Scalars['String']['input']>;
limit?: InputMaybe<Scalars['Int']['input']>;
offset?: InputMaybe<Scalars['Int']['input']>;
orderBy?: InputMaybe<Scalars['String']['input']>;
orderDirection?: InputMaybe<Scalars['String']['input']>;
where?: InputMaybe<ProposalsOnchainFilter>;
Expand All @@ -625,6 +636,7 @@ export type AccountReceivedTransfersArgs = {
after?: InputMaybe<Scalars['String']['input']>;
before?: InputMaybe<Scalars['String']['input']>;
limit?: InputMaybe<Scalars['Int']['input']>;
offset?: InputMaybe<Scalars['Int']['input']>;
orderBy?: InputMaybe<Scalars['String']['input']>;
orderDirection?: InputMaybe<Scalars['String']['input']>;
where?: InputMaybe<TransferFilter>;
Expand All @@ -635,6 +647,7 @@ export type AccountSentTransfersArgs = {
after?: InputMaybe<Scalars['String']['input']>;
before?: InputMaybe<Scalars['String']['input']>;
limit?: InputMaybe<Scalars['Int']['input']>;
offset?: InputMaybe<Scalars['Int']['input']>;
orderBy?: InputMaybe<Scalars['String']['input']>;
orderDirection?: InputMaybe<Scalars['String']['input']>;
where?: InputMaybe<TransferFilter>;
Expand All @@ -645,6 +658,7 @@ export type AccountVotesArgs = {
after?: InputMaybe<Scalars['String']['input']>;
before?: InputMaybe<Scalars['String']['input']>;
limit?: InputMaybe<Scalars['Int']['input']>;
offset?: InputMaybe<Scalars['Int']['input']>;
orderBy?: InputMaybe<Scalars['String']['input']>;
orderDirection?: InputMaybe<Scalars['String']['input']>;
where?: InputMaybe<VotesOnchainFilter>;
Expand Down Expand Up @@ -1421,6 +1435,7 @@ export type ProposalsOnchainVotesArgs = {
after?: InputMaybe<Scalars['String']['input']>;
before?: InputMaybe<Scalars['String']['input']>;
limit?: InputMaybe<Scalars['Int']['input']>;
offset?: InputMaybe<Scalars['Int']['input']>;
orderBy?: InputMaybe<Scalars['String']['input']>;
orderDirection?: InputMaybe<Scalars['String']['input']>;
where?: InputMaybe<VotesOnchainFilter>;
Expand Down Expand Up @@ -2444,6 +2459,7 @@ export type TransactionDelegationsArgs = {
after?: InputMaybe<Scalars['String']['input']>;
before?: InputMaybe<Scalars['String']['input']>;
limit?: InputMaybe<Scalars['Int']['input']>;
offset?: InputMaybe<Scalars['Int']['input']>;
orderBy?: InputMaybe<Scalars['String']['input']>;
orderDirection?: InputMaybe<Scalars['String']['input']>;
where?: InputMaybe<DelegationFilter>;
Expand All @@ -2454,6 +2470,7 @@ export type TransactionTransfersArgs = {
after?: InputMaybe<Scalars['String']['input']>;
before?: InputMaybe<Scalars['String']['input']>;
limit?: InputMaybe<Scalars['Int']['input']>;
offset?: InputMaybe<Scalars['Int']['input']>;
orderBy?: InputMaybe<Scalars['String']['input']>;
orderDirection?: InputMaybe<Scalars['String']['input']>;
where?: InputMaybe<TransferFilter>;
Expand Down
Loading