Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix isClaimed for edgecase with non validator Ids #6027

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions packages/api-derive/src/staking/stakerRewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ function parseRewards (api: DeriveApi, stashId: AccountId, [erasPoints, erasPref
return {
era,
eraReward,
// This might not always be accurate as you need validator account information in order to see if the rewards have been claimed.
// This is possibly adjusted in `filterRewards` when need be.
isClaimed: claimedRewardsEras.some((c) => c.eq(era)),
isEmpty,
isValidator,
Expand Down Expand Up @@ -151,12 +153,26 @@ function filterRewards (eras: EraIndex[], valInfo: [string, DeriveStakingQuery][
return true;
})
.filter(({ validators }) => Object.keys(validators).length !== 0)
.map((reward) =>
objectSpread({}, reward, {
isClaimed: reward.isClaimed,
.map((reward) => {
let isClaimed = reward.isClaimed;
const valKeys = Object.keys(reward.validators);

if (!reward.isClaimed && valKeys.length) {
for (const key of valKeys) {
const info = queryValidators.find((i) => i.accountId.toString() === key);

if (info) {
isClaimed = info.claimedRewardsEras.toArray().some((era) => era.eq(reward.era));
break;
}
}
}

return objectSpread({}, reward, {
isClaimed,
nominators: reward.nominating.filter((n) => reward.validators[n.validatorId])
})
);
});
});
}

export function _stakerRewardsEras (instanceId: string, api: DeriveApi): (eras: EraIndex[], withActive?: boolean) => Observable<ErasResult> {
Expand Down
Loading