@@ -4,33 +4,36 @@ import {
4
4
tilesAtom ,
5
5
tileTimerAtom ,
6
6
} from "../../../api/atoms" ;
7
- import type { TxnWaterfall } from "../../../api/types" ;
7
+ import type { Epoch , TxnWaterfall } from "../../../api/types" ;
8
8
import { atomWithImmer } from "jotai-immer" ;
9
9
import { produce } from "immer" ;
10
10
import { countBy } from "lodash" ;
11
11
import { epochAtom , slotOverrideAtom } from "../../../atoms" ;
12
12
13
+ function isSlotValid ( slot ?: number , epoch ?: Epoch ) {
14
+ return (
15
+ slot === undefined ||
16
+ Boolean ( epoch && epoch . start_slot <= slot && slot <= epoch . end_slot )
17
+ ) ;
18
+ }
19
+
13
20
export const baseSelectedSlotAtom = ( function ( ) {
14
- const _baseSelectedSlotAtom = atom < {
15
- slot : number | undefined ;
16
- isValid : boolean ;
17
- } > ( {
18
- slot : undefined ,
19
- isValid : true ,
20
- } ) ;
21
+ const _baseSelectedSlotAtom = atom < number > ( ) ;
21
22
22
23
return atom (
23
- ( get ) => get ( _baseSelectedSlotAtom ) ,
24
- ( get , set , slot : number | undefined ) => {
24
+ ( get ) => {
25
25
const epoch = get ( epochAtom ) ;
26
- const isValid =
27
- slot === undefined ||
28
- Boolean ( epoch && epoch . start_slot <= slot && slot <= epoch . end_slot ) ;
29
-
30
- set ( _baseSelectedSlotAtom , {
26
+ const slot = get ( _baseSelectedSlotAtom ) ;
27
+ return {
31
28
slot,
32
- isValid,
33
- } ) ;
29
+ isValid : isSlotValid ( slot , epoch ) ,
30
+ } ;
31
+ } ,
32
+ ( get , set , slot : number | undefined ) => {
33
+ set ( _baseSelectedSlotAtom , slot ) ;
34
+
35
+ const epoch = get ( epochAtom ) ;
36
+ const isValid = isSlotValid ( slot , epoch ) ;
34
37
35
38
if ( isValid && slot !== undefined ) {
36
39
// Scroll to selected slot if new selection is defined
0 commit comments