Adjust multi to infer return types (#4002)
* Adjust multi to infer return types * some linting * Additional * Dedupe
This commit is contained in:
@@ -48,7 +48,7 @@ export function _erasPoints (instanceId: string, api: ApiInterfaceRx): (eras: Er
|
||||
|
||||
return !remaining.length
|
||||
? of(cached)
|
||||
: api.query.staking.erasRewardPoints.multi<EraRewardPoints>(remaining).pipe(
|
||||
: api.query.staking.erasRewardPoints.multi(remaining).pipe(
|
||||
map((points): DeriveEraPoints[] => {
|
||||
const query = mapPoints(remaining, points);
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ export function _erasRewards (instanceId: string, api: ApiInterfaceRx): (eras: E
|
||||
return of(cached);
|
||||
}
|
||||
|
||||
return api.query.staking.erasValidatorReward.multi<Option<Balance>>(remaining).pipe(
|
||||
return api.query.staking.erasValidatorReward.multi(remaining).pipe(
|
||||
map((optRewards) => {
|
||||
const query = mapRewards(remaining, optRewards);
|
||||
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { Option, Vec } from '@polkadot/types';
|
||||
import type { AccountId, Keys } from '@polkadot/types/interfaces';
|
||||
import type { AccountId } from '@polkadot/types/interfaces';
|
||||
import type { NodeRuntimeSessionKeys } from '@polkadot/types/lookup';
|
||||
import type { ITuple } from '@polkadot/types/types';
|
||||
import type { DeriveStakingKeys } from './types';
|
||||
|
||||
@@ -12,13 +13,17 @@ import { combineLatest, map, of, switchMap } from 'rxjs';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
function extractsIds (stashId: Uint8Array | string, queuedKeys: [AccountId, Keys][], nextKeys: Option<Keys>): DeriveStakingKeys {
|
||||
function extractsIds (stashId: Uint8Array | string, queuedKeys: [AccountId, NodeRuntimeSessionKeys | AccountId[]][], nextKeys: Option<NodeRuntimeSessionKeys>): DeriveStakingKeys {
|
||||
const sessionIds = (queuedKeys.find(([currentId]) => currentId.eq(stashId)) || [undefined, [] as AccountId[]])[1];
|
||||
const nextSessionIds = nextKeys.unwrapOr([] as AccountId[]);
|
||||
|
||||
return {
|
||||
nextSessionIds,
|
||||
sessionIds
|
||||
nextSessionIds: Array.isArray(nextSessionIds)
|
||||
? nextSessionIds
|
||||
: [...nextSessionIds.values()] as AccountId[],
|
||||
sessionIds: Array.isArray(sessionIds)
|
||||
? sessionIds
|
||||
: [...sessionIds.values()] as AccountId[]
|
||||
};
|
||||
}
|
||||
|
||||
@@ -33,13 +38,13 @@ export function keys (instanceId: string, api: ApiInterfaceRx): (stashId: Uint8A
|
||||
export function keysMulti (instanceId: string, api: ApiInterfaceRx): (stashIds: (Uint8Array | string)[]) => Observable<DeriveStakingKeys[]> {
|
||||
return memo(instanceId, (stashIds: (Uint8Array | string)[]): Observable<DeriveStakingKeys[]> =>
|
||||
stashIds.length
|
||||
? api.query.session.queuedKeys<Vec<ITuple<[AccountId, Keys]>>>().pipe(
|
||||
switchMap((queuedKeys): Observable<[Vec<ITuple<[AccountId, Keys]>>, Option<Keys>[]]> =>
|
||||
? api.query.session.queuedKeys().pipe(
|
||||
switchMap((queuedKeys): Observable<[Vec<ITuple<[AccountId, NodeRuntimeSessionKeys]>>, Option<NodeRuntimeSessionKeys>[]]> =>
|
||||
combineLatest([
|
||||
of(queuedKeys),
|
||||
api.consts.session?.dedupKeyPrefix
|
||||
? api.query.session.nextKeys.multi<Option<Keys>>(stashIds.map((stashId) => [api.consts.session.dedupKeyPrefix, stashId]))
|
||||
: api.query.session.nextKeys.multi<Option<Keys>>(stashIds)
|
||||
? api.query.session.nextKeys.multi(stashIds.map((stashId) => [api.consts.session.dedupKeyPrefix, stashId]))
|
||||
: api.query.session.nextKeys.multi(stashIds)
|
||||
])
|
||||
),
|
||||
map(([queuedKeys, nextKeys]) =>
|
||||
|
||||
@@ -34,7 +34,7 @@ function getLedgers (api: ApiInterfaceRx, optIds: (Option<AccountId> | null)[],
|
||||
|
||||
return (
|
||||
ids.length
|
||||
? api.query.staking.ledger.multi<Option<StakingLedger>>(ids)
|
||||
? api.query.staking.ledger.multi(ids)
|
||||
: of([])
|
||||
).pipe(
|
||||
map((optLedgers): Option<StakingLedger>[] => {
|
||||
@@ -57,19 +57,19 @@ function getStashInfo (api: ApiInterfaceRx, stashIds: AccountId[], activeEra: Er
|
||||
|
||||
return combineLatest([
|
||||
withController || withLedger
|
||||
? api.query.staking.bonded.multi<Option<AccountId>>(stashIds)
|
||||
? api.query.staking.bonded.multi(stashIds)
|
||||
: of(stashIds.map(() => null)),
|
||||
withNominations
|
||||
? api.query.staking.nominators.multi<Option<Nominations>>(stashIds)
|
||||
? api.query.staking.nominators.multi(stashIds)
|
||||
: of(stashIds.map(() => emptyNoms)),
|
||||
withDestination
|
||||
? api.query.staking.payee.multi<RewardDestination>(stashIds)
|
||||
? api.query.staking.payee.multi(stashIds)
|
||||
: of(stashIds.map(() => emptyRewa)),
|
||||
withPrefs
|
||||
? api.query.staking.validators.multi<ValidatorPrefs>(stashIds)
|
||||
? api.query.staking.validators.multi(stashIds)
|
||||
: of(stashIds.map(() => emptyPrefs)),
|
||||
withExposure
|
||||
? api.query.staking.erasStakers.multi<Exposure>(stashIds.map((stashId) => [activeEra, stashId]))
|
||||
? api.query.staking.erasStakers.multi(stashIds.map((stashId) => [activeEra, stashId]))
|
||||
: of(stashIds.map(() => emptyExpo))
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { EraIndex, ValidatorPrefs } from '@polkadot/types/interfaces';
|
||||
import type { EraIndex } from '@polkadot/types/interfaces';
|
||||
import type { DeriveStakerPrefs } from '../types';
|
||||
|
||||
import { map, switchMap } from 'rxjs';
|
||||
@@ -13,7 +13,7 @@ import { memo } from '../util';
|
||||
export function _stakerPrefs (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, eras: EraIndex[], withActive: boolean) => Observable<DeriveStakerPrefs[]> {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
return memo(instanceId, (accountId: Uint8Array | string, eras: EraIndex[], _withActive: boolean): Observable<DeriveStakerPrefs[]> =>
|
||||
api.query.staking.erasValidatorPrefs.multi<ValidatorPrefs>(eras.map((era) => [era, accountId])).pipe(
|
||||
api.query.staking.erasValidatorPrefs.multi(eras.map((era) => [era, accountId])).pipe(
|
||||
map((all): DeriveStakerPrefs[] =>
|
||||
all.map((validatorPrefs, index): DeriveStakerPrefs => ({
|
||||
era: eras[index],
|
||||
|
||||
Reference in New Issue
Block a user