@@ -34,47 +34,47 @@ function parse (api: DeriveApi, [hashes, proposals, votes]: Result): DeriveColle
3434 . filter ( ( proposal ) : proposal is DeriveCollectiveProposal => ! ! proposal ) ;
3535}
3636
37- function _proposalsFrom ( section : string , api : DeriveApi , hashes : ( Hash | Uint8Array | string ) [ ] ) : Observable < DeriveCollectiveProposal [ ] > {
38- return ( isFunction ( api . query [ section ] ?. proposals ) && hashes . length
37+ function _proposalsFrom ( api : DeriveApi , query : DeriveApi [ 'query' ] [ 'council' ] , hashes : ( Hash | Uint8Array | string ) [ ] ) : Observable < DeriveCollectiveProposal [ ] > {
38+ return ( isFunction ( query ?. proposals ) && hashes . length
3939 ? combineLatest ( [
4040 of ( hashes ) ,
4141 // this should simply be api.query[section].proposalOf.multi<Option<Proposal>>(hashes),
4242 // however we have had cases on Edgeware where the indices have moved around after an
4343 // upgrade, which results in invalid on-chain data
4444 combineLatest ( hashes . map ( ( h ) =>
45- api . query [ section ] . proposalOf < Option < Proposal > > ( h ) . pipe (
45+ query . proposalOf < Option < Proposal > > ( h ) . pipe (
4646 catchError ( ( ) => of ( null ) )
4747 )
4848 ) ) ,
49- api . query [ section ] . voting . multi < Option < Votes > > ( hashes )
49+ query . voting . multi < Option < Votes > > ( hashes )
5050 ] )
5151 : of < Result > ( [ [ ] , [ ] , [ ] ] )
5252 ) . pipe (
5353 map ( ( r ) => parse ( api , r ) )
5454 ) ;
5555}
5656
57- export function hasProposals ( _section : Collective ) : ( instanceId : string , api : DeriveApi ) => ( ) => Observable < boolean > {
58- return withSection ( _section , ( section , api ) =>
57+ export function hasProposals ( section : Collective ) : ( instanceId : string , api : DeriveApi ) => ( ) => Observable < boolean > {
58+ return withSection ( section , ( query ) =>
5959 ( ) : Observable < boolean > =>
60- of ( isFunction ( api . query [ section ] ?. proposals ) )
60+ of ( isFunction ( query ?. proposals ) )
6161 ) ;
6262}
6363
64- export function proposals ( _section : Collective ) : ( instanceId : string , api : DeriveApi ) => ( ) => Observable < DeriveCollectiveProposal [ ] > {
65- return withSection ( _section , ( section , api ) =>
64+ export function proposals ( section : Collective ) : ( instanceId : string , api : DeriveApi ) => ( ) => Observable < DeriveCollectiveProposal [ ] > {
65+ return withSection ( section , ( query , api ) =>
6666 ( ) : Observable < DeriveCollectiveProposal [ ] > =>
67- api . derive [ section as 'council' ] . proposalHashes ( ) . pipe (
68- switchMap ( ( all ) => _proposalsFrom ( section , api , all ) )
67+ api . derive [ section ] . proposalHashes ( ) . pipe (
68+ switchMap ( ( all ) => _proposalsFrom ( api , query , all ) )
6969 )
7070 ) ;
7171}
7272
73- export function proposal ( _section : Collective ) : ( instanceId : string , api : DeriveApi ) => ( hash : Hash | Uint8Array | string ) => Observable < DeriveCollectiveProposal | null > {
74- return withSection ( _section , ( section , api ) =>
73+ export function proposal ( section : Collective ) : ( instanceId : string , api : DeriveApi ) => ( hash : Hash | Uint8Array | string ) => Observable < DeriveCollectiveProposal | null > {
74+ return withSection ( section , ( query , api ) =>
7575 ( hash : Hash | Uint8Array | string ) : Observable < DeriveCollectiveProposal | null > =>
76- isFunction ( api . query [ section ] ?. proposals )
77- ? firstObservable ( _proposalsFrom ( section , api , [ hash ] ) )
76+ isFunction ( query ?. proposals )
77+ ? firstObservable ( _proposalsFrom ( api , query , [ hash ] ) )
7878 : of ( null )
7979 ) ;
8080}
0 commit comments