More small readability enhancements (#1296)

* More small readability enhancements

* Pacify CC on manual checks
This commit is contained in:
Jaco Greeff
2019-08-11 22:44:02 +02:00
committed by GitHub
parent a12a776392
commit 5ee2caf00e
8 changed files with 91 additions and 87 deletions
@@ -26,7 +26,6 @@ import { HeaderAndValidators } from './subscribeNewHead';
*/
export function getHeader (api: ApiInterfaceRx): (hash: Uint8Array | string) => Observable<HeaderExtended | undefined> {
return (hash: Uint8Array | string): Observable<HeaderExtended | undefined> =>
// tslint:disable-next-line
(combineLatest([
api.rpc.chain.getHeader(hash),
api.query.session
@@ -40,7 +39,6 @@ export function getHeader (api: ApiInterfaceRx): (hash: Uint8Array | string) =>
// where rpc.chain.getHeader throws, we will land here - it can happen that
// we supplied an invalid hash. (Due to defaults, storeage will have an
// empty value, so only the RPC is affected). So return undefined
// tslint:disable-next-line
of() as Observable<undefined>
),
drr()
+14 -12
View File
@@ -12,6 +12,19 @@ import { ApiInterfaceRx } from '@polkadot/api/types';
import { DerivedElectionsInfo } from '../types';
import { drr } from '../util/drr';
function query (api: ApiInterfaceRx): Observable<[[AccountId, BlockNumber][], AccountId[], BN, BN, SetIndex, BlockNumber, VoteIndex, SetIndex]> {
return api.queryMulti([
api.query.elections.members,
api.query.elections.candidates,
api.query.elections.candidateCount,
api.query.elections.desiredSeats,
api.query.elections.nextVoterSet,
api.query.elections.termDuration,
api.query.elections.voteCount,
api.query.elections.voterCount
]) as any;
}
/**
* @name info
* @returns An object containing the combined results of the storage queries for
@@ -27,18 +40,7 @@ import { drr } from '../util/drr';
*/
export function info (api: ApiInterfaceRx): () => Observable<DerivedElectionsInfo> {
return (): Observable<DerivedElectionsInfo> => {
return (
api.queryMulti([
api.query.elections.members,
api.query.elections.candidates,
api.query.elections.candidateCount,
api.query.elections.desiredSeats,
api.query.elections.nextVoterSet,
api.query.elections.termDuration,
api.query.elections.voteCount,
api.query.elections.voterCount
]) as any as Observable<[[AccountId, BlockNumber][], AccountId[], BN, BN, SetIndex, BlockNumber, VoteIndex, SetIndex]>
).pipe(
return query(api).pipe(
map(([members, candidates, candidateCount, desiredSeats, nextVoterSet, termDuration, voteCount, voterCount]): DerivedElectionsInfo => ({
members: members.reduce(
(record: Record<string, BlockNumber>, [accountId, blockNumber]): Record<string, BlockNumber> => {