on bd2bfea help sign in
bridge/src/store/roller.ts
39 lines 1.4 kB history raw
1import create from 'zustand';
2import { L2Point, PendingTransaction } from '@urbit/roller-api/build';
4import { HOUR } from 'lib/utils/roller';
5import { Invite } from 'types/Invite';
7export interface RollerStore {
8 nextBatchTime: number;
9 nextRoll: string;
10 pendingTransactions: PendingTransaction[];
11 currentPoint: L2Point | null;
12 currentL2: boolean;
13 invites: Invite[];
14 setNextBatchTime: (nextBatchTime: number) => void;
15 setNextRoll: (nextRoll: string) => void;
16 setPendingTransactions: (pendingTransactions: PendingTransaction[]) => void;
17 setCurrentPoint: (currentPoint: L2Point) => void;
18 setInvites: (invites: Invite[]) => void;
21export const useRollerStore = create<RollerStore>(set => ({
22 nextBatchTime: new Date().getTime() + HOUR,
23 nextRoll: '0h 00m 00s',
24 pendingTransactions: [],
25 currentPoint: null,
26 currentL2: false,
27 invites: [],
28 setNextBatchTime: (nextBatchTime: number) => set(() => ({ nextBatchTime })),
29 setNextRoll: (nextRoll: string) => set(() => ({ nextRoll })),
30 setPendingTransactions: (pendingTransactions: PendingTransaction[]) =>
31 set(() => ({ pendingTransactions })),
32 setCurrentPoint: (currentPoint: L2Point) =>
33 set(() => ({
34 currentPoint,
35 currentL2:
36 currentPoint?.dominion === 'l2' || currentPoint?.dominion === 'spawn',
37 })),
38 setInvites: (invites: Invite[]) => set(() => ({ invites })),
39}));