Expose derive staking.nextElected (#2042)
This commit is contained in:
@@ -12,16 +12,20 @@ import { StorageKey } from '@polkadot/types';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
function queryNextStakers (api: ApiInterfaceRx): Observable<AccountId[]> {
|
||||
// only populate for next era in the last session, so track both here - entries are not
|
||||
// subscriptions, so we need a trigger - currentIndex acts as that trigger to refresh
|
||||
return api.derive.session.indexes().pipe(
|
||||
switchMap(({ activeEra }): Observable<StorageKey[]> =>
|
||||
api.query.staking.erasStakers.keys(activeEra.addn(1)).pipe(take(1))
|
||||
),
|
||||
map((keys): AccountId[] =>
|
||||
keys.map((key): AccountId => key.args[1] as AccountId)
|
||||
)
|
||||
export function nextElected (api: ApiInterfaceRx): () => Observable<AccountId[]> {
|
||||
return memo((): Observable<AccountId[]> =>
|
||||
api.query.staking.erasStakers
|
||||
? api.derive.session.indexes().pipe(
|
||||
// only populate for next era in the last session, so track both here - entries are not
|
||||
// subscriptions, so we need a trigger - currentIndex acts as that trigger to refresh
|
||||
switchMap(({ currentEra }): Observable<StorageKey[]> =>
|
||||
api.query.staking.erasStakers.keys(currentEra).pipe(take(1))
|
||||
),
|
||||
map((keys): AccountId[] =>
|
||||
keys.map((key): AccountId => key.args[1] as AccountId)
|
||||
)
|
||||
)
|
||||
: api.query.staking.currentElected<AccountId[]>()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -38,9 +42,7 @@ export function validators (api: ApiInterfaceRx): () => Observable<DeriveStaking
|
||||
? api.query.session.validators()
|
||||
: of([]),
|
||||
api.query.staking
|
||||
? api.query.staking.erasStakers
|
||||
? queryNextStakers(api)
|
||||
: api.query.staking.currentElected<AccountId[]>()
|
||||
? api.derive.staking.nextElected()
|
||||
: of([])
|
||||
]).pipe(
|
||||
map(([validators, nextElected]): DeriveStakingValidators => ({
|
||||
|
||||
Reference in New Issue
Block a user