Skip to content

Commit

Permalink
refactor: add pagination for projects
Browse files Browse the repository at this point in the history
  • Loading branch information
luisvid committed Oct 26, 2024
1 parent 591c769 commit 7104315
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions packages/ethernaut-optigov/src/tasks/Projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ require('../scopes/optigov')
'projects',
'Prints a list of projects registered in RetroPGF, given specified filters',
)
.addOptionalParam(
'limit',
'The maximum number of proposals to fetch. Defaults to 10.',
10,
types.int,
)
.addOptionalParam(
'offset',
'The number of proposals to skip before starting to fetch. Defaults to 0.',
0,
types.int,
)
.addParam(
'round',
'The round number to query. Defaults to "latest". Can also be "any" to query all rounds.',
Expand All @@ -26,9 +38,9 @@ require('../scopes/optigov')
undefined,
types.string,
)
.setAction(async ({ round, name, category }) => {
.setAction(async ({ limit, offset, round, name, category }) => {
try {
const projects = await getProjects(round)
const projects = await getProjects(limit, offset, round)

const filteredProjects = filterProjects(projects, name, category)

Expand Down Expand Up @@ -67,7 +79,7 @@ function printProjects(projects) {
return strs.join('\n\n')
}

async function getProjects(round) {
async function getProjects(limit, offset, round) {
const agora = new Agora()
const projects = new Projects(agora)

Expand All @@ -78,8 +90,8 @@ async function getProjects(round) {
}

if (!roundId) {
return await projects.getProjects()
return await projects.getProjects(limit, offset)
}

return await projects.getRoundProjects({ roundId })
return await projects.getRoundProjects({ roundId, limit, offset })
}

0 comments on commit 7104315

Please sign in to comment.