Make api.const.*.* typed (#1584)
* Make api.const.*.* typed * Fix tsc errors * Remove ConstantCodec * as any as * Remove as any
This commit is contained in:
@@ -19,9 +19,9 @@ function queryV2 (api: ApiInterfaceRx): Observable<Result> {
|
||||
return of([
|
||||
// get values from api.const for substrate versions post spec_version: 101
|
||||
// https://github.com/paritytech/substrate/pull/2883/files#diff-5e5e1c3aec9ddfde0a9054d062ab3db9R131
|
||||
api.consts.balances.creationFee as Balance,
|
||||
api.consts.balances.existentialDeposit as Balance,
|
||||
api.consts.balances.transferFee as Balance,
|
||||
api.consts.balances.creationFee,
|
||||
api.consts.balances.existentialDeposit,
|
||||
api.consts.balances.transferFee,
|
||||
paymentBase.transactionBaseFee as Balance,
|
||||
paymentBase.transactionByteFee as Balance
|
||||
]);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import { AccountId, SetIndex } from '@polkadot/types/interfaces';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { Vec, Option, createType } from '@polkadot/types';
|
||||
import { Vec, Option, createType, u32 } from '@polkadot/types';
|
||||
import { DerivedVoterPositions } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
@@ -15,11 +15,11 @@ import { memo } from '../util';
|
||||
|
||||
function queryElections (api: ApiInterfaceRx): Observable<DerivedVoterPositions> {
|
||||
return api.query.elections.nextVoterSet<SetIndex>().pipe(
|
||||
switchMap((nextVoterSet: SetIndex): Observable<[BN, Vec<Option<AccountId>>[]]> => combineLatest(
|
||||
of(api.consts.elections.voterSetSize) as any as Observable<BN>,
|
||||
api.query.elections.voters.multi([...Array(+nextVoterSet + 1).keys()].map((_, i): [number] => [i])) as any as Observable<Vec<Option<AccountId>>[]>
|
||||
switchMap((nextVoterSet: SetIndex): Observable<[u32, Vec<Option<AccountId>>[]]> => combineLatest(
|
||||
of(api.consts.elections.voterSetSize),
|
||||
api.query.elections.voters.multi<Vec<Option<AccountId>>>([...Array(+nextVoterSet + 1).keys()].map((_, i): [number] => [i]))
|
||||
)),
|
||||
map((result: [BN, Vec<Option<AccountId>>[]]): DerivedVoterPositions => {
|
||||
map((result: [u32, Vec<Option<AccountId>>[]]): DerivedVoterPositions => {
|
||||
const [setSize, voters] = result;
|
||||
|
||||
return voters.reduce((result: DerivedVoterPositions, vec, setIndex): DerivedVoterPositions => {
|
||||
|
||||
@@ -87,7 +87,7 @@ function infoLatestAura (api: ApiInterfaceRx): Observable<DerivedSessionInfo> {
|
||||
return api.derive.session.indexes().pipe(
|
||||
map((indexes): DerivedSessionInfo =>
|
||||
createDerivedLatest([
|
||||
[false, createType('u64', 1), api.consts.staking.sessionsPerEra as SessionIndex],
|
||||
[false, createType('u64', 1), api.consts.staking.sessionsPerEra],
|
||||
indexes,
|
||||
[createType('u64', 1), createType('u64', 1), createType('u64', 1), createType('SessionIndex', 1)]
|
||||
])
|
||||
@@ -107,7 +107,7 @@ function infoLatestBabe (api: ApiInterfaceRx): Observable<DerivedSessionInfo> {
|
||||
]).pipe(
|
||||
map(([indexes, slots]: [DeriveSessionIndexes, ResultSlots]): DerivedSessionInfo =>
|
||||
createDerivedLatest([
|
||||
[true, api.consts.babe.epochDuration as u64, api.consts.staking.sessionsPerEra as SessionIndex],
|
||||
[true, api.consts.babe.epochDuration, api.consts.staking.sessionsPerEra],
|
||||
indexes,
|
||||
slots
|
||||
])
|
||||
|
||||
Reference in New Issue
Block a user