Skip to content

Commit

Permalink
feat: add get referendum by id
Browse files Browse the repository at this point in the history
  • Loading branch information
voliva committed Jan 17, 2025
1 parent a2bd1a0 commit c6c9230
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/sdk-governance/src/referenda/referenda-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ export function createReferendaSdk(
})
.filter((v) => !!v)
}
async function getOngoingReferendum(id: number) {
const referendum =
await typedApi.query.Referenda.ReferendumInfoFor.getValue(id)
if (referendum?.type === "Ongoing") {
return enhanceOngoingReferendum(id, referendum.value)
}
return null
}

const [rawReferendumById$, referendaKeyChange$] = partitionEntries(
typedApi.query.Referenda.ReferendumInfoFor.watchEntries().pipe(
Expand Down Expand Up @@ -288,6 +296,7 @@ export function createReferendaSdk(
ongoingReferendaIds$,
},
getOngoingReferenda,
getOngoingReferendum,
getSpenderTrack,
getTrack,
createReferenda,
Expand Down
1 change: 1 addition & 0 deletions packages/sdk-governance/src/referenda/sdk-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export type ReferendaTrack = Omit<

export interface ReferendaSdk {
getOngoingReferenda(): Promise<OngoingReferendum[]>
getOngoingReferendum(id: number): Promise<OngoingReferendum | null>
watch: {
ongoingReferenda$: Observable<Map<number, OngoingReferendum>>
ongoingReferendaIds$: Observable<number[]>
Expand Down

0 comments on commit c6c9230

Please sign in to comment.