Skip to content

Commit

Permalink
fix: staking-payouts for legacy types (#1394)
Browse files Browse the repository at this point in the history
* fix: staking-payouts for legacy kusama node

* add stakingledgerto240

* remove console.logs

* add comment

* add comment
  • Loading branch information
TarikGul committed Feb 7, 2024
1 parent 684ae97 commit e91a913
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions src/services/accounts/AccountsStakingPayoutsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@ import type {
DeriveEraValidatorExposure,
} from '@polkadot/api-derive/staking/types';
import type { Option, StorageKey, u32 } from '@polkadot/types';
import type { AccountId, BalanceOf, BlockHash, EraIndex, Perbill, StakingLedger } from '@polkadot/types/interfaces';
import type {
AccountId,
BalanceOf,
BlockHash,
EraIndex,
Perbill,
StakingLedger,
StakingLedgerTo240,
} from '@polkadot/types/interfaces';
import type {
PalletStakingEraRewardPoints,
PalletStakingExposure,
Expand Down Expand Up @@ -285,12 +293,28 @@ export class AccountsStakingPayoutsService extends AbstractService {
if (!validatorLedger) {
continue;
}
// Check if the reward has already been claimed

/**
* Check if the reward has already been claimed.
*
* It is important to note that the following examines types that are both current and historic.
* When going back far enough in certain chains types such as `StakingLedgerTo240` are necessary for grabbing
* any reward data.
*/
let indexOfEra: number;
if (validatorLedger.legacyClaimedRewards) {
indexOfEra = validatorLedger.legacyClaimedRewards.indexOf(eraIndex);
} else {
} else if ((validatorLedger as unknown as StakingLedger).claimedRewards) {
indexOfEra = (validatorLedger as unknown as StakingLedger).claimedRewards.indexOf(eraIndex);
} else if ((validatorLedger as unknown as StakingLedgerTo240).lastReward) {
const lastReward = (validatorLedger as unknown as StakingLedgerTo240).lastReward;
if (lastReward.isSome) {
indexOfEra = (validatorLedger as unknown as StakingLedgerTo240).lastReward.unwrap().toNumber();
} else {
continue;
}
} else {
continue;
}
const claimed: boolean = Number.isInteger(indexOfEra) && indexOfEra !== -1;
if (unclaimedOnly && claimed) {
Expand Down

0 comments on commit e91a913

Please sign in to comment.