Skip to content

Commit

Permalink
small type changes
Browse files Browse the repository at this point in the history
  • Loading branch information
TarikGul committed Mar 8, 2024
1 parent 12c35f8 commit 4201815
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/api-derive/src/staking/stakerExposure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions packages/api-derive/src/staking/stakerRewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;

Check failure on line 41 in packages/api-derive/src/staking/stakerRewards.ts

View workflow job for this annotation

GitHub Actions / pr (lint)

Prefer using an optional chain expression instead, as it's more concise and easier to read
let avail = BN_ZERO;
let value: BN | undefined;

Expand All @@ -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));

Expand Down
2 changes: 1 addition & 1 deletion packages/api-derive/src/staking/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export interface DeriveStakerExposure {
isEmpty: boolean;
isValidator: boolean;
nominating: DeriveEraExposureNominating[];
validators: DeriveEraValidatorExposure;
validators: DeriveEraValidatorExposurePaged;
}

export interface DeriveStakerPrefs {
Expand Down

0 comments on commit 4201815

Please sign in to comment.