diff --git a/packages/api-derive/src/staking/account.ts b/packages/api-derive/src/staking/account.ts index 7365d8b4da..2eac50f188 100644 --- a/packages/api-derive/src/staking/account.ts +++ b/packages/api-derive/src/staking/account.ts @@ -7,7 +7,7 @@ import { Balance, StakingLedger, UnlockChunk } from '@polkadot/types/interfaces' import { DeriveSessionInfo, DeriveStakingAccount, DeriveStakingQuery, DeriveUnlocking } from '../types'; import BN from 'bn.js'; -import { Observable, combineLatest } from 'rxjs'; +import { Observable } from 'rxjs'; import { map, switchMap } from 'rxjs/operators'; import { isUndefined } from '@polkadot/util'; @@ -70,21 +70,19 @@ function parseResult (api: ApiInterfaceRx, sessionInfo: DeriveSessionInfo, query }; } -export function _account (api: ApiInterfaceRx): (sessionInfo: DeriveSessionInfo, accountId: Uint8Array | string) => Observable { - return memo((sessionInfo: DeriveSessionInfo, accountId: Uint8Array | string): Observable => - api.derive.staking.query(accountId).pipe( - map((query) => parseResult(api, sessionInfo, query)) - )); -} - /** * @description From a stash, retrieve the controllerId and fill in all the relevant staking details */ export function account (api: ApiInterfaceRx): (accountId: Uint8Array | string) => Observable { return memo((accountId: Uint8Array | string): Observable => api.derive.session.info().pipe( - switchMap((sessionInfo) => api.derive.staking._account(sessionInfo, accountId)) - )); + switchMap((sessionInfo) => + api.derive.staking.query(accountId).pipe( + map((query) => parseResult(api, sessionInfo, query)) + ) + ) + ) + ); } /** @@ -94,7 +92,12 @@ export function accounts (api: ApiInterfaceRx): (accountIds: (Uint8Array | strin return memo((accountIds: (Uint8Array | string)[]): Observable => api.derive.session.info().pipe( switchMap((sessionInfo) => - combineLatest(accountIds.map((accountId) => api.derive.staking._account(sessionInfo, accountId))) + api.derive.staking.queryMulti(accountIds).pipe( + map((queries) => + queries.map((query) => parseResult(api, sessionInfo, query)) + ) + ) ) - )); + ) + ); } diff --git a/packages/api-derive/src/staking/electedInfo.ts b/packages/api-derive/src/staking/electedInfo.ts index b7761f1e04..d4963df409 100644 --- a/packages/api-derive/src/staking/electedInfo.ts +++ b/packages/api-derive/src/staking/electedInfo.ts @@ -5,7 +5,7 @@ import { ApiInterfaceRx } from '@polkadot/api/types'; import { DeriveStakingElected } from '../types'; -import { Observable, combineLatest, of } from 'rxjs'; +import { Observable } from 'rxjs'; import { map, switchMap } from 'rxjs/operators'; import { memo } from '../util'; @@ -13,20 +13,14 @@ import { memo } from '../util'; export function electedInfo (api: ApiInterfaceRx): () => Observable { return memo((): Observable => api.derive.staking.validators().pipe( - switchMap(({ nextElected }): Observable => { - if (!nextElected.length) { - return of({ info: [], nextElected: [] }); - } - - return combineLatest( - nextElected.map((accountId) => api.derive.staking.query(accountId)) - ).pipe( + switchMap(({ nextElected }): Observable => + api.derive.staking.queryMulti(nextElected).pipe( map((info): DeriveStakingElected => ({ info, nextElected })) - ); - }) + ) + ) ) ); } diff --git a/packages/api-derive/src/staking/waitingInfo.ts b/packages/api-derive/src/staking/waitingInfo.ts index 0ac3ef9803..aacf8874b2 100644 --- a/packages/api-derive/src/staking/waitingInfo.ts +++ b/packages/api-derive/src/staking/waitingInfo.ts @@ -5,7 +5,7 @@ import { ApiInterfaceRx } from '@polkadot/api/types'; import { DeriveStakingWaiting } from '../types'; -import { Observable, combineLatest, of } from 'rxjs'; +import { Observable, combineLatest } from 'rxjs'; import { map, switchMap } from 'rxjs/operators'; import { memo } from '../util'; @@ -20,13 +20,7 @@ export function waitingInfo (api: ApiInterfaceRx): () => Observable a.toString()); const waiting = stashes.filter((v) => !elected.includes(v.toString())); - if (!waiting.length) { - return of({ info: [], waiting: [] }); - } - - return combineLatest( - waiting.map((accountId) => api.derive.staking.query(accountId)) - ).pipe( + return api.derive.staking.queryMulti(waiting).pipe( map((info): DeriveStakingWaiting => ({ info, waiting