Update api.derive to use api.queryMulti (#911)

* session api.queryMulti

* Make a single subscription to retrieve all session info

* Adjustments

* WIP

* Seems mostly comprehensive, need to full test e2e

* e2e tests for operations

* Allow "create from empty"

* skip

* Remove comment

* Remove ancient ?'s

* Update types.ts
This commit is contained in:
Jaco Greeff
2019-05-16 11:36:41 +02:00
committed by GitHub
parent bafda6dc93
commit 2dfc55cb5c
16 changed files with 237 additions and 132 deletions
@@ -45,20 +45,26 @@ export class ReferendumInfoExtended extends ReferendumInfo {
}
}
export function constructInfo (index: BN | number, optionInfo?: Option<ReferendumInfo>): Option<ReferendumInfoExtended> {
const info = optionInfo
? optionInfo.unwrapOr(null)
: null;
return new Option<ReferendumInfoExtended>(
ReferendumInfoExtended,
isNull(info)
? null
: new ReferendumInfoExtended(info, index)
);
}
export function referendumInfo (api: ApiInterface$Rx) {
return (index: BN | number): Observable<Option<ReferendumInfoExtended>> => {
return (api.query.democracy.referendumInfoOf(index) as Observable<Option<ReferendumInfo>>)
.pipe(
map((optionInfo) => {
const info = optionInfo.unwrapOr(null);
return new Option<ReferendumInfoExtended>(
ReferendumInfoExtended,
isNull(info)
? null
: new ReferendumInfoExtended(info, index)
);
}),
map((optionInfo) =>
constructInfo(index, optionInfo)
),
drr()
);
};