Skip to content

Commit

Permalink
Fix global delegation (snapshot-labs#511)
Browse files Browse the repository at this point in the history
* Fix global delegation

* Fix global delegation

* remove ts-ignore
  • Loading branch information
ChaituVR authored Mar 30, 2022
1 parent c590122 commit 036332d
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/utils/delegation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export async function getDelegations(space, network, addresses, snapshot) {
const PAGE_SIZE = 1000;
let result = [];
let page = 0;
const params = {
const params: any = {
delegations: {
__args: {
where: {
Expand Down Expand Up @@ -41,6 +41,26 @@ export async function getDelegations(space, network, addresses, snapshot) {
page++;
if (pageDelegations.length < PAGE_SIZE) break;
}

// Global delegations are null in decentralized subgraph
page = 0;
delete params.delegations.__args.where.space_in;

while (true) {
params.delegations.__args.skip = page * PAGE_SIZE;
params.delegations.__args.where.space = null;
const pageResult = await subgraphRequest(
SNAPSHOT_SUBGRAPH_URL[network],
params
);
result = result.concat(pageResult);

const pageDelegations = pageResult.delegations || [];
result = result.concat(pageDelegations);
page++;
if (pageDelegations.length < PAGE_SIZE) break;
}

const delegations = result.filter(
(delegation: any) =>
addressesLc.includes(delegation.delegate) &&
Expand Down

0 comments on commit 036332d

Please sign in to comment.