Skip to content

Commit

Permalink
Add isClaimed field to api.derive.staking._stakerRewards (#6007)
Browse files Browse the repository at this point in the history
* Add isClaimed field to `api.derive.staking._stakerRewards`

* Fix isClaimed: false
  • Loading branch information
TarikGul authored Oct 24, 2024
1 parent 9d9a99e commit da100e8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/api-derive/src/staking/stakerRewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function extractCompatRewards (claimedRewardsEras: Vec<u32>, ledger?: PalletStak
return claimedRewardsEras.toArray().concat(l);
}

function parseRewards (api: DeriveApi, stashId: AccountId, [erasPoints, erasPrefs, erasRewards]: ErasResult, exposures: DeriveStakerExposure[]): DeriveStakerReward[] {
function parseRewards (api: DeriveApi, stashId: AccountId, [erasPoints, erasPrefs, erasRewards]: ErasResult, exposures: DeriveStakerExposure[], claimedRewardsEras: Vec<u32>): DeriveStakerReward[] {
return exposures.map(({ era, isEmpty, isValidator, nominating, validators: eraValidators }): DeriveStakerReward => {
const { eraPoints, validators: allValPoints } = erasPoints.find((p) => p.era.eq(era)) || { eraPoints: BN_ZERO, validators: {} as DeriveEraValPoints };
const { eraReward } = erasRewards.find((r) => r.era.eq(era)) || { eraReward: api.registry.createType('Balance') };
Expand Down Expand Up @@ -84,6 +84,7 @@ function parseRewards (api: DeriveApi, stashId: AccountId, [erasPoints, erasPref
return {
era,
eraReward,
isClaimed: claimedRewardsEras.some((c) => c.eq(era)),
isEmpty,
isValidator,
nominating,
Expand Down Expand Up @@ -152,6 +153,7 @@ function filterRewards (eras: EraIndex[], valInfo: [string, DeriveStakingQuery][
.filter(({ validators }) => Object.keys(validators).length !== 0)
.map((reward) =>
objectSpread({}, reward, {
isClaimed: filter.some((f) => reward.era.eq(f)),
nominators: reward.nominating.filter((n) => reward.validators[n.validatorId])
})
);
Expand Down Expand Up @@ -182,7 +184,7 @@ export function _stakerRewards (instanceId: string, api: DeriveApi): (accountIds
const allRewards = queries.map(({ claimedRewardsEras, stakingLedger, stashId }, index): DeriveStakerReward[] =>
(!stashId || (!stakingLedger && !claimedRewardsEras))
? []
: parseRewards(api, stashId, erasResult, exposures[index])
: parseRewards(api, stashId, erasResult, exposures[index], claimedRewardsEras)
);

if (withActive) {
Expand Down
1 change: 1 addition & 0 deletions packages/api-derive/src/staking/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export interface DeriveStakerRewardValidator {
export interface DeriveStakerReward {
era: EraIndex;
eraReward: Balance;
isClaimed: boolean;
isEmpty: boolean;
isValidator: boolean;
nominating: DeriveEraExposureNominating[];
Expand Down

0 comments on commit da100e8

Please sign in to comment.