* Bump common (w/ rxjs 7) * Adjust * pre bump * Cleanup imports * Add missing switchMap * CHANGELOG * Remove duplicate imports * Bump common * Direct rxjs import
33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import type { Observable } from 'rxjs';
|
|
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
|
import type { DeriveSessionInfo } from '../types';
|
|
|
|
import { map } from 'rxjs';
|
|
|
|
import { memo } from '../util';
|
|
|
|
/**
|
|
* @description Retrieves all the session and era query and calculates specific values on it as the length of the session and eras
|
|
*/
|
|
export function info (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveSessionInfo> {
|
|
return memo(instanceId, (): Observable<DeriveSessionInfo> =>
|
|
api.derive.session.indexes().pipe(
|
|
map((indexes) => {
|
|
const sessionLength = api.consts?.babe?.epochDuration || api.registry.createType('u64', 1);
|
|
const sessionsPerEra = api.consts?.staking?.sessionsPerEra || api.registry.createType('SessionIndex', 1);
|
|
|
|
return {
|
|
...indexes,
|
|
eraLength: api.registry.createType('BlockNumber', sessionsPerEra.mul(sessionLength)),
|
|
isEpoch: !!api.query.babe,
|
|
sessionLength,
|
|
sessionsPerEra
|
|
};
|
|
})
|
|
)
|
|
);
|
|
}
|