Skip to content

Commit

Permalink
Merge pull request #2074 from decentdao/correct-proposal-count
Browse files Browse the repository at this point in the history
Fix proposal count
  • Loading branch information
mudrila authored Jul 4, 2024
2 parents 3b72d6a + 73c20c6 commit cfe7d70
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/components/pages/DaoDashboard/Info/InfoProposals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const nonSnapshotProposals = (proposals: FractalProposal[]) => {

const totalProposalsCount = (
proposals: FractalProposal[] | null,
skippedProposalCount: number,
type: GovernanceType | undefined,
) => {
if (!proposals) {
Expand Down Expand Up @@ -53,8 +54,11 @@ const totalProposalsCount = (
}, 0);

// Then, return the highest Azorius proposal ID
// plus the number of Snapshot proposals.
return highestNonSnapshotProposalId + proposals.length - nonSnapshot.length;
// plus the number of Snapshot proposals
// minus the number of skipped proposals.
return (
highestNonSnapshotProposalId + proposals.length - nonSnapshot.length - skippedProposalCount
);
}
default: {
return 0;
Expand All @@ -79,6 +83,7 @@ const nonActiveProposals = (proposals: FractalProposal[]) => {

const allActiveProposalsCount = (
proposals: FractalProposal[] | null,
skippedProposalCount: number,
type: GovernanceType | undefined,
) => {
if (!proposals) {
Expand All @@ -103,7 +108,11 @@ const allActiveProposalsCount = (
} else {
// Getting here means that all of the loaded proposals so far are active
// or there are no non-Snapshot proposals.
const totalNonSnapshotProposalsCount = totalProposalsCount(allNonSnapshotProposals, type);
const totalNonSnapshotProposalsCount = totalProposalsCount(
allNonSnapshotProposals,
skippedProposalCount,
type,
);
if (totalNonSnapshotProposalsCount === activeNonSnapshotProposals.length) {
// If we're here, then all of the proposals on this Safe are active, or there are zero of them!
return activeNonSnapshotProposals.length + activeSnapshotProposals.length;
Expand All @@ -123,7 +132,7 @@ export function InfoProposals() {
const { t } = useTranslation('dashboard');
const {
node: { daoAddress },
governance: { proposals, type },
governance: { proposals, type, skippedProposalCount },
} = useFractal();

if (!daoAddress || !type) {
Expand All @@ -139,11 +148,11 @@ export function InfoProposals() {
);
}

const totalProposalsValue = totalProposalsCount(proposals, type);
const totalProposalsValue = totalProposalsCount(proposals, skippedProposalCount, type);
const totalProposalsDisplay =
totalProposalsValue === undefined ? '...' : totalProposalsValue.toString();

const activeProposalsValue = allActiveProposalsCount(proposals, type);
const activeProposalsValue = allActiveProposalsCount(proposals, skippedProposalCount, type);
const activeProposalsDisplay =
activeProposalsValue === undefined ? '...' : activeProposalsValue.toString();

Expand Down
4 changes: 4 additions & 0 deletions src/hooks/DAO/loaders/governance/useAzoriusProposals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ export const useAzoriusProposals = () => {
proposalCreatedEvent.args[1].eq(0) // proposal id 0
) {
// skip
action.dispatch({
type: FractalGovernanceAction.SKIPPED_A_PROPOSAL,
payload: null,
});
continue;
}

Expand Down
5 changes: 5 additions & 0 deletions src/providers/App/governance/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export enum FractalGovernanceAction {
SET_GOVERNANCE_TYPE = 'SET_GOVERNANCE_TYPE',
SET_PROPOSALS = 'SET_PROPOSALS',
SET_AZORIUS_PROPOSAL = 'SET_AZORIUS_PROPOSAL',
SKIPPED_A_PROPOSAL = 'SKIPPED_A_PROPOSAL',
SET_SNAPSHOT_PROPOSALS = 'SET_SNAPSHOT_PROPOSALS',
SET_PROPOSAL_TEMPLATES = 'SET_PROPOSAL_TEMPLATES',
SET_STRATEGY = 'SET_STRATEGY',
Expand Down Expand Up @@ -69,6 +70,10 @@ export type FractalGovernanceActions =
type: FractalGovernanceAction.SET_AZORIUS_PROPOSAL;
payload: FractalProposal;
}
| {
type: FractalGovernanceAction.SKIPPED_A_PROPOSAL;
payload: null;
}
| {
type: FractalGovernanceAction.SET_SNAPSHOT_PROPOSALS;
payload: FractalProposal[];
Expand Down
7 changes: 7 additions & 0 deletions src/providers/App/governance/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const initialGovernanceState: FractalGovernance = {
loadingProposals: true,
allProposalsLoaded: false,
proposals: null,
skippedProposalCount: 0,
pendingProposals: null,
proposalTemplates: null,
type: undefined,
Expand Down Expand Up @@ -81,6 +82,12 @@ export const governanceReducer = (state: FractalGovernance, action: FractalGover
]),
};
}
case FractalGovernanceAction.SKIPPED_A_PROPOSAL: {
return {
...state,
skippedProposalCount: state.skippedProposalCount + 1,
};
}
case FractalGovernanceAction.SET_PROPOSAL_TEMPLATES: {
return { ...state, proposalTemplates: action.payload };
}
Expand Down
1 change: 1 addition & 0 deletions src/types/fractal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ export interface Governance {
allProposalsLoaded: boolean;
proposals: FractalProposal[] | null;
pendingProposals: string[] | null;
skippedProposalCount: number;
proposalTemplates?: ProposalTemplate[] | null;
tokenClaimContract?: ERC20Claim;
}
Expand Down

0 comments on commit cfe7d70

Please sign in to comment.