Skip to content

Commit cda589a

Browse files
committed
Moves the DKG logic to DKGStatusRow
1 parent 48a71a4 commit cda589a

File tree

8 files changed

+211
-170
lines changed

8 files changed

+211
-170
lines changed

web/frontend/src/mocks/handlers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export const handlers = [
6363
? {
6464
lastname: 'Bobster',
6565
firstname: 'Alice',
66-
role: UserRole.Voter,
66+
role: UserRole.Admin,
6767
sciper: userId,
6868
}
6969
: {};

web/frontend/src/pages/election/Show.tsx

+32-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Modal from 'components/modal/Modal';
99
import StatusTimeline from './components/StatusTimeline';
1010
import Loading from 'pages/Loading';
1111
import Action from './components/Action';
12-
import { NodeStatus } from 'types/node';
12+
import { InternalDKGInfo, NodeStatus } from 'types/node';
1313
import useGetResults from './components/utils/useGetResults';
1414
import UserIDTable from './components/UserIDTable';
1515
import DKGStatusTable from './components/DKGStatusTable';
@@ -42,7 +42,7 @@ const ElectionShow: FC = () => {
4242

4343
const [nodeProxyAddresses, setNodeProxyAddresses] = useState<Map<string, string>>(new Map());
4444
const [nodeToSetup, setNodeToSetup] = useState<[string, string]>(null);
45-
// The status of each node
45+
// The status of each node. Key is the node's address.
4646
const [DKGStatuses, setDKGStatuses] = useState<Map<string, NodeStatus>>(new Map());
4747

4848
const [nodeLoading, setNodeLoading] = useState<Map<string, boolean>>(null);
@@ -51,6 +51,25 @@ const ElectionShow: FC = () => {
5151
const ongoingItem = 'ongoingAction' + electionID;
5252
const nodeToSetupItem = 'nodeToSetup' + electionID;
5353

54+
const notifyDKGState = (node: string, info: InternalDKGInfo) => {
55+
console.log('DKG node updated:', info);
56+
switch (info.getStatus()) {
57+
case NodeStatus.Failed:
58+
console.log('DKG node failed');
59+
setOngoingAction(OngoingAction.None);
60+
break;
61+
case NodeStatus.Setup:
62+
setOngoingAction(OngoingAction.None);
63+
setStatus(Status.Setup);
64+
break;
65+
}
66+
67+
const newDKGStatuses = new Map(DKGStatuses);
68+
newDKGStatuses.set(node, info.getStatus());
69+
setDKGStatuses(newDKGStatuses);
70+
console.log('dkg statuses:', DKGStatuses);
71+
};
72+
5473
// Fetch result when available after a status change
5574
useEffect(() => {
5675
if (status === Status.ResultAvailable && isResultAvailable) {
@@ -76,6 +95,7 @@ const ElectionShow: FC = () => {
7695
const storedOngoingAction = JSON.parse(window.localStorage.getItem(ongoingItem));
7796

7897
if (storedOngoingAction !== null) {
98+
console.log('stored ongoing action:', storedOngoingAction);
7999
setOngoingAction(storedOngoingAction);
80100
}
81101

@@ -141,14 +161,20 @@ const ElectionShow: FC = () => {
141161

142162
// TODO: can be modified such that if the majority of the node are
143163
// initialized than the election status can still be set to initialized
144-
if (statuses.includes(NodeStatus.NotInitialized)) return;
164+
if (statuses.includes(NodeStatus.NotInitialized)) {
165+
setOngoingAction(OngoingAction.None);
166+
setStatus(Status.Initial);
167+
return;
168+
}
145169

146170
if (statuses.includes(NodeStatus.Setup)) {
171+
setOngoingAction(OngoingAction.None);
147172
setStatus(Status.Setup);
148173
return;
149174
}
150175

151176
if (statuses.includes(NodeStatus.Unreachable)) return;
177+
if (statuses.includes(NodeStatus.Failed)) return;
152178

153179
setStatus(Status.Initialized);
154180

@@ -220,8 +246,6 @@ const ElectionShow: FC = () => {
220246
setOngoingAction={setOngoingAction}
221247
nodeToSetup={nodeToSetup}
222248
setNodeToSetup={setNodeToSetup}
223-
DKGStatuses={DKGStatuses}
224-
setDKGStatuses={setDKGStatuses}
225249
/>
226250
)}
227251
</div>
@@ -248,6 +272,9 @@ const ElectionShow: FC = () => {
248272
setDKGStatuses={setDKGStatuses}
249273
setTextModalError={setTextModalError}
250274
setShowModalError={setShowModalError}
275+
ongoingAction={ongoingAction}
276+
notifyDKGState={notifyDKGState}
277+
nodeToSetup={nodeToSetup}
251278
/>
252279
</div>
253280
</div>

web/frontend/src/pages/election/components/Action.tsx

+1-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import PropTypes from 'prop-types';
33

44
import { ID } from 'types/configuration';
55
import { OngoingAction, Status } from 'types/election';
6-
import { NodeStatus } from 'types/node';
76
import useChangeAction from './utils/useChangeAction';
87

98
type ActionProps = {
@@ -19,8 +18,6 @@ type ActionProps = {
1918
setOngoingAction: (action: OngoingAction) => void;
2019
nodeToSetup: [string, string];
2120
setNodeToSetup: ([node, proxy]: [string, string]) => void;
22-
DKGStatuses: Map<string, NodeStatus>;
23-
setDKGStatuses: (dkgStatuses: Map<string, NodeStatus>) => void;
2421
};
2522

2623
const Action: FC<ActionProps> = ({
@@ -36,8 +33,6 @@ const Action: FC<ActionProps> = ({
3633
setOngoingAction,
3734
nodeToSetup,
3835
setNodeToSetup,
39-
DKGStatuses,
40-
setDKGStatuses,
4136
}) => {
4237
const { getAction, modalClose, modalCancel, modalDelete, modalSetup } = useChangeAction(
4338
status,
@@ -51,9 +46,7 @@ const Action: FC<ActionProps> = ({
5146
ongoingAction,
5247
setOngoingAction,
5348
nodeToSetup,
54-
setNodeToSetup,
55-
DKGStatuses,
56-
setDKGStatuses
49+
setNodeToSetup
5750
);
5851

5952
return (

web/frontend/src/pages/election/components/ChooseProxyModal.tsx

+1-5
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ import { Dialog, Transition } from '@headlessui/react';
22
import { CogIcon } from '@heroicons/react/outline';
33
import { FC, Fragment, useRef } from 'react';
44
import { useTranslation } from 'react-i18next';
5-
import { NodeStatus } from 'types/node';
65

76
type ChooseProxyModalProps = {
87
roster: string[];
98
showModal: boolean;
10-
DKGStatuses: Map<string, NodeStatus>;
119
nodeProxyAddresses: Map<string, string>;
1210
nodeToSetup: [string, string];
1311
setNodeToSetup: (node: [string, string]) => void;
@@ -18,7 +16,6 @@ type ChooseProxyModalProps = {
1816
const ChooseProxyModal: FC<ChooseProxyModalProps> = ({
1917
roster,
2018
showModal,
21-
DKGStatuses,
2219
nodeProxyAddresses,
2320
nodeToSetup,
2421
setNodeToSetup,
@@ -48,8 +45,7 @@ const ChooseProxyModal: FC<ChooseProxyModalProps> = ({
4845
nodeToSetup !== null &&
4946
roster.map((node, index) => {
5047
const proxy = nodeProxyAddresses.get(node);
51-
const status = DKGStatuses.get(node);
52-
const checkable = proxy !== '' && status === NodeStatus.Initialized;
48+
const checkable = proxy !== '';
5349

5450
return (
5551
<div className="flex items-center my-4 ml-4" key={node}>

0 commit comments

Comments
 (0)