Small combineLatest -> queryMulti opts (#2316)

* Small combineLatest -> queryMulti opts

* Update packages/api-derive/src/staking/ownSlashes.ts
This commit is contained in:
Jaco Greeff
2020-05-28 12:43:02 +02:00
committed by GitHub
parent f630d43a25
commit 97438bb2e8
2 changed files with 10 additions and 8 deletions
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { EraIndex } from '@polkadot/types/interfaces';
import { EraIndex, Exposure } from '@polkadot/types/interfaces';
import { ApiInterfaceRx } from '@polkadot/api/types';
import { DeriveOwnExposure } from '../types';
@@ -22,9 +22,9 @@ export function _ownExposure (api: ApiInterfaceRx): (accountId: Uint8Array | str
return cached
? of(cached)
: combineLatest([
api.query.staking.erasStakersClipped(era, accountId),
api.query.staking.erasStakers(era, accountId)
: api.queryMulti<[Exposure, Exposure]>([
[api.query.staking.erasStakersClipped, [era, accountId]],
[api.query.staking.erasStakers, [era, accountId]]
]).pipe(
map(([clipped, exposure]): DeriveOwnExposure => {
const value = { clipped, era, exposure };
@@ -2,12 +2,14 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { EraIndex } from '@polkadot/types/interfaces';
import { ApiInterfaceRx } from '@polkadot/api/types';
import { BalanceOf, EraIndex, Perbill } from '@polkadot/types/interfaces';
import { ITuple } from '@polkadot/types/types';
import { DeriveStakerSlashes } from '../types';
import { Observable, combineLatest, of } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
import { Option } from '@polkadot/types';
import { deriveCache, memo } from '../util';
@@ -22,9 +24,9 @@ export function _ownSlash (api: ApiInterfaceRx): (accountId: Uint8Array | string
return cached
? of(cached)
: combineLatest([
api.query.staking.nominatorSlashInEra(era, accountId),
api.query.staking.validatorSlashInEra(era, accountId)
: api.queryMulti<[Option<BalanceOf>, Option<ITuple<[Perbill, BalanceOf]>>]>([
[api.query.staking.nominatorSlashInEra, [era, accountId]],
[api.query.staking.validatorSlashInEra, [era, accountId]]
]).pipe(
map(([optNom, optVal]): DeriveStakerSlashes => {
const value = {