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
+3 -3
View File
@@ -32,13 +32,13 @@
"@polkadot/rpc-core": "1.20.0-beta.4",
"@polkadot/rpc-provider": "1.20.0-beta.4",
"@polkadot/types": "1.20.0-beta.4",
"@polkadot/util": "^2.14.1",
"@polkadot/util-crypto": "^2.14.1",
"@polkadot/util": "^2.15.0-beta.0",
"@polkadot/util-crypto": "^2.15.0-beta.0",
"bn.js": "^5.1.2",
"memoizee": "^0.4.14",
"rxjs": "^6.5.5"
},
"devDependencies": {
"@polkadot/keyring": "^2.14.1"
"@polkadot/keyring": "^2.15.0-beta.0"
}
}
@@ -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(