27 lines
821 B
TypeScript
27 lines
821 B
TypeScript
// Copyright 2017-2022 @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
|
|
}))
|
|
));
|
|
}
|