-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathuseStepper.tsx
More file actions
87 lines (82 loc) · 2.73 KB
/
useStepper.tsx
File metadata and controls
87 lines (82 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import {
UseConfirmUpgradeType,
UseScheduleMeshSafeUpgradeType,
} from "plugins/lime-plugin-mesh-wide-upgrade/src/meshUpgradeQueries";
import {
MeshWideUpgradeInfo,
NodeMeshUpgradeInfo,
StepperState,
} from "plugins/lime-plugin-mesh-wide-upgrade/src/meshUpgradeTypes";
import { EupgradeStatus } from "plugins/lime-plugin-mesh-wide-upgrade/src/utils/eupgrade";
export const getStepperStatus = (
nodeInfo: MeshWideUpgradeInfo | undefined,
thisNode: NodeMeshUpgradeInfo | undefined,
thisNodeError: boolean,
newVersionAvailable: boolean,
downloadStatus: EupgradeStatus,
scheduleMeshSafeUpgradeStatus: UseScheduleMeshSafeUpgradeType | undefined,
confirmUpgradeStatus: UseConfirmUpgradeType | undefined,
someNodeAreDownloading: boolean,
isAborting: boolean
): StepperState => {
if (!nodeInfo || !thisNode) return "INITIAL";
if (isAborting) {
return "ABORTING";
}
if (downloadStatus === "download-failed") {
return "ERROR";
}
if (
thisNode.upgrade_state === "DEFAULT" ||
thisNode.upgrade_state === "ABORTED"
) {
if (newVersionAvailable) return "UPDATE_AVAILABLE";
return "NO_UPDATE";
}
if (thisNode.main_node === "STARTING") {
if (downloadStatus === "downloaded") {
return "DOWNLOADED_MAIN";
}
return "DOWNLOADING_MAIN";
}
if (
thisNode.upgrade_state === "READY_FOR_UPGRADE" ||
thisNode.upgrade_state === "DOWNLOADING" ||
thisNode.upgrade_state === "UPGRADE_SCHEDULED"
) {
// We suppose that if the upgrade is scheduled, and we lost the connection is because is upgrading
if (thisNode.upgrade_state === "UPGRADE_SCHEDULED" && thisNodeError) {
return "UPGRADING";
}
if (scheduleMeshSafeUpgradeStatus?.isLoading) {
return "SENDING_START_SCHEDULE";
}
if (
scheduleMeshSafeUpgradeStatus?.results?.length ||
scheduleMeshSafeUpgradeStatus?.errors?.length
) {
return "UPGRADE_SCHEDULED";
}
if (someNodeAreDownloading) {
return "NODES_DOWNLOADING";
}
// Here the user can send the schedule upgrade to the nodes
return "TRANSACTION_STARTED";
}
if (
thisNode.upgrade_state === "CONFIRMATION_PENDING" ||
thisNode.upgrade_state === "CONFIRMED"
) {
if (confirmUpgradeStatus?.isLoading) {
return "SENDING_CONFIRMATION";
}
if (confirmUpgradeStatus?.errors?.length) {
return "CONFIRMATION_PENDING";
}
return thisNode.upgrade_state;
}
if (thisNode.upgrade_state === "ERROR") {
return "ERROR";
}
return "INITIAL";
};