Skip to content

Commit bdafcd9

Browse files
authored
Sanitize eras for _stakerRewards (#5912)
* Sanitize eras for _stakerRewards * Small nits
1 parent 0957103 commit bdafcd9

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

packages/api-derive/src/staking/stakerRewards.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,15 @@ export function _stakerRewardsEras (instanceId: string, api: DeriveApi): (eras:
168168
}
169169

170170
export function _stakerRewards (instanceId: string, api: DeriveApi): (accountIds: (Uint8Array | string)[], eras: EraIndex[], withActive?: boolean) => Observable<DeriveStakerReward[][]> {
171-
return memo(instanceId, (accountIds: (Uint8Array | string)[], eras: EraIndex[], withActive = false): Observable<DeriveStakerReward[][]> =>
172-
combineLatest([
171+
return memo(instanceId, (accountIds: (Uint8Array | string)[], eras: EraIndex[], withActive = false): Observable<DeriveStakerReward[][]> => {
172+
// Ensures that when number or string types are passed in they are sanitized
173+
// Ref: https://github.com/polkadot-js/api/issues/5910
174+
const sanitizedEras: EraIndex[] = eras.map((e) => typeof e === 'number' || typeof e === 'string' ? api.registry.createType('u32', e) : e);
175+
176+
return combineLatest([
173177
api.derive.staking.queryMulti(accountIds, { withClaimedRewardsEras: true, withLedger: true }),
174-
api.derive.staking._stakerExposures(accountIds, eras, withActive),
175-
api.derive.staking._stakerRewardsEras(eras, withActive)
178+
api.derive.staking._stakerExposures(accountIds, sanitizedEras, withActive),
179+
api.derive.staking._stakerRewardsEras(sanitizedEras, withActive)
176180
]).pipe(
177181
switchMap(([queries, exposures, erasResult]): Observable<DeriveStakerReward[][]> => {
178182
const allRewards = queries.map(({ claimedRewardsEras, stakingLedger, stashId }, index): DeriveStakerReward[] =>
@@ -208,7 +212,8 @@ export function _stakerRewards (instanceId: string, api: DeriveApi): (accountIds
208212
)
209213
);
210214
})
211-
)
215+
);
216+
}
212217
);
213218
}
214219

0 commit comments

Comments
 (0)