Skip to content

Commit

Permalink
fix: badge query
Browse files Browse the repository at this point in the history
  • Loading branch information
ncomerci committed Sep 7, 2023
1 parent 56b6fbe commit d425f06
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
5 changes: 4 additions & 1 deletion src/clients/OtterspaceSubgraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@ query Badges($raft_id: String!, $address: Bytes!, $first: Int!, $skip: Int!) {
}`

const BADGE_SPEC_OWNERS_QUERY = `
query Badges($badgeCid: String!) {
query Badges($badgeCid: String!, $skip: Int!, $first: Int!) {
badges: badges(
where: {spec: $badgeCid}
orderBy: id
first: $first
skip: $skip
){
id
owner {
Expand Down
30 changes: 20 additions & 10 deletions src/services/BadgesService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,26 +117,36 @@ export class BadgesService {
landOwnerAddresses
)

const outcomes: AirdropOutcome[] = []
const batches = splitArray([...eligibleUsers, ...usersWithBadgesToReinstate], 50)

for (const batch of batches) {
const outcome = await BadgesService.giveBadgeToUsers(LAND_OWNER_BADGE_SPEC_CID, batch)
outcomes.push(outcome)
const airdropOutcomes: AirdropOutcome[] = []
const airdropBatches = splitArray(eligibleUsers, 50)
for (const batch of airdropBatches) {
const outcome = await airdropWithRetry(LAND_OWNER_BADGE_SPEC_CID, batch)
airdropOutcomes.push(outcome)
}

const failedOutcomes = outcomes.filter(
const reinstateResults = await BadgesService.reinstateBadge(LAND_OWNER_BADGE_SPEC_CID, usersWithBadgesToReinstate)

const failedAirdropOutcomes = airdropOutcomes.filter(
({ status, error }) =>
status === AirdropJobStatus.FAILED &&
error !== ErrorReason.NoUserWithoutBadge &&
error !== ErrorReason.NoUserHasVoted
)
if (failedOutcomes.length > 0) {
console.error('Unable to give LandOwner badges', failedOutcomes)
if (failedAirdropOutcomes.length > 0) {
console.error('Unable to give LandOwner badges', failedAirdropOutcomes)

ErrorService.report('Unable to give LandOwner badges', {
category: ErrorCategory.Badges,
failedOutcomes,
failedAirdropOutcomes,
})
}

const failedReinstatements = reinstateResults.filter((result) => result.status === ActionStatus.Failed)
if (failedReinstatements.length > 0) {
console.error('Unable to reinstate LandOwner badges', failedReinstatements)
ErrorService.report('Unable to reinstate LandOwner badges', {
category: ErrorCategory.Badges,
failedReinstatements,
})
}

Expand Down

0 comments on commit d425f06

Please sign in to comment.