Skip to content

Commit

Permalink
refactor: Moved notifyMapElegible back into a function
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosvdr committed May 9, 2024
1 parent 2c6b581 commit 3d77404
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions packages/indexer-common/src/allocations/query-fees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,31 +431,33 @@ export class AllocationReceiptCollector implements ReceiptCollector {
}

startRAVProcessing() {
const notifyAndMapEligible = (signedRavs: ValidRavs) => {
if (signedRavs.belowThreshold.length > 0) {
const logger = this.logger.child({ function: 'startRAVProcessing()' })
const totalValueGRT = formatGRT(
signedRavs.belowThreshold.reduce(
(total, signedRav) =>
total.add(BigNumber.from(signedRav.rav.rav.valueAggregate)),
BigNumber.from(0),
),
)
logger.info(`Query RAVs below the redemption threshold`, {
hint: 'If you would like to redeem vouchers like this, reduce the voucher redemption threshold',
voucherRedemptionThreshold: formatGRT(this.voucherRedemptionThreshold),
belowThresholdCount: signedRavs.belowThreshold.length,
totalValueGRT,
allocations: signedRavs.belowThreshold.map(
(signedRav) => signedRav.rav.rav.allocationId,
),
})
}
return signedRavs.eligible
}

const pendingRAVs = this.getPendingRAVs()
const signedRAVs = this.getSignedRAVsEventual(pendingRAVs)
const eligibleRAVs = signedRAVs
.map((signedRavs: ValidRavs) => {
if (signedRavs.belowThreshold.length > 0) {
const logger = this.logger.child({ function: 'startRAVProcessing()' })
const totalValueGRT = formatGRT(
signedRavs.belowThreshold.reduce(
(total, signedRav) =>
total.add(BigNumber.from(signedRav.rav.rav.valueAggregate)),
BigNumber.from(0),
),
)
logger.info(`Query RAVs below the redemption threshold`, {
hint: 'If you would like to redeem vouchers like this, reduce the voucher redemption threshold',
voucherRedemptionThreshold: formatGRT(this.voucherRedemptionThreshold),
belowThresholdCount: signedRavs.belowThreshold.length,
totalValueGRT,
allocations: signedRavs.belowThreshold.map(
(signedRav) => signedRav.rav.rav.allocationId,
),
})
}
return signedRavs.eligible
})
.map(notifyAndMapEligible)
.filter((signedRavs) => signedRavs.length > 0)
eligibleRAVs.pipe(async (ravs) => await this.submitRAVs(ravs))
}
Expand Down

0 comments on commit 3d77404

Please sign in to comment.