Files
api/packages/api-derive/src/staking/overview.ts
T
Jaco 4913cf65fd Move api-derive to correct location (#4343)
* Move api-derive to correct location

* Adjust (linting ok)

* No composite

* ApiDerive split

* Adjust

* Still WIP, getting closer

* It lints

* derive build issues sorted

* It builds :)

* Add system_health to mock

* api-augment usage

* Cleanups

* Adjust paths

* linting

* Some <'s

* Revert <>'s

* linting

* ordering

* Augmentation tweaks

* yarn.lock

* export
2021-12-18 09:18:55 +02:00

27 lines
821 B
TypeScript

// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { DeriveApi, DeriveStakingOverview } from '../types';
import { combineLatest, map } from 'rxjs';
import { memo } from '../util';
/**
* @description Retrieve the staking overview, including elected and points earned
*/
export function overview (instanceId: string, api: DeriveApi): () => Observable<DeriveStakingOverview> {
return memo(instanceId, (): Observable<DeriveStakingOverview> =>
combineLatest([
api.derive.session.indexes(),
api.derive.staking.validators()
]).pipe(
map(([indexes, { nextElected, validators }]): DeriveStakingOverview => ({
...indexes,
nextElected,
validators
}))
));
}