From dd64b1486560a01d43c367d646801bce11f2181f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wiktor=20Tkaczy=C5=84ski?= Date: Fri, 23 Aug 2024 17:57:15 +0200 Subject: [PATCH] feat: allow getDelegatesBySpace to fetch delegates for all spaces 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. --- src/utils/delegation.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/utils/delegation.ts b/src/utils/delegation.ts index 488a43800..1ffdd3354 100644 --- a/src/utils/delegation.ts +++ b/src/utils/delegation.ts @@ -13,7 +13,7 @@ type Delegation = { export default async function getDelegatesBySpace( network: string, - space: string, + space: string | null, snapshot: string | number = 'latest', options: any = {} ) { @@ -26,7 +26,7 @@ export default async function getDelegatesBySpace( let pivot = 0; const result = new Map(); - const spaceIn = buildSpaceIn(space); + const spaceIn = space ? buildSpaceIn(space) : null; while (true) { const newResults = await fetchData({ @@ -86,7 +86,7 @@ async function fetchData({ snapshot }: { url: string; - spaces: string[]; + spaces: string[] | null; pivot: number; snapshot: string | number; }): Promise { @@ -94,7 +94,6 @@ async function fetchData({ delegations: { __args: { where: { - space_in: spaces, timestamp_gte: pivot }, first: PAGE_SIZE, @@ -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 || []; }