Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions packages/api-derive/src/staking/electedInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.

import { ApiInterfaceRx } from '@polkadot/api/types';
import { AccountId } from '@polkadot/types/interfaces';
import { DerivedStaking, DerivedStakingElected } from '../types';

import { Observable, combineLatest, of } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';

import { memo } from '../util';

export function electedInfo (api: ApiInterfaceRx): () => Observable<DerivedStakingElected> {
return memo((): Observable<DerivedStakingElected> =>
api.derive.staking.validators().pipe(
switchMap(({ currentElected }): Observable<[AccountId[], DerivedStaking[]]> =>
combineLatest([
of(currentElected),
combineLatest(currentElected.map((accountId): Observable<DerivedStaking> =>
api.derive.staking.info(accountId)
))
])
),
map(([currentElected, info]): DerivedStakingElected => ({
currentElected, info
}))
)
);
}
1 change: 1 addition & 0 deletions packages/api-derive/src/staking/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// of the Apache-2.0 license. See the LICENSE file for details.

export * from './controllers';
export * from './electedInfo';
export * from './info';
export * from './overview';
export * from './recentlyOffline';
Expand Down
5 changes: 5 additions & 0 deletions packages/api-derive/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ export type DerivedStakingAccount = [AccountId, DerivedStakingOnlineStatus];

export type DerivedStakingAccounts = DerivedStakingAccount[];

export interface DerivedStakingElected {
currentElected: AccountId[];
info: DerivedStaking[];
}

export interface DerivedStakingOnlineStatus {
online?: {
isOnline: boolean;
Expand Down