From 420181581211370923c252fe65df7a5b9d861123 Mon Sep 17 00:00:00 2001 From: tarikgul Date: Fri, 8 Mar 2024 12:24:44 -0500 Subject: [PATCH] small type changes --- packages/api-derive/src/staking/stakerExposure.ts | 4 ++-- packages/api-derive/src/staking/stakerRewards.ts | 8 ++++---- packages/api-derive/src/staking/types.ts | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/api-derive/src/staking/stakerExposure.ts b/packages/api-derive/src/staking/stakerExposure.ts index 2cf0c932b26b..df3eb06d733b 100644 --- a/packages/api-derive/src/staking/stakerExposure.ts +++ b/packages/api-derive/src/staking/stakerExposure.ts @@ -4,7 +4,7 @@ import type { Observable } from 'rxjs'; import type { EraIndex } from '@polkadot/types/interfaces'; import type { DeriveApi } from '../types.js'; -import type { DeriveEraValidatorExposure, DeriveStakerExposure } from './types.js'; +import type { DeriveEraValidatorExposurePaged, DeriveStakerExposure } from './types.js'; import { map, switchMap } from 'rxjs'; @@ -19,7 +19,7 @@ export function _stakerExposures (instanceId: string, api: DeriveApi): (accountI stakerIds.map((stakerId) => exposures.map(({ era, nominators: allNominators, validators: allValidators }): DeriveStakerExposure => { const isValidator = !!allValidators[stakerId]; - const validators: DeriveEraValidatorExposure = {}; + const validators: DeriveEraValidatorExposurePaged = {}; const nominating = allNominators[stakerId] || []; if (isValidator) { diff --git a/packages/api-derive/src/staking/stakerRewards.ts b/packages/api-derive/src/staking/stakerRewards.ts index c439843a4eea..c01b1112d987 100644 --- a/packages/api-derive/src/staking/stakerRewards.ts +++ b/packages/api-derive/src/staking/stakerRewards.ts @@ -4,7 +4,7 @@ import type { Observable } from 'rxjs'; import type { u32, Vec } from '@polkadot/types'; import type { AccountId, EraIndex } from '@polkadot/types/interfaces'; -import type { PalletStakingStakingLedger } from '@polkadot/types/lookup'; +import type { PalletStakingExposure, PalletStakingStakingLedger } from '@polkadot/types/lookup'; import type { BN } from '@polkadot/util'; import type { DeriveApi, DeriveEraPoints, DeriveEraPrefs, DeriveEraRewards, DeriveEraValPoints, DeriveEraValPrefs, DeriveStakerExposure, DeriveStakerReward, DeriveStakerRewardValidator } from '../types.js'; import type { DeriveStakingQuery } from './types.js'; @@ -38,7 +38,7 @@ function parseRewards (api: DeriveApi, stashId: AccountId, [erasPoints, erasPref Object.entries(eraValidators).forEach(([validatorId, exposure]): void => { const valPoints = allValPoints[validatorId] || BN_ZERO; const valComm = allValPrefs[validatorId]?.commission.unwrap() || BN_ZERO; - const expTotal = exposure.total?.unwrap() || BN_ZERO; + const expTotal = ((exposure as PalletStakingExposure).total && (exposure as PalletStakingExposure).total?.unwrap()) || BN_ZERO; let avail = BN_ZERO; let value: BN | undefined; @@ -48,8 +48,8 @@ function parseRewards (api: DeriveApi, stashId: AccountId, [erasPoints, erasPref const valCut = valComm.mul(avail).div(BN_BILLION); let staked: BN; - if (validatorId === stakerId) { - staked = exposure.own.unwrap(); + if (validatorId === stakerId && (exposure as PalletStakingExposure).own) { + staked = (exposure as PalletStakingExposure).own.unwrap(); } else { const stakerExp = exposure.others.find(({ who }) => who.eq(stakerId)); diff --git a/packages/api-derive/src/staking/types.ts b/packages/api-derive/src/staking/types.ts index 8b21aa494de6..b84cd9fecfcb 100644 --- a/packages/api-derive/src/staking/types.ts +++ b/packages/api-derive/src/staking/types.ts @@ -74,7 +74,7 @@ export interface DeriveStakerExposure { isEmpty: boolean; isValidator: boolean; nominating: DeriveEraExposureNominating[]; - validators: DeriveEraValidatorExposure; + validators: DeriveEraValidatorExposurePaged; } export interface DeriveStakerPrefs {