Additional derive cleanups (#4307)
* Additional derive cleanups * Adjust * Multi cache set * Adjust mapping
This commit is contained in:
@@ -1,18 +1,19 @@
|
||||
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { ApiInterfaceRx, ObsInnerType } from '@polkadot/api/types';
|
||||
import type { EraIndex } from '@polkadot/types/interfaces';
|
||||
import type { ExactDerive } from '../bundle';
|
||||
|
||||
import { switchMap } from 'rxjs';
|
||||
import { combineLatest, of, switchMap } from 'rxjs';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
type ApplyReturn<T extends keyof ExactDerive['staking']> = ReturnType<ExactDerive['staking'][T]>;
|
||||
|
||||
export function filterEras <T extends { era: EraIndex }> (eras: EraIndex[], list: T[]): EraIndex[] {
|
||||
return eras.filter((era) => !list.some((entry) => era.eq(entry.era)));
|
||||
return eras.filter((e) => !list.some(({ era }) => e.eq(era)));
|
||||
}
|
||||
|
||||
export function erasHistoricApply <F extends '_erasExposure' | '_erasPoints' | '_erasPrefs' | '_erasRewards' | '_erasSlashes'> (fn: F): (instanceId: string, api: ApiInterfaceRx) => (withActive?: boolean) => ApplyReturn<F> {
|
||||
@@ -36,3 +37,15 @@ export function erasHistoricApplyAccount <F extends '_ownExposures' | '_ownSlash
|
||||
)
|
||||
) as any;
|
||||
}
|
||||
|
||||
export function combineEras <F extends '_eraExposure' | '_eraPrefs' | '_eraSlashes'> (fn: F): (instanceId: string, api: ApiInterfaceRx) => (eras: EraIndex[], withActive: boolean) => Observable<ObsInnerType<ApplyReturn<F>>[]> {
|
||||
return (instanceId: string, api: ApiInterfaceRx) =>
|
||||
// Cannot quite get the typing right, but it is right in the code
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
memo(instanceId, (eras: EraIndex[], withActive: boolean) =>
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
eras.length
|
||||
? combineLatest(eras.map((e) => api.derive.staking[fn](e, withActive)))
|
||||
: of([])
|
||||
) as any;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user