1import create from 'zustand';
2import { PendingTransaction } from '@urbit/roller-api';
3import { toBN } from 'web3-utils';
6import { HOUR } from 'lib/utils/roller';
7import Point, { Points } from 'lib/types/Point';
8import { toL1Details } from 'lib/utils/point';
9import { PendingL1, PendingL1Txn } from 'lib/types/PendingL1Transaction';
11const getPointsAndList = (points: Points, point: Point) => ({
13 pointList: Object.values(points).sort((a, b) => a.value - b.value),
14 point: point.isDefault ? point : points[point.value],
17export const EMPTY_POINT = new Point({
19 details: toL1Details({}),
23export interface RollerStore {
25 nextQuotaTime: number;
26 pendingTransactions: PendingTransaction[];
30 pendingL1ByPoint: PendingL1;
32 recentlyCompleted: number;
34 setLoading: (loading: boolean) => void;
35 setModalText: (modalText: string) => void;
36 setNextQuotaTime: (nextQuotaTime: number) => void;
37 setPendingTransactions: (pendingTransactions: PendingTransaction[]) => void;
38 setPoint: (point: number) => void;
39 setPoints: (points: Points) => void;
40 updatePoint: (point: Point) => void;
41 storePendingL1Txn: (txn: PendingL1Txn) => void;
42 deletePendingL1Txn: (txn: PendingL1Txn) => void;
43 setEthBalance: (ethBalance: BN) => void;
46export const useRollerStore = create<RollerStore>(set => ({
48 nextQuotaTime: new Date().getTime() + 24 * HOUR,
49 pendingTransactions: [],
56 setLoading: (loading: boolean) => set(() => ({ loading })),
57 setNextQuotaTime: (nextQuotaTime: number) => set(() => ({ nextQuotaTime })),
58 setPendingTransactions: (pendingTransactions: PendingTransaction[]) =>
60 const oldPending = state.pendingTransactions.length;
61 if (oldPending > 0 && pendingTransactions.length === 0) {
65 recentlyCompleted: oldPending,
68 return { ...state, pendingTransactions };
70 setPoint: (point: number) =>
71 set(state => ({ point: state.points[point] || EMPTY_POINT })),
72 setPoints: (points: Points) =>
73 set(({ point }) => getPointsAndList(points, point)),
74 updatePoint: (newPoint: Point) =>
75 set(({ point, points }) => {
76 const newPoints: Points = Object.assign({}, points);
77 newPoints[newPoint.value] = newPoint;
78 return getPointsAndList(newPoints, point);
80 setModalText: (modalText?: string) => set(() => ({ modalText })),
81 storePendingL1Txn: (txn: PendingL1Txn) =>
82 set(({ pendingL1ByPoint }) => {
83 const newPending = Object.assign({}, pendingL1ByPoint);
84 newPending[txn.point] = [...(pendingL1ByPoint[txn.point] || []), txn];
85 return { pendingL1ByPoint: newPending };
87 deletePendingL1Txn: (txn: PendingL1Txn) =>
88 set(({ pendingL1ByPoint }) => {
89 const newPending = Object.assign({}, pendingL1ByPoint);
90 newPending[txn.point] =
91 pendingL1ByPoint[txn.point]?.filter(({ id }) => id !== txn.id) || [];
92 return { pendingL1ByPoint: newPending };
94 setEthBalance: (ethBalance: BN) => set(() => ({ ethBalance })),
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