diff --git a/packages/page-referenda/src/Referenda/Referendum.tsx b/packages/page-referenda/src/Referenda/Referendum.tsx index b0d043f9b8..ff492fd778 100644 --- a/packages/page-referenda/src/Referenda/Referendum.tsx +++ b/packages/page-referenda/src/Referenda/Referendum.tsx @@ -302,25 +302,45 @@ function getChartProps (bestNumber: BN, blockInterval: BN, chartProps: ChartResu }); } -function extractInfo (info: PalletReferendaReferendumInfoConvictionVotingTally | PalletReferendaReferendumInfoRankedCollectiveTally): { enactAt: { at: boolean, blocks: BN } | null, nextAlarm: null | BN, submittedIn: null | BN } { - let enactAt: { at: boolean, blocks: BN } | null = null; +function extractInfo (info: PalletReferendaReferendumInfoConvictionVotingTally | PalletReferendaReferendumInfoRankedCollectiveTally, track?: PalletReferendaTrackInfo): { confirmEnd: BN | null, enactAt: { at: boolean, blocks: BN, end: BN | null } | null, nextAlarm: null | BN, submittedIn: null | BN } { + let confirmEnd: BN | null = null; + let enactAt: { at: boolean, blocks: BN, end: BN | null } | null = null; let nextAlarm: BN | null = null; let submittedIn: BN | null = null; if (info.isOngoing) { - const { alarm, enactment, submitted } = info.asOngoing; + const { alarm, deciding, enactment, submitted } = info.asOngoing; enactAt = { at: enactment.isAt, blocks: enactment.isAt ? enactment.asAt - : enactment.asAfter + : enactment.asAfter, + end: null }; nextAlarm = alarm.unwrapOr([null])[0]; submittedIn = submitted; + + if (deciding.isSome) { + const { confirming } = deciding.unwrap(); + + if (confirming.isSome) { + // we are confirming with the specific end block + confirmEnd = confirming.unwrap(); + + if (track) { + // add our track data + const fastEnd = confirmEnd.add(track.minEnactmentPeriod); + + enactAt.end = enactment.isAt + ? bnMax(fastEnd, enactment.asAt) + : fastEnd.add(enactment.asAfter); + } + } + } } - return { enactAt, nextAlarm, submittedIn }; + return { confirmEnd, enactAt, nextAlarm, submittedIn }; } function Referendum (props: Props): React.ReactElement { @@ -347,9 +367,9 @@ function Referendum (props: Props): React.ReactElement { [bestNumber, blockInterval, chartResult, id, isExpanded, t, track] ); - const { enactAt, nextAlarm, submittedIn } = useMemo( - () => extractInfo(info), - [info] + const { confirmEnd, enactAt, nextAlarm, submittedIn } = useMemo( + () => extractInfo(info, track), + [info, track] ); const chartLegend = useMemo( @@ -428,6 +448,18 @@ function Referendum (props: Props): React.ReactElement { )} + {confirmEnd && ( + <> +
{t('Confirm end')}
+ + + )} + {enactAt?.end && ( + <> +
{t('Enact end')}
+ + + )}