This repository was archived by the owner on Apr 21, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathDLCList.tsx
More file actions
94 lines (83 loc) · 3.06 KB
/
Copy pathDLCList.tsx
File metadata and controls
94 lines (83 loc) · 3.06 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import { Collapsible } from "@kobalte/core";
import { Contract } from "@mutinywallet/mutiny-wasm";
import { createResource, For, Suspense } from "solid-js";
import { Button, InnerCard, VStack } from "~/components";
import { useMegaStore } from "~/state/megaStore";
type RefetchDLCsType = (
info?: unknown
) => Contract[] | Promise<Contract[] | undefined> | null | undefined;
function DLCItem(props: { dlc: Contract; refetch: RefetchDLCsType }) {
const [state, _] = useMegaStore();
const handleRejectDLC = async () => {
await state.mutiny_wallet?.reject_dlc_offer(props.dlc.id);
await props.refetch();
};
const handleAcceptDLC = async () => {
await state.mutiny_wallet?.accept_dlc_offer(props.dlc.id);
};
const handleCloseDLC = async () => {
const userInput = prompt("Enter oracle sigs:");
if (userInput != null) {
await state.mutiny_wallet?.close_dlc(
props.dlc.id,
userInput.trim()
);
}
};
return (
<Collapsible.Root>
<Collapsible.Trigger class="w-full">
<h2 class="truncate rounded bg-neutral-200 px-4 py-2 text-start font-mono text-lg text-black">
{">"} {props.dlc.id}
</h2>
</Collapsible.Trigger>
<Collapsible.Content>
<VStack>
<pre class="overflow-x-auto whitespace-pre-wrap break-all">
{JSON.stringify(props.dlc, null, 2)}
</pre>
<Button intent="green" layout="xs" onClick={handleCloseDLC}>
Close
</Button>
<Button
intent="green"
layout="xs"
onClick={handleAcceptDLC}
>
Accept
</Button>
<Button intent="red" layout="xs" onClick={handleRejectDLC}>
Reject
</Button>
</VStack>
</Collapsible.Content>
</Collapsible.Root>
);
}
export function DLCsList() {
const [state, _] = useMegaStore();
const getDLCs = async () => {
return (await state.mutiny_wallet?.list_dlcs()) as Promise<Contract[]>;
};
const [dlcs, { refetch }] = createResource(getDLCs);
return (
<>
<InnerCard title="DLCs">
{/* By wrapping this in a suspense I don't cause the page to jump to the top */}
<Suspense>
<VStack>
<For
each={dlcs.latest}
fallback={<code>No DLCs found.</code>}
>
{(dlc) => <DLCItem dlc={dlc} refetch={refetch} />}
</For>
</VStack>
</Suspense>
<Button layout="small" onClick={refetch}>
Refresh
</Button>
</InnerCard>
</>
);
}