Skip to content

Commit

Permalink
add referenda watch API
Browse files Browse the repository at this point in the history
  • Loading branch information
voliva committed Jan 20, 2025
1 parent eb02910 commit f98bd44
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion docs/pages/sdks/governance/referenda.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<OngoingReferendum> = 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<number, OngoingReferendum>` 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<number, OngoingReferendum>
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.
Expand Down

0 comments on commit f98bd44

Please sign in to comment.