Allow approvalsOf to take string as "who" input (#1434)

* Allow approvalsOf to take string as "who" input

* Re-add <SetIndex> (build fails)
This commit is contained in:
Jaco Greeff
2019-10-02 12:15:50 +02:00
committed by GitHub
parent afff880c20
commit 17a10fbffe
@@ -24,21 +24,20 @@ import { drr } from '../util/drr';
* ```
*/
export function approvalsOf (api: ApiInterfaceRx): (who: AccountId) => Observable<boolean[][]> {
return (who: AccountId): Observable<boolean[][]> =>
(api.query.elections.nextVoterSet<SetIndex>())
.pipe(
switchMap((nextVoterSet: SetIndex): Observable<Vec<ApprovalFlag>[]> =>
api.query.elections.approvalsOf.multi(
[...Array(nextVoterSet.toNumber() + 1).keys()].map((i): [string, number] => [
who.toString(), i]
)
) as any as Observable<Vec<ApprovalFlag>[]>
),
map((votes: Vec<ApprovalFlag>[]): boolean[][] =>
votes.map((flags: Vec<ApprovalFlag>): boolean[] =>
approvalFlagsToBools(flags)
return (who: AccountId | string): Observable<boolean[][]> =>
api.query.elections.nextVoterSet<SetIndex>().pipe(
switchMap((nextVoterSet: SetIndex): Observable<Vec<ApprovalFlag>[]> =>
api.query.elections.approvalsOf.multi(
[...Array(nextVoterSet.toNumber() + 1).keys()].map((i): [string, number] => [
who.toString(), i]
)
),
drr()
);
) as any as Observable<Vec<ApprovalFlag>[]>
),
map((votes: Vec<ApprovalFlag>[]): boolean[][] =>
votes.map((flags: Vec<ApprovalFlag>): boolean[] =>
approvalFlagsToBools(flags)
)
),
drr()
);
}