Skip to content

Commit 08d5289

Browse files
SekhmetChaituVR
andauthored
feat: allow getDelegatesBySpace to fetch delegates for all spaces (#1050)
* 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. * v0.12.7 --------- Co-authored-by: Chaitanya <[email protected]>
1 parent 57630e8 commit 08d5289

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@snapshot-labs/snapshot.js",
3-
"version": "0.12.6",
3+
"version": "0.12.7",
44
"repository": "snapshot-labs/snapshot.js",
55
"license": "MIT",
66
"main": "dist/snapshot.cjs.js",

src/utils/delegation.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type Delegation = {
1313

1414
export default async function getDelegatesBySpace(
1515
network: string,
16-
space: string,
16+
space: string | null,
1717
snapshot: string | number = 'latest',
1818
options: any = {}
1919
) {
@@ -26,7 +26,7 @@ export default async function getDelegatesBySpace(
2626

2727
let pivot = 0;
2828
const result = new Map<string, Delegation>();
29-
const spaceIn = buildSpaceIn(space);
29+
const spaceIn = space ? buildSpaceIn(space) : null;
3030

3131
while (true) {
3232
const newResults = await fetchData({
@@ -86,15 +86,14 @@ async function fetchData({
8686
snapshot
8787
}: {
8888
url: string;
89-
spaces: string[];
89+
spaces: string[] | null;
9090
pivot: number;
9191
snapshot: string | number;
9292
}): Promise<Delegation[]> {
9393
const params: any = {
9494
delegations: {
9595
__args: {
9696
where: {
97-
space_in: spaces,
9897
timestamp_gte: pivot
9998
},
10099
first: PAGE_SIZE,
@@ -113,5 +112,9 @@ async function fetchData({
113112
params.delegations.__args.block = { number: snapshot };
114113
}
115114

115+
if (spaces !== null) {
116+
params.delegations.__args.where.space_in = spaces;
117+
}
118+
116119
return (await subgraphRequest(url, params)).delegations || [];
117120
}

0 commit comments

Comments
 (0)