memo for range & entries

This commit is contained in:
Jaco Greeff
2020-03-09 22:57:09 +01:00
parent bcbd4b8d40
commit c1facd8b1c
5 changed files with 18 additions and 13 deletions
@@ -7,7 +7,7 @@ import { Exposure } from '@polkadot/types/interfaces';
import { DeriveEraExposure, DeriveEraExposures, DeriveEraPointsAll, DeriveEraValPoints } from '../types';
import { Observable, combineLatest, of } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
import { map, switchMap, take } from 'rxjs/operators';
import { StorageKey } from '@polkadot/types';
import { memo } from '../util';
@@ -35,7 +35,7 @@ export function erasExposure (api: ApiInterfaceRx): (withActive?: boolean) => Ob
// we could just do entries over the full set, however the set can be quite large - split it into
// batches - may need to re-visit this, or alternatively use pages keys for exceptionally large sets
allPoints.map(({ era }): Observable<[StorageKey, Exposure][]> =>
api.query.staking.erasStakers.entries(era)
api.query.staking.erasStakers.entries(era).pipe(take(1))
)
)
])
@@ -7,7 +7,7 @@ import { ActiveEraInfo, Balance, EraIndex, EraRewardPoints } from '@polkadot/typ
import { DeriveEraPointsAll, DeriveEraValPoints } from '../types';
import { Observable, combineLatest, of } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
import { map, switchMap, take } from 'rxjs/operators';
import { Option, u32 } from '@polkadot/types';
import { memo } from '../util';
@@ -53,10 +53,10 @@ export function erasPoints (api: ApiInterfaceRx): (withActive?: boolean) => Obse
combineLatest([
of(indexes),
indexes.length
? api.query.staking.erasRewardPoints.multi<EraRewardPoints>(indexes)
? api.query.staking.erasRewardPoints.multi<EraRewardPoints>(indexes).pipe(take(1))
: of([]),
indexes.length
? api.query.staking.erasValidatorReward.multi<Option<Balance>>(indexes)
? api.query.staking.erasValidatorReward.multi<Option<Balance>>(indexes).pipe(take(1))
: of([])
])
),
@@ -7,7 +7,7 @@ import { AccountId, Exposure } from '@polkadot/types/interfaces';
import { DeriveStakingValidators } from '../types';
import { Observable, combineLatest, of } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
import { map, switchMap, take } from 'rxjs/operators';
import { StorageKey } from '@polkadot/types';
import { memo } from '../util';
@@ -17,7 +17,7 @@ function queryNextStakers (api: ApiInterfaceRx): Observable<AccountId[]> {
// subscriptions, so we need a trigger - currentIndex acts as that trigger to refresh
return api.derive.session.indexes().pipe(
switchMap(({ activeEra }): Observable<[StorageKey, Exposure][]> =>
api.query.staking.erasStakers.entries(activeEra.addn(1))
api.query.staking.erasStakers.entries(activeEra.addn(1)).pipe(take(1))
),
map((entries): AccountId[] =>
entries.map(([key]): AccountId => key.args[1] as AccountId)