* Prototype static init Enum/Set/Struct * Adjust (similar, logic extracted - further local testing) * Adjust with latest util (no prototype atm) * Introduce prototype assignment * Old Enum tests * Fix toCallsOnly spread * Adjust * Use objectSpread in derives (decorated objects only) * Adjust * Remove extra map from bag get * Additional spreads * Signer spread * Formatting * typo * Adjust spreads for session * Additional spread * Adjust spread * Formatting * CHANGELOG * Adjust * slice * CHANGELOG
30 lines
895 B
TypeScript
30 lines
895 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 { objectSpread } from '@polkadot/util';
|
|
|
|
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 =>
|
|
objectSpread({}, indexes, {
|
|
nextElected,
|
|
validators
|
|
})
|
|
)
|
|
));
|
|
}
|