Files
api/packages/api-derive/src/staking/currentPoints.ts
T
Valentin Fernandez ed62d164ea Document available Api Derives (#6106)
* document derives from accounts to democracy

* Derive Documentation progress

* Derive Documentation progress

* tx and staking docs

* Staking docs progress

* more staking docs

* Staking module complete

* imonline, elections and progress in democracy

* Document missing derives

* lint
2025-02-27 10:56:34 -03:00

29 lines
943 B
TypeScript

// Copyright 2017-2025 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { PalletStakingEraRewardPoints } from '@polkadot/types/lookup';
import type { DeriveApi } from '../types.js';
import { switchMap } from 'rxjs';
import { memo } from '../util/index.js';
/**
* @name currentPoints
* @description Retrieve the staking overview, including elected and points earned.
* @example
* ```javascript
* const currentPoints = await api.derive.staking.currentPoints();
* console.log(currentPoints.toHuman());
* ```
*/
export function currentPoints (instanceId: string, api: DeriveApi): () => Observable<PalletStakingEraRewardPoints> {
return memo(instanceId, (): Observable<PalletStakingEraRewardPoints> =>
api.derive.session.indexes().pipe(
switchMap(({ activeEra }) =>
api.query.staking.erasRewardPoints(activeEra)
)
));
}