Remove combineLatest where multi is used (#895)

* Remove combineLatest where multi is used

* Add e2e test for derive.controllers
This commit is contained in:
Jaco Greeff
2019-06-12 16:45:45 +12:00
committed by Ian He
parent afcc7fb701
commit 1857d8d521
3 changed files with 26 additions and 16 deletions
+12 -8
View File
@@ -3,7 +3,7 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import BN from 'bn.js';
import { combineLatest, Observable, of } from 'rxjs';
import { Observable, of } from 'rxjs';
import { ApiInterface$Rx } from '@plugnet/api/types';
import { AccountId, Vote } from '@plugnet/types';
@@ -11,12 +11,16 @@ import { drr } from '../util/drr';
export function votes (api: ApiInterface$Rx) {
return (referendumId: BN, accountIds: Array<AccountId> = []): Observable<Array<Vote>> => {
return !accountIds || !accountIds.length
? of([]).pipe(drr())
: combineLatest(
api.query.democracy.voteOf.multi(accountIds.map(accountId => [referendumId, accountId])) as Observable<Vote>
).pipe(
drr()
);
return (
!accountIds || !accountIds.length
? of([])
: api.query.democracy.voteOf.multi(
accountIds.map(accountId =>
[referendumId, accountId]
)
) as any as Observable<Array<Vote>>
).pipe(
drr()
);
};
}
@@ -9,12 +9,6 @@ import { AccountId, Option } from '@plugnet/types';
import { drr } from '../util/drr';
function allBonds (api: ApiInterface$Rx, stashIds: Array<AccountId>) {
return combineLatest(
api.query.staking.bonded.multi(stashIds) as Observable<Option<AccountId>>
);
}
/**
* @description From the list of stash accounts, retrieve the list of controllers
*/
@@ -25,7 +19,7 @@ export function controllers (api: ApiInterface$Rx) {
switchMap(([stashIds]) =>
combineLatest([
of(stashIds),
allBonds(api, stashIds)
api.query.staking.bonded.multi(stashIds) as any as Observable<Array<Option<AccountId>>>
])
),
drr()