forked from Txio-labs/txio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsystemHealth.ts
More file actions
74 lines (69 loc) · 1.7 KB
/
Copy pathsystemHealth.ts
File metadata and controls
74 lines (69 loc) · 1.7 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
import {
ActivityLog,
RPCHealthMetric
} from '../types';
export type SystemHealthState = {
status:
| 'healthy'
| 'degraded'
| 'error'
| 'unknown';
label: string;
message: string;
toastType:
| 'success'
| 'info'
| 'error';
};
export const deriveSystemHealth = (
rpcHealth: Pick<RPCHealthMetric, 'status'> | null,
activityLogs: Pick<ActivityLog, 'type'>[]
): SystemHealthState => {
if (rpcHealth?.status === 'down') {
return {
status: 'error',
label: 'RPC Offline',
message:
'The active RPC endpoint is unavailable.',
toastType: 'error'
};
}
if (
activityLogs.some(
(log) => log.type === 'error'
)
) {
return {
status: 'error',
label: 'Recent Errors',
message:
'Recent errors detected. Open the terminal for details.',
toastType: 'error'
};
}
if (rpcHealth?.status === 'degraded') {
return {
status: 'degraded',
label: 'RPC Degraded',
message:
'The active RPC endpoint is responding slowly.',
toastType: 'info'
};
}
if (rpcHealth?.status === 'healthy') {
return {
status: 'healthy',
label: 'System Optimal',
message:
'System operational. No recent errors.',
toastType: 'success'
};
}
return {
status: 'unknown',
label: 'Checking System',
message:
'System health is still being checked.',
toastType: 'info'
};
};