1
1
import { CommitmentStatus , SlotContent } from "../store/websocketStore.ts" ;
2
2
3
- export type CustomRow = {
3
+ export type ExtendedCommitmentStatus = CommitmentStatus | "next-leader" | "scheduled" ;
4
+ type ExtendedSlotContent = Omit < SlotContent , "commitment" > & {
5
+ commitment : ExtendedCommitmentStatus ;
6
+ } ;
7
+
8
+ export type CustomRowBasic = {
4
9
id : string ;
5
10
leader : string ;
6
11
slots : {
7
- commitment : CommitmentStatus ;
12
+ commitment : ExtendedCommitmentStatus ;
8
13
slot : number ;
9
14
} [ ] ;
10
15
transactions : {
@@ -22,15 +27,18 @@ export type CustomRow = {
22
27
fee1 : number [ ] ;
23
28
fee2 : number [ ] ;
24
29
} ;
30
+ export type CustomRow = Omit < CustomRowBasic , "slots" > & {
31
+ slots : { slot : number ; commitment : ExtendedCommitmentStatus } [ ] ;
32
+ } ;
25
33
type FxType = ( arg : [ id : string , slots : SlotContent [ ] ] ) => CustomRow ;
26
34
27
- const getFakeSlot = ( leader : string , newSlotId : number ) : SlotContent => ( {
35
+ export const getFakeSlot = ( leader : string , newSlotId : number ) : ExtendedSlotContent => ( {
28
36
leader,
29
37
slot : newSlotId ,
30
38
totalTransactionsFiltered : 0 ,
31
39
feeLevels : [ 0 , 0 , 0 ] ,
32
40
feeAverage : 0 ,
33
- commitment : "fake" as "confirmed ",
41
+ commitment : "scheduled " ,
34
42
totalUnitsConsumed : 0 ,
35
43
totalFee : 0 ,
36
44
hash : "" ,
@@ -40,7 +48,7 @@ const getFakeSlot = (leader: string, newSlotId: number): SlotContent => ({
40
48
time : 0 ,
41
49
} ) ;
42
50
43
- function fillGaps ( list : SlotContent [ ] ) : SlotContent [ ] {
51
+ function fillGaps ( list : SlotContent [ ] ) : ExtendedSlotContent [ ] {
44
52
if ( ! list . length ) return list ;
45
53
if ( list . length === 4 ) return list ;
46
54
const groupIdx = ( ( list ?. [ 0 ] ?. slot || 0 ) / 4 ) | 0 ;
@@ -51,7 +59,7 @@ function fillGaps(list: SlotContent[]): SlotContent[] {
51
59
const isFourth = list . find ( ( elt ) => ( elt . slot / 4 ) % 1 === 0.75 ) ;
52
60
53
61
const newLeader = list ?. [ 0 ] ?. leader || "UNKNOWN" ;
54
- const newList : typeof list = [ ] ;
62
+ const newList : ExtendedSlotContent [ ] = [ ] ;
55
63
isFirst ? newList . push ( { ...isFirst } ) : newList . push ( getFakeSlot ( newLeader , groupIdx * 4 ) ) ;
56
64
isSecond ? newList . push ( { ...isSecond } ) : newList . push ( getFakeSlot ( newLeader , groupIdx * 4 + 1 ) ) ;
57
65
isThird ? newList . push ( { ...isThird } ) : newList . push ( getFakeSlot ( newLeader , groupIdx * 4 + 2 ) ) ;
@@ -66,6 +74,13 @@ function fillGaps(list: SlotContent[]): SlotContent[] {
66
74
export const prepareValidatorRow : FxType = ( [ id , rawSlots ] ) => {
67
75
const slots = fillGaps ( rawSlots ) ;
68
76
const leader = slots [ 0 ] ?. leader || "UNKNOWN" ;
77
+ return prepareSingeRow ( id , leader , slots ) ;
78
+ } ;
79
+ export function prepareSingeRow (
80
+ id : string ,
81
+ leader : string ,
82
+ slots : ExtendedSlotContent [ ]
83
+ ) : CustomRow {
69
84
return {
70
85
id,
71
86
leader,
@@ -97,4 +112,4 @@ export const prepareValidatorRow: FxType = ([id, rawSlots]) => {
97
112
fee1 : slots . map ( ( elt ) => elt . feeLevels [ 1 ] || 0 ) ,
98
113
fee2 : slots . map ( ( elt ) => elt . feeLevels [ 2 ] || 0 ) ,
99
114
} ;
100
- } ;
115
+ }
0 commit comments