Adjust for zero-length combines (#2369)

This commit is contained in:
Jaco Greeff
2020-06-20 20:00:01 +02:00
committed by GitHub
parent 735f2b835e
commit 5b96d52fa6
12 changed files with 70 additions and 62 deletions
@@ -5,7 +5,7 @@
import { ApiInterfaceRx } from '@polkadot/api/types';
import { DeriveStakingElected } from '../types';
import { Observable, combineLatest } from 'rxjs';
import { Observable, combineLatest, of } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
import { memo } from '../util';
@@ -13,16 +13,20 @@ import { memo } from '../util';
export function electedInfo (api: ApiInterfaceRx): () => Observable<DeriveStakingElected> {
return memo((): Observable<DeriveStakingElected> =>
api.derive.staking.validators().pipe(
switchMap(({ nextElected }): Observable<DeriveStakingElected> =>
combineLatest(
switchMap(({ nextElected }): Observable<DeriveStakingElected> => {
if (!nextElected.length) {
return of({ info: [], nextElected: [] });
}
return combineLatest(
nextElected.map((accountId) => api.derive.staking.query(accountId))
).pipe(
map((info): DeriveStakingElected => ({
info,
nextElected
}))
)
)
);
})
)
);
}
@@ -5,7 +5,7 @@
import { ApiInterfaceRx } from '@polkadot/api/types';
import { DeriveStakingWaiting } from '../types';
import { Observable, combineLatest } from 'rxjs';
import { Observable, combineLatest, of } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
import { memo } from '../util';
@@ -20,6 +20,10 @@ export function waitingInfo (api: ApiInterfaceRx): () => Observable<DeriveStakin
const elected = nextElected.map((a) => a.toString());
const waiting = stashes.filter((v) => !elected.includes(v.toString()));
if (!waiting.length) {
return of({ info: [], waiting: [] });
}
return combineLatest(
waiting.map((accountId) => api.derive.staking.query(accountId))
).pipe(