ApiDerive.staking backwards compatibility. (#5868)

* Start of backwards compatibility for api.derive.staking

* Update nextElected to be compatible

* lint

* Comments

* remove clipped from query

* Ensure backwards compat for ownExposure

* Fix query
This commit is contained in:
Tarik Gul
2024-05-06 19:18:58 +03:00
committed by GitHub
parent e0e9829417
commit 15c8859b06
4 changed files with 49 additions and 17 deletions
@@ -11,6 +11,7 @@ import { memo } from '../util/index.js';
export function nextElected (instanceId: string, api: DeriveApi): () => Observable<AccountId[]> {
return memo(instanceId, (): Observable<AccountId[]> =>
// Compatibility for future generation changes in staking.
api.query.staking.erasStakersPaged
? api.derive.session.indexes().pipe(
// only populate for next era in the last session, so track both here - entries are not
@@ -18,7 +19,14 @@ export function nextElected (instanceId: string, api: DeriveApi): () => Observab
switchMap(({ currentEra }) => api.query.staking.erasStakersPaged.keys(currentEra)),
map((keys) => keys.map(({ args: [, accountId] }) => accountId))
)
: api.query.staking['currentElected']<AccountId[]>()
: api.query.staking.erasStakers
? api.derive.session.indexes().pipe(
// only populate for next era in the last session, so track both here - entries are not
// subscriptions, so we need a trigger - currentIndex acts as that trigger to refresh
switchMap(({ currentEra }) => api.query.staking.erasStakers.keys(currentEra)),
map((keys) => keys.map(({ args: [, accountId] }) => accountId))
)
: api.query.staking['currentElected']<AccountId[]>()
);
}