From f98bd449d50db950bb40f9ed43a26cbb9bbf17e7 Mon Sep 17 00:00:00 2001 From: Victor Oliva Date: Mon, 20 Jan 2025 10:00:21 +0100 Subject: [PATCH] add referenda watch API --- docs/pages/sdks/governance/referenda.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/pages/sdks/governance/referenda.md b/docs/pages/sdks/governance/referenda.md index 4595fd8b..9aaf3d62 100644 --- a/docs/pages/sdks/governance/referenda.md +++ b/docs/pages/sdks/governance/referenda.md @@ -99,10 +99,25 @@ When creating a referendum, if the call is short it can be inlined directly in t ## Fetching Ongoing Referenda -Closed referenda are mostly removed from the chain. The Referenda SDK lists ongoing referenda based from on-chain data: +Closed referenda are mostly removed from the chain. The Referenda SDK lists ongoing referenda based from on-chain data, or can fetch one specific by index: ```ts const referenda: Array = await referendaSdk.getOngoingReferenda(); + +const referendum: OngoingReferendum | null = await referendaSdk.getOngoingReferendum(15); +``` + +You can also subscribe to changes using the watch API. This provides two ways of working with it: `ongoingReferenda$` returns a `Map` with all referenda, and there are also `ongoingReferendaIds$` and `getOngoingReferendumById$(id: number)` for cases where you want to show the list and detail separately. + +```ts +// Map +referendaSdk.watch.ongoingReferenda$.subscribe(console.log); + +// number[] +referendaSdk.watch.ongoingReferendaIds$.subscribe(console.log); + +// Bounty +referendaSdk.watch.getOngoingReferendumById$(5).subscribe(console.log); ``` `OngoingReferendum` provides helpful methods to interact with proposals.