diff --git a/packages/api-derive/src/staking/info.ts b/packages/api-derive/src/staking/info.ts index 926f8ed586..56eb4acd0f 100644 --- a/packages/api-derive/src/staking/info.ts +++ b/packages/api-derive/src/staking/info.ts @@ -7,7 +7,7 @@ import { DerivedStaking } from '../types'; import { Observable, of } from 'rxjs'; import { map, switchMap } from 'rxjs/operators'; import { ApiInterface$Rx } from '@polkadot/api/types'; -import { AccountId, Option, StakingLedger, ValidatorPrefs } from '@polkadot/types'; +import { AccountId, Exposure, Option, StakingLedger, ValidatorPrefs } from '@polkadot/types'; import { drr } from '../util/drr'; @@ -16,17 +16,21 @@ function withStashController (api: ApiInterface$Rx, accountId: AccountId, contro return ( api.queryMulti([ + [api.query.session.nextKeyFor, controllerId], [api.query.staking.ledger, controllerId], - [api.query.staking.validators, stashId], - [api.query.session.nextKeyFor, controllerId] - ]) as any as Observable<[Option, [ValidatorPrefs], Option]> + [api.query.staking.nominators, stashId], + [api.query.staking.stakers, stashId], + [api.query.staking.validators, stashId] + ]) as any as Observable<[Option, Option, [Array], Exposure, [ValidatorPrefs]]> ).pipe( - map(([stakingLedger, [validatorPrefs], nextKeyFor]) => ({ + map(([nextKeyFor, stakingLedger, [nominators], stakers, [validatorPrefs]]) => ({ accountId, controllerId, nextSessionId: nextKeyFor.isSome ? nextKeyFor.unwrap() : undefined, + nominators, + stakers, stakingLedger: stakingLedger.isSome ? stakingLedger.unwrap() : undefined, @@ -43,16 +47,20 @@ function withControllerLedger (api: ApiInterface$Rx, accountId: AccountId, staki return ( api.queryMulti([ - [api.query.staking.validators, stashId], - [api.query.session.nextKeyFor, controllerId] - ]) as any as Observable<[[ValidatorPrefs], Option]> + [api.query.session.nextKeyFor, controllerId], + [api.query.staking.nominators, stashId], + [api.query.staking.stakers, stashId], + [api.query.staking.validators, stashId] + ]) as any as Observable<[Option, [Array], Exposure, [ValidatorPrefs]]> ).pipe( - map(([[validatorPrefs], nextKeyFor]) => ({ + map(([nextKeyFor, [nominators], stakers, [validatorPrefs]]) => ({ accountId, controllerId, nextSessionId: nextKeyFor.isSome ? nextKeyFor.unwrap() : undefined, + nominators, + stakers, stakingLedger, stashId, validatorPrefs diff --git a/packages/api-derive/src/types.ts b/packages/api-derive/src/types.ts index daea44a0b8..5bb5d80133 100644 --- a/packages/api-derive/src/types.ts +++ b/packages/api-derive/src/types.ts @@ -3,7 +3,7 @@ // of the Apache-2.0 license. See the LICENSE file for details. import BN from 'bn.js'; -import { AccountId, Balance, BlockNumber, StakingLedger, ValidatorPrefs, Vote } from '@polkadot/types'; +import { AccountId, Balance, BlockNumber, Exposure, StakingLedger, ValidatorPrefs, Vote } from '@polkadot/types'; export type DerivedBalances = { accountId: AccountId, @@ -61,6 +61,8 @@ export type DerivedStaking = { accountId: AccountId, controllerId?: AccountId, nextSessionId?: AccountId, + nominators?: Array, + stakers?: Exposure, stakingLedger?: StakingLedger, stashId?: AccountId, validatorPrefs?: ValidatorPrefs