Small cleanups & consistency (#2151)
* Small cleanups & consistency * Fixes
This commit is contained in:
@@ -16,7 +16,7 @@ function retrievePointsPrev (api: ApiInterfaceRx, currentElected: AccountId[]):
|
||||
api.registry.createType('EraRewardPoints', {
|
||||
individual: new Map<AccountId, RewardPoint>(
|
||||
individual
|
||||
.map((points): RewardPoint => api.registry.createType('RewardPoint', points))
|
||||
.map((points) => api.registry.createType('RewardPoint', points))
|
||||
.map((points, index): [AccountId, RewardPoint] => [currentElected[index], points])
|
||||
),
|
||||
total
|
||||
|
||||
@@ -18,9 +18,7 @@ export function electedInfo (api: ApiInterfaceRx): () => Observable<DeriveStakin
|
||||
combineLatest([
|
||||
of(nextElected),
|
||||
combineLatest(
|
||||
nextElected.map((accountId): Observable<DeriveStakingQuery> =>
|
||||
api.derive.staking.query(accountId)
|
||||
)
|
||||
nextElected.map((accountId) => api.derive.staking.query(accountId))
|
||||
)
|
||||
])
|
||||
),
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { ActiveEraInfo, EraIndex } from '@polkadot/types/interfaces';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { Option, u32 } from '@polkadot/types';
|
||||
@@ -21,7 +22,7 @@ export function erasHistoric (api: ApiInterfaceRx): (withActive?: boolean) => Ob
|
||||
map(([activeEraOpt, historyDepth]): EraIndex[] => {
|
||||
const result: EraIndex[] = [];
|
||||
const max = historyDepth.toNumber();
|
||||
const activeEra = activeEraOpt.unwrapOrDefault().index.toBn();
|
||||
const activeEra: BN = activeEraOpt.unwrapOrDefault().index;
|
||||
let lastEra = activeEra;
|
||||
|
||||
while (lastEra.gten(0) && (result.length < max)) {
|
||||
|
||||
@@ -29,9 +29,7 @@ export function ownSlashes (api: ApiInterfaceRx): (accountId: Uint8Array | strin
|
||||
era,
|
||||
total: optVal.isSome
|
||||
? optVal.unwrap()[1]
|
||||
: optNom.isSome
|
||||
? optNom.unwrap()
|
||||
: api.registry.createType('Balance')
|
||||
: optNom.unwrapOrDefault()
|
||||
}))
|
||||
)
|
||||
);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { DeriveStakerExposure, DeriveEraExposureNominating, DeriveEraValidatorExposure } from '../types';
|
||||
import { DeriveStakerExposure, DeriveEraValidatorExposure } from '../types';
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
@@ -19,13 +19,11 @@ export function stakerExposure (api: ApiInterfaceRx): (accountId: Uint8Array | s
|
||||
exposures.map(({ era, nominators: allNominators, validators: allValidators }): DeriveStakerExposure => {
|
||||
const isValidator = !!allValidators[stakerId];
|
||||
const validators: DeriveEraValidatorExposure = {};
|
||||
let nominating: DeriveEraExposureNominating[] = [];
|
||||
const nominating = allNominators[stakerId] || [];
|
||||
|
||||
if (isValidator) {
|
||||
validators[stakerId] = allValidators[stakerId];
|
||||
} else if (allNominators[stakerId]) {
|
||||
nominating = allNominators[stakerId];
|
||||
|
||||
} else if (nominating) {
|
||||
nominating.forEach(({ validatorId }): void => {
|
||||
validators[validatorId] = allValidators[validatorId];
|
||||
});
|
||||
|
||||
@@ -19,9 +19,7 @@ export function stakerPoints (api: ApiInterfaceRx): (accountId: Uint8Array | str
|
||||
points.map(({ era, eraPoints, validators }): DeriveStakerPoints => ({
|
||||
era,
|
||||
eraPoints,
|
||||
points: validators[stakerId]
|
||||
? validators[stakerId]
|
||||
: api.registry.createType('RewardPoint')
|
||||
points: validators[stakerId] || api.registry.createType('RewardPoint')
|
||||
}))
|
||||
)
|
||||
);
|
||||
|
||||
@@ -8,7 +8,6 @@ import { DeriveStakingValidators } from '../types';
|
||||
|
||||
import { Observable, combineLatest, of } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { StorageKey } from '@polkadot/types';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
@@ -18,9 +17,7 @@ export function nextElected (api: ApiInterfaceRx): () => Observable<AccountId[]>
|
||||
? 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 }): Observable<StorageKey[]> =>
|
||||
api.query.staking.erasStakers.keys(currentEra)
|
||||
),
|
||||
switchMap(({ currentEra }) => api.query.staking.erasStakers.keys(currentEra)),
|
||||
map((keys): AccountId[] =>
|
||||
keys.map((key): AccountId => key.args[1] as AccountId)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user