Repository navigation
Expand file tree
/
Copy pathActionsView.tsx
More file actions
59 lines (54 loc) · 1.9 KB
/
Copy pathActionsView.tsx
File metadata and controls
59 lines (54 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { useCallback, useEffect, useRef, useState } from "react";
import { PendingActionsView } from "./PendingActionsView";
import { ProposeActionPanel } from "./ProposeActionPanel";
import {
fetchTokenOpsGovernance,
type TokenOpsGovernance,
} from "../dash/governance";
import { errorMessage } from "../dash/logger";
import { useSession } from "../session/useSession";
export function ActionsView({ onComplete }: { onComplete?: () => void }) {
const session = useSession();
const [governance, setGovernance] = useState<TokenOpsGovernance | null>(null);
const [governanceError, setGovernanceError] = useState<string | null>(null);
const requestId = useRef(0);
const refreshGovernance = useCallback(async () => {
const currentRequestId = ++requestId.current;
if (!session.sdk || !session.contractId) {
setGovernance(null);
setGovernanceError(null);
return null;
}
setGovernanceError(null);
try {
const nextGovernance = await fetchTokenOpsGovernance({
sdk: session.sdk,
contractId: session.contractId,
});
if (currentRequestId === requestId.current) {
setGovernance(nextGovernance);
}
return nextGovernance;
} catch (err) {
if (currentRequestId === requestId.current) {
setGovernance(null);
setGovernanceError(errorMessage(err));
}
return null;
}
}, [session.contractId, session.sdk]);
useEffect(() => {
const timer = window.setTimeout(() => void refreshGovernance(), 0);
return () => window.clearTimeout(timer);
}, [refreshGovernance]);
return (
<div className="actions-screen">
{governanceError && <div className="notice error">{governanceError}</div>}
<ProposeActionPanel governance={governance} onComplete={onComplete} />
<PendingActionsView
governance={governance}
refreshGovernance={refreshGovernance}
/>
</div>
);
}