* Pass registry to all codec types
* Pass through registry inside API (where the rubber meets the road)
* Small additions
* Derive w/ registry
* Types are more-or-less covered
* Some test adjustments (guided by linting)
* Rid the world of some ../injector
* Additional cleanups, merge injector into registry
* Cleanup extrinsics (always passing registry)
* Remove injector imports (not all replaced)
* Typ spec cleanups
* Phase 1 - types seem lint-free
* rpc-{core,provider} lint free
* Start working through metadata
* Small metadata additions
* Some e2e tests (out-of-order)
* Down to a handful
* Fixup tests for packages/types/src/codec/*.spec.ts
* packages/types/src/codec passes all tests
* packages/types ok (Convert storage with registry fn)
* progress (sort out injection, dreaded find-before msg)
* Down to 1 lint issue...
* Linting done... along with on-demand import
* Exposed ordering
* Remove global injects
* Cleanup comments
* Add CHANGELOG & UPGRADING
* Apply suggestions from code review
Co-Authored-By: Amaury Martiny <amaury.martiny@protonmail.com>
* Update Metadata description
38 lines
1.6 KiB
TypeScript
38 lines
1.6 KiB
TypeScript
// 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 { EraPoints } from '@polkadot/types/interfaces';
|
|
import { ApiInterfaceRx } from '@polkadot/api/types';
|
|
import { DerivedStakingOverview } from '../types';
|
|
|
|
import { Observable, combineLatest, of } from 'rxjs';
|
|
import { map, switchMap } from 'rxjs/operators';
|
|
import { createType } from '@polkadot/types';
|
|
|
|
import { memo } from '../util';
|
|
|
|
/**
|
|
* @description Retrieve the staking overview, including elected and points earned
|
|
*/
|
|
export function overview (api: ApiInterfaceRx): () => Observable<DerivedStakingOverview> {
|
|
return memo((): Observable<DerivedStakingOverview> =>
|
|
combineLatest([
|
|
api.derive.session.indexes(),
|
|
api.derive.staking.validators()
|
|
]).pipe(
|
|
switchMap(([{ currentEra, currentIndex, validatorCount }, { currentElected, validators }]) =>
|
|
combineLatest([
|
|
of({ currentElected, currentEra, currentIndex, validators, validatorCount }),
|
|
// this will change on a per block basis, keep it innermost (and it needs eraIndex)
|
|
api.query.staking?.currentEraPointsEarned
|
|
? api.query.staking.currentEraPointsEarned<EraPoints>(currentEra)
|
|
: of(createType(api.registry, 'EraPoints'))
|
|
])
|
|
),
|
|
map(([{ currentElected, currentEra, currentIndex, validators, validatorCount }, eraPoints]): DerivedStakingOverview => ({
|
|
currentElected, currentEra, currentIndex, eraPoints, validators, validatorCount
|
|
}))
|
|
));
|
|
}
|