Skip to content

Commit 930019f

Browse files
committed
Fixes some edge cases
1 parent 80a7b52 commit 930019f

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

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

+10-16
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,8 @@ const ElectionShow: FC = () => {
5353

5454
// called by a DKG row
5555
const notifyDKGState = (node: string, info: InternalDKGInfo) => {
56-
console.log('DKG node updated:', info);
5756
switch (info.getStatus()) {
5857
case NodeStatus.Failed:
59-
console.log('DKG node failed');
6058
setOngoingAction(OngoingAction.None);
6159
break;
6260
case NodeStatus.Setup:
@@ -68,7 +66,6 @@ const ElectionShow: FC = () => {
6866
const newDKGStatuses = new Map(DKGStatuses);
6967
newDKGStatuses.set(node, info.getStatus());
7068
setDKGStatuses(newDKGStatuses);
71-
console.log('dkg statuses:', DKGStatuses);
7269
};
7370

7471
// called by a DKG row
@@ -103,7 +100,6 @@ const ElectionShow: FC = () => {
103100
const storedOngoingAction = JSON.parse(window.localStorage.getItem(ongoingItem));
104101

105102
if (storedOngoingAction !== null) {
106-
console.log('stored ongoing action:', storedOngoingAction);
107103
setOngoingAction(storedOngoingAction);
108104
}
109105

@@ -152,10 +148,14 @@ const ElectionShow: FC = () => {
152148
// eslint-disable-next-line react-hooks/exhaustive-deps
153149
}, [roster]);
154150

151+
// Keep the "DKGLoading" state according to "nodeLoading". This state tells if
152+
// one of the element on the map is true.
155153
useEffect(() => {
156154
if (nodeLoading !== null) {
157155
if (!Array.from(nodeLoading.values()).includes(true)) {
158156
setDKGLoading(false);
157+
} else {
158+
setDKGLoading(true);
159159
}
160160
}
161161
// eslint-disable-next-line react-hooks/exhaustive-deps
@@ -166,24 +166,18 @@ const ElectionShow: FC = () => {
166166
if (status === Status.Initial) {
167167
if (DKGStatuses !== null && !DKGLoading) {
168168
const statuses = Array.from(DKGStatuses.values());
169+
setOngoingAction(OngoingAction.None);
169170

170171
// TODO: can be modified such that if the majority of the node are
171172
// initialized than the election status can still be set to initialized
172-
if (statuses.includes(NodeStatus.NotInitialized)) {
173-
setOngoingAction(OngoingAction.None);
174-
setStatus(Status.Initial);
173+
if (
174+
statuses.includes(NodeStatus.NotInitialized) ||
175+
statuses.includes(NodeStatus.Unreachable) ||
176+
statuses.includes(NodeStatus.Failed)
177+
) {
175178
return;
176179
}
177180

178-
if (statuses.includes(NodeStatus.Setup)) {
179-
setOngoingAction(OngoingAction.None);
180-
setStatus(Status.Setup);
181-
return;
182-
}
183-
184-
if (statuses.includes(NodeStatus.Unreachable)) return;
185-
if (statuses.includes(NodeStatus.Failed)) return;
186-
187181
setStatus(Status.Initialized);
188182

189183
// Status Failed is handled by useChangeAction

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,15 @@ const DKGStatusRow: FC<DKGStatusRowProps> = ({
101101
useEffect(() => {
102102
if (
103103
ongoingAction === OngoingAction.Initializing &&
104-
(status === NodeStatus.NotInitialized || status === NodeStatus.Failed)
104+
(status === NodeStatus.NotInitialized ||
105+
status === NodeStatus.Failed ||
106+
status === NodeStatus.Unreachable)
105107
) {
106108
setDKGLoading(true);
107109

108110
initializeNode()
109111
.then(() => {
112+
setInfo('');
110113
setStatus(NodeStatus.Initialized);
111114
})
112115
.catch((e: Error) => {

0 commit comments

Comments
 (0)