Remove combineLatest where multi is used (#895)
* Remove combineLatest where multi is used * Add e2e test for derive.controllers
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user