Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
IKeysCeremonyExecutionStatus as EStatus,
IKeysCeremonyTrusteeStatus as TStatus,
IExecutionStatus,
isKeysCeremonyTerminal,
} from "@/services/KeyCeremony"
import {Sequent_Backend_Election_Event, Sequent_Backend_Keys_Ceremony} from "@/gql/graphql"
import {Alert, CircularProgress} from "@mui/material"
Expand Down Expand Up @@ -74,21 +75,18 @@ export const TrusteeWizard: React.FC<TrusteeWizardProps> = ({
status.public_key !== undefined &&
currentCeremony.execution_status === EStatus.IN_PROGRESS &&
!status.trustees.find((trustee) => trustee.status === TStatus.WAITING)
const ceremonyTerminal = isKeysCeremonyTerminal(currentCeremony.execution_status as EStatus)

const calculateCurrentStep: () => WizardStep = () => {
if (ceremonyTerminal) {
return WizardStep.Status
}
// If trustee is not participating, show status step
if (!trusteeParticipating) {
return WizardStep.Status
// If trustee is participating but is not started, show status step
} else if (currentCeremony.execution_status === EStatus.USER_CONFIGURATION) {
return WizardStep.Status
// If trustee is participating but is not started, show status step
} else if (
currentCeremony.execution_status === EStatus.CANCELLED ||
currentCeremony.execution_status === EStatus.SUCCESS
) {
return WizardStep.Success
// if the trustee has not checked the key, then show the start screen
// If the trustee has not checked the key, then show the start screen
} else if (
currentCeremony.execution_status === EStatus.IN_PROGRESS &&
!trusteeCheckedKeys
Expand All @@ -102,14 +100,16 @@ export const TrusteeWizard: React.FC<TrusteeWizardProps> = ({
const [currentStep, setCurrentStep] = useState<WizardStep>(calculateCurrentStep())

useEffect(() => {
if (!trusteeCheckedKeys && trusteeParticipating && keysGenerated) {
if (ceremonyTerminal) {
setCurrentStep(WizardStep.Status)
} else if (!trusteeCheckedKeys && trusteeParticipating && keysGenerated) {
setCurrentStep(WizardStep.Start)
} else if (!keysGenerated) {
setCurrentStep(WizardStep.Not_Generated)
} else {
setCurrentStep(WizardStep.Status)
}
}, [trusteeCheckedKeys, trusteeParticipating, keysGenerated])
}, [ceremonyTerminal, trusteeCheckedKeys, trusteeParticipating, keysGenerated])

const checkKeysGenerated = () => {
return !trusteeCheckedKeys && trusteeParticipating && !keysGenerated
Expand Down
4 changes: 4 additions & 0 deletions packages/admin-portal/src/services/KeyCeremony.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export enum IKeysCeremonyTrusteeStatus {
KEY_CHECKED = "KEY_CHECKED",
}

export const isKeysCeremonyTerminal = (status: IKeysCeremonyExecutionStatus): boolean =>
status === IKeysCeremonyExecutionStatus.SUCCESS ||
status === IKeysCeremonyExecutionStatus.CANCELLED

export interface IKeysCeremonyTrustee {
name: string
status: IKeysCeremonyTrusteeStatus
Expand Down
18 changes: 18 additions & 0 deletions packages/admin-portal/src/services/keysCeremonyTerminal.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-FileCopyrightText: 2026 Sequent Tech Inc <legal@sequentech.io>
//
// SPDX-License-Identifier: AGPL-3.0-only

import {IKeysCeremonyExecutionStatus as EStatus, isKeysCeremonyTerminal} from "./KeyCeremony"

describe("isKeysCeremonyTerminal", () => {
it.each([EStatus.SUCCESS, EStatus.CANCELLED])("recognizes terminal status %s", (status) => {
expect(isKeysCeremonyTerminal(status)).toBe(true)
})

it.each([EStatus.USER_CONFIGURATION, EStatus.STARTED, EStatus.IN_PROGRESS])(
"rejects active status %s",
(status) => {
expect(isKeysCeremonyTerminal(status)).toBe(false)
}
)
})
Loading