Filter old rewards with stakingLedger (ledger can update) (#2155)

* Filter old rewards with stakingLedger (ledger can update)

* Cleanup internal functions
This commit is contained in:
Jaco Greeff
2020-04-10 18:06:14 +02:00
committed by GitHub
parent 3089529405
commit e5d9bbc264
17 changed files with 169 additions and 203 deletions
@@ -11,11 +11,11 @@ import { map, switchMap } from 'rxjs/operators';
import { memo } from '../util';
export function stakerSlashesOver (api: ApiInterfaceRx): (accountId: Uint8Array | string, eras: EraIndex[]) => Observable<DeriveStakerSlashes[]> {
export function _stakerSlashes (api: ApiInterfaceRx): (accountId: Uint8Array | string, eras: EraIndex[]) => Observable<DeriveStakerSlashes[]> {
return memo((accountId: Uint8Array | string, eras: EraIndex[]): Observable<DeriveStakerSlashes[]> => {
const stakerId = api.registry.createType('AccountId', accountId).toString();
return api.derive.staking.erasSlashesOver(eras).pipe(
return api.derive.staking._erasSlashes(eras).pipe(
map((slashes): DeriveStakerSlashes[] =>
slashes.map(({ era, nominators, validators }): DeriveStakerSlashes => ({
era,
@@ -29,7 +29,7 @@ export function stakerSlashesOver (api: ApiInterfaceRx): (accountId: Uint8Array
export function stakerSlashes (api: ApiInterfaceRx): (accountId: Uint8Array | string, withActive?: boolean) => Observable<DeriveStakerSlashes[]> {
return memo((accountId: Uint8Array | string, withActive?: boolean): Observable<DeriveStakerSlashes[]> =>
api.derive.staking.erasHistoric(withActive).pipe(
switchMap((eras) => api.derive.staking.stakerSlashesOver(accountId, eras))
switchMap((eras) => api.derive.staking._stakerSlashes(accountId, eras))
)
);
}