Skip to content

Commit

Permalink
feat: allow getDelegatesBySpace to fetch delegates for all spaces
Browse files Browse the repository at this point in the history
With this change space can be passed as null and this will result in all
delegates to be returned instead of per-space results only.

This will be used on new delegate-registry-api.
  • Loading branch information
Sekhmet committed Aug 23, 2024
1 parent 57630e8 commit dd64b14
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/utils/delegation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Delegation = {

export default async function getDelegatesBySpace(
network: string,
space: string,
space: string | null,
snapshot: string | number = 'latest',
options: any = {}
) {
Expand All @@ -26,7 +26,7 @@ export default async function getDelegatesBySpace(

let pivot = 0;
const result = new Map<string, Delegation>();
const spaceIn = buildSpaceIn(space);
const spaceIn = space ? buildSpaceIn(space) : null;

while (true) {
const newResults = await fetchData({
Expand Down Expand Up @@ -86,15 +86,14 @@ async function fetchData({
snapshot
}: {
url: string;
spaces: string[];
spaces: string[] | null;
pivot: number;
snapshot: string | number;
}): Promise<Delegation[]> {
const params: any = {
delegations: {
__args: {
where: {
space_in: spaces,
timestamp_gte: pivot
},
first: PAGE_SIZE,
Expand All @@ -113,5 +112,9 @@ async function fetchData({
params.delegations.__args.block = { number: snapshot };
}

if (spaces !== null) {
params.delegations.__args.where.space_in = spaces;
}

return (await subgraphRequest(url, params)).delegations || [];
}

0 comments on commit dd64b14

Please sign in to comment.