Skip to content

Commit

Permalink
Merge pull request #144 from terra-money/fix/proposals-query
Browse files Browse the repository at this point in the history
Temporary fix to allow for querying more than 100 proposals
  • Loading branch information
terencelimzhengwei authored Oct 6, 2023
2 parents 954031e + 05068cc commit f39e71a
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions apps/enterprise/src/queries/useDaoProposalsQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,30 @@ export const useDaoProposalsQuery = ({
return useQuery(
[QUERY_KEY.PROPOSALS, address],
async () => {
const { proposals } = await query<ProposalsQueryArguments, enterprise.ProposalsResponse>(address, {
proposals: { limit: 500 },
});
// Removing temporarily to allow for querying all proposals
// const { proposals } = await query<ProposalsQueryArguments, enterprise.ProposalsResponse>(address, {
// proposals: { limit: 500 },
// });

return proposals.map((resp) => toProposal(resp, toDao(assertDefined(dao)))).sort((a, b) => b.created - a.created);
// return proposals.map((resp) => toProposal(resp, toDao(assertDefined(dao)))).sort((a, b) => b.created - a.created);

let proposalList: any[] = [];
let startAfter = 0;

while (true) {
const { proposals } = await query<ProposalsQueryArguments, enterprise.ProposalsResponse>(address, {
proposals: {
limit: 100,
start_after: startAfter
},
});
await proposalList.push.apply(proposalList, proposals);
startAfter += 100;

if(proposals.length < 100) {
return proposalList.map((resp) => toProposal(resp, toDao(assertDefined(dao)))).sort((a, b) => b.created - a.created);
}
}
},
{
refetchOnMount: false,
Expand Down

0 comments on commit f39e71a

Please sign in to comment.