Skip to content

Commit

Permalink
Sanitize eras for _stakerRewards (#5912)
Browse files Browse the repository at this point in the history
* Sanitize eras for _stakerRewards

* Small nits
  • Loading branch information
TarikGul committed Jun 25, 2024
1 parent 0957103 commit bdafcd9
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions packages/api-derive/src/staking/stakerRewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,15 @@ export function _stakerRewardsEras (instanceId: string, api: DeriveApi): (eras:
}

export function _stakerRewards (instanceId: string, api: DeriveApi): (accountIds: (Uint8Array | string)[], eras: EraIndex[], withActive?: boolean) => Observable<DeriveStakerReward[][]> {
return memo(instanceId, (accountIds: (Uint8Array | string)[], eras: EraIndex[], withActive = false): Observable<DeriveStakerReward[][]> =>
combineLatest([
return memo(instanceId, (accountIds: (Uint8Array | string)[], eras: EraIndex[], withActive = false): Observable<DeriveStakerReward[][]> => {
// Ensures that when number or string types are passed in they are sanitized
// Ref: https://github.com/polkadot-js/api/issues/5910
const sanitizedEras: EraIndex[] = eras.map((e) => typeof e === 'number' || typeof e === 'string' ? api.registry.createType('u32', e) : e);

return combineLatest([
api.derive.staking.queryMulti(accountIds, { withClaimedRewardsEras: true, withLedger: true }),
api.derive.staking._stakerExposures(accountIds, eras, withActive),
api.derive.staking._stakerRewardsEras(eras, withActive)
api.derive.staking._stakerExposures(accountIds, sanitizedEras, withActive),
api.derive.staking._stakerRewardsEras(sanitizedEras, withActive)
]).pipe(
switchMap(([queries, exposures, erasResult]): Observable<DeriveStakerReward[][]> => {
const allRewards = queries.map(({ claimedRewardsEras, stakingLedger, stashId }, index): DeriveStakerReward[] =>
Expand Down Expand Up @@ -208,7 +212,8 @@ export function _stakerRewards (instanceId: string, api: DeriveApi): (accountIds
)
);
})
)
);
}
);
}

Expand Down

0 comments on commit bdafcd9

Please sign in to comment.