diff --git a/CHANGELOG.md b/CHANGELOG.md index 4632528fbc..d80a42d57a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ Changes: - Emit `decorated` event on API on metadata decoration - Dedupe and extend `WrapperKeepOpaque/WrapperOpaque` - Align `Range/RangeInclusive` usage with similar types +- Adjust bounty derive, return empty on no `{treasury, bounties}.bounties` - Update to latest Substrate, Kusama & Polkadot static metadata diff --git a/packages/api-derive/src/bounties/bounties.ts b/packages/api-derive/src/bounties/bounties.ts index 1a1b97ca8a..85914a922b 100644 --- a/packages/api-derive/src/bounties/bounties.ts +++ b/packages/api-derive/src/bounties/bounties.ts @@ -35,29 +35,31 @@ export function bounties (instanceId: string, api: DeriveApi): () => Observable< const bountyBase = api.query.bounties || api.query.treasury; return memo(instanceId, (): Observable => - combineLatest([ - bountyBase.bountyCount(), - api.query.council - ? api.query.council.proposalCount() - : of(0) - ]).pipe( - switchMap(() => combineLatest([ - bountyBase.bounties.keys(), - api.derive.council - ? api.derive.council.proposals() - : of([]) - ])), - switchMap(([keys, proposals]): Observable => { - const ids = keys.map(({ args: [id] }) => id); + bountyBase.bounties + ? combineLatest([ + bountyBase.bountyCount(), + api.query.council + ? api.query.council.proposalCount() + : of(0) + ]).pipe( + switchMap(() => combineLatest([ + bountyBase.bounties.keys(), + api.derive.council + ? api.derive.council.proposals() + : of([]) + ])), + switchMap(([keys, proposals]): Observable => { + const ids = keys.map(({ args: [id] }) => id); - return combineLatest([ - bountyBase.bounties.multi(ids), - bountyBase.bountyDescriptions.multi(ids), - of(ids), - of(filterBountiesProposals(api, proposals)) - ]); - }), - map(parseResult) - ) + return combineLatest([ + bountyBase.bounties.multi(ids), + bountyBase.bountyDescriptions.multi(ids), + of(ids), + of(filterBountiesProposals(api, proposals)) + ]); + }), + map(parseResult) + ) + : of(parseResult([[], [], [], []])) ); }