1import create from 'zustand';
2import { L2Point, PendingTransaction, Ownership } from '@urbit/roller-api';
4import { HOUR, isL2, isL2Spawn } from 'lib/utils/roller';
5import { increaseProxyNonce, setProxyNonce } from 'lib/utils/nonce';
6import { Invite } from 'lib/types/Invite';
8export interface RollerStore {
11 pendingTransactions: PendingTransaction[];
12 currentPoint: L2Point | null;
14 currentL2Spawn: boolean;
16 [point: number]: Ownership;
18 increaseNonce: (point: number, proxy: string) => void;
25 setNonces: (point: number, owner: Ownership) => void;
27 recentlyCompleted: number;
28 setNextBatchTime: (nextBatchTime: number) => void;
29 setNextRoll: (nextRoll: string) => void;
30 setPendingTransactions: (pendingTransactions: PendingTransaction[]) => void;
31 setCurrentPoint: (currentPoint: L2Point) => void;
32 setInvites: (invites: Invite[]) => void;
35export const useRollerStore = create<RollerStore>(set => ({
36 nextBatchTime: new Date().getTime() + HOUR,
37 nextRoll: '0h 00m 00s',
38 pendingTransactions: [],
41 currentL2Spawn: false,
45 increaseNonce: (point: number, proxy: string) =>
47 const owner = increaseProxyNonce(state.nonces[point], proxy);
48 console.log(point, proxy, owner);
49 if (!owner) throw new Error("Can't increase nonce for this proxy");
50 return { ...state, nonces: { ...state.nonces, [point]: owner } };
52 setNonce: (point: number, owner: Ownership, proxy: string, nonce: number) =>
54 const updatedOwner = setProxyNonce(owner, proxy, nonce);
55 if (!updatedOwner) throw new Error("Can't set nonce for this proxy");
58 nonces: { ...state.nonces, [point]: updatedOwner },
61 setNonces: (point: number, owner: Ownership) =>
63 return { ...state, nonces: { ...state.nonces, [point]: owner } };
65 setNextBatchTime: (nextBatchTime: number) => set(() => ({ nextBatchTime })),
66 setNextRoll: (nextRoll: string) => set(() => ({ nextRoll })),
67 setPendingTransactions: (pendingTransactions: PendingTransaction[]) =>
69 const oldPending = state.pendingTransactions.length;
70 if (oldPending > 0 && pendingTransactions.length === 0) {
74 recentlyCompleted: oldPending,
77 return { ...state, pendingTransactions };
79 setCurrentPoint: (currentPoint: L2Point) =>
82 currentL2: isL2(currentPoint?.dominion),
83 currentL2Spawn: isL2Spawn(currentPoint?.dominion),
85 setInvites: (invites: Invite[]) => set(() => ({ invites })),
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list