Skip to content

Commit

Permalink
fix for claimed in case of validator account
Browse files Browse the repository at this point in the history
- bringing back `partially claimed` for validator
  • Loading branch information
Imod7 committed Aug 6, 2024
1 parent 88be07e commit cd66735
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/services/accounts/AccountsStakingInfoService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ describe('AccountsStakingInfoService', () => {
).toStrictEqual(response22939322);
});

it('works with a valid stash account (block 21157800) & returns an array of claimed (including case erasStakersOverview=null & erasStakers>0, era 1419) & partially claimed (era 1468) (Polkadot)', async () => {
it('works with a validator account (block 21157800) & returns an array of claimed (including case erasStakersOverview=null & erasStakers>0, era 1419), partially claimed & unclaimed eras (Polkadot)', async () => {
expect(
sanitizeNumbers(
await accountStakingInfoService21157800.fetchAccountStakingInfo(blockHash21157800, testAddressPolkadot),
Expand Down
22 changes: 10 additions & 12 deletions src/services/accounts/AccountsStakingInfoService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ export class AccountsStakingInfoService extends AbstractService {
throw new InternalServerError('CurrentEra is None when Some was expected');
}
const currentEra = currentEraMaybeOption.unwrap().toNumber();
console.log('currentEra: ', currentEra);

const eraStart = currentEra - depth;
const eraStart = currentEra - depth > 0 ? currentEra - depth : 0;
let oldCallChecked = false;
for (let e = eraStart; e < eraStart + depth; e++) {
let claimedRewardsEras: u32[] = [];
Expand Down Expand Up @@ -119,10 +117,6 @@ export class AccountsStakingInfoService extends AbstractService {
if (currentEraMaybeOption.isNone) {
throw new InternalServerError('CurrentEra is None when Some was expected');
}
// const currentEra = currentEraMaybeOption.unwrap().toNumber();
// let eraStart = currentEra - depth;

// for (let e = eraStart; e < eraStart + depth; e++) {
const claimedRewardsPerEra = await historicApi.query.staking.claimedRewards(e, stash);
const erasStakersOverview = await historicApi.query.staking.erasStakersOverview(e, stash);
let erasStakers = null;
Expand Down Expand Up @@ -150,11 +144,13 @@ export class AccountsStakingInfoService extends AbstractService {
? 'unclaimed'
: claimedRewardsPerEra.length === pageCount
? 'claimed'
: (!isValidator && nominatorClaimed === true) || (isValidator && claimedRewardsPerEra.length != 0)
? 'claimed'
: !isValidator && nominatorClaimed === false
? 'unclaimed'
: 'undefined';
: isValidator && claimedRewardsPerEra.length != pageCount
? 'partially claimed'
: !isValidator && nominatorClaimed === true
? 'claimed'
: !isValidator && nominatorClaimed === false
? 'unclaimed'
: 'undefined';
claimedRewards.push({ era: e, status: eraStatus });
} else if (erasStakers && erasStakers.total.toBigInt() > 0) {
// if erasStakers.total > 0, then the pageCount is always 1
Expand All @@ -168,6 +164,8 @@ export class AccountsStakingInfoService extends AbstractService {
// this.getValidatorInfo(historicApi, e, nomination, pageCount, claimedRewardsPerEra);
});
}
} else {
break;
}
}
const numSlashingSpans = slashingSpansOption.isSome ? slashingSpansOption.unwrap().prior.length + 1 : 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ const traceBlock = () =>
Promise.resolve().then(() => polkadotRegistryV1002000.createType('TraceBlockResponse', traceBlockRPC.result));

/**
* Deafult Mock polkadot-js ApiPromise. Values are largely meant to be accurate for block
* Default Mock polkadot-js ApiPromise. Values are largely meant to be accurate for block
* #21157800, which is what most Service unit tests are based on.
*/
export const defaultMockApi21157800 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@
},
{
"era": "1468",
"status": "claimed"
"status": "partially claimed"
},
{
"era": "1469",
Expand Down
2 changes: 1 addition & 1 deletion src/types/responses/AccountStakingInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { IAt } from '.';

export interface IEraStatus {
era: number;
status: 'claimed' | 'unclaimed' | 'undefined';
status: 'claimed' | 'unclaimed' | 'partially claimed' | 'undefined';
}

export interface IStakingLedger {
Expand Down

0 comments on commit cd66735

Please sign in to comment.