Skip to content

Commit c2816f6

Browse files
fix: move epoch check to selected slot getter
1 parent 9ff98c6 commit c2816f6

File tree

1 file changed

+20
-17
lines changed
  • src/features/Overview/SlotPerformance

1 file changed

+20
-17
lines changed

src/features/Overview/SlotPerformance/atoms.ts

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,36 @@ import {
44
tilesAtom,
55
tileTimerAtom,
66
} from "../../../api/atoms";
7-
import type { TxnWaterfall } from "../../../api/types";
7+
import type { Epoch, TxnWaterfall } from "../../../api/types";
88
import { atomWithImmer } from "jotai-immer";
99
import { produce } from "immer";
1010
import { countBy } from "lodash";
1111
import { epochAtom, slotOverrideAtom } from "../../../atoms";
1212

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+
1320
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>();
2122

2223
return atom(
23-
(get) => get(_baseSelectedSlotAtom),
24-
(get, set, slot: number | undefined) => {
24+
(get) => {
2525
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 {
3128
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);
3437

3538
if (isValid && slot !== undefined) {
3639
// Scroll to selected slot if new selection is defined

0 commit comments

Comments
 (0)