Skip to content

Commit

Permalink
fix: APP-3244 - Fix proposal filters on governance page (#1357)
Browse files Browse the repository at this point in the history
* included explicit filteredProposal function fixing the issue

* removing client side filter fix, and adding sdk filter functionality for token voting plugin

* adding sdk filter functionality for multisig  plugin
  • Loading branch information
Barukimang authored May 29, 2024
1 parent 86c1f4e commit c182cff
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/services/aragon-sdk/queries/use-proposals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ import {providers} from 'ethers';
import {
toMultisigProposalListItem,
toTokenVotingProposalListItem,
computeMultisigProposalStatusFilter,
computeTokenVotingProposalStatusFilter,
} from '../selectors/proposals';
import {
QueryMultisigProposals,
Expand All @@ -71,7 +73,13 @@ async function getProposalsList(
params: IFetchProposalsParams,
network: SupportedNetworks
) {
const {daoAddressOrEns, limit, skip, direction, sortBy} = params;
const {daoAddressOrEns, limit, skip, direction, sortBy, status} = params;

const statusFilter = status
? isTokenVotingClient(client)
? computeTokenVotingProposalStatusFilter(status)
: computeMultisigProposalStatusFilter(status)
: {};

if (isTokenVotingClient(client)) {
const {tokenVotingProposals} = await request<{
Expand All @@ -80,6 +88,7 @@ async function getProposalsList(
}>(SUBGRAPH_API_URL[network]!, QueryTokenVotingProposals, {
where: {
dao: daoAddressOrEns,
...statusFilter,
},
limit,
skip,
Expand Down Expand Up @@ -124,6 +133,7 @@ async function getProposalsList(
}>(SUBGRAPH_API_URL[network]!, QueryMultisigProposals, {
where: {
dao: daoAddressOrEns,
...statusFilter,
},
limit,
skip,
Expand Down
66 changes: 66 additions & 0 deletions src/services/aragon-sdk/selectors/proposals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
decodeRatio,
getCompactProposalId,
hexToBytes,
ProposalStatus,
InvalidProposalStatusError,
} from '@aragon/sdk-client-common';
import {SubgraphMultisigProposalListItem} from 'utils/types';
import {
Expand Down Expand Up @@ -112,3 +114,67 @@ export function toTokenVotingProposalListItem(
}),
};
}

export function computeMultisigProposalStatusFilter(status: ProposalStatus) {
let where = {};
const now = Math.round(new Date().getTime() / 1000).toString();
switch (status) {
case ProposalStatus.PENDING:
where = {startDate_gte: now};
break;
case ProposalStatus.ACTIVE:
where = {startDate_lt: now, endDate_gte: now, executed: false};
break;
case ProposalStatus.EXECUTED:
where = {executed: true};
break;
case ProposalStatus.SUCCEEDED:
where = {
or: [
{approvalReached: true, endDate_lt: now, isSignaling: false},
{approvalReached: true, isSignaling: true},
],
};
break;
case ProposalStatus.DEFEATED:
where = {
endDate_lt: now,
executed: false,
};
break;
default:
throw new InvalidProposalStatusError();
}
return where;
}

export function computeTokenVotingProposalStatusFilter(status: ProposalStatus) {
let where = {};
const now = Math.round(new Date().getTime() / 1000).toString();
switch (status) {
case ProposalStatus.PENDING:
where = {startDate_gte: now};
break;
case ProposalStatus.ACTIVE:
where = {startDate_lt: now, endDate_gte: now, executed: false};
break;
case ProposalStatus.EXECUTED:
where = {executed: true};
break;
case ProposalStatus.SUCCEEDED:
where = {
or: [{approvalReached: true, endDate_lt: now}, {earlyExecutable: true}],
};
break;
case ProposalStatus.DEFEATED:
where = {
potentiallyExecutable: false,
endDate_lt: now,
executed: false,
};
break;
default:
throw new InvalidProposalStatusError();
}
return where;
}

0 comments on commit c182cff

Please sign in to comment.