Skip to content
This repository was archived by the owner on Apr 21, 2025. It is now read-only.

Commit a2e0ed5

Browse files
committed
dlcs
1 parent 3629627 commit a2e0ed5

File tree

6 files changed

+389
-0
lines changed

6 files changed

+389
-0
lines changed

src/components/DLCList.tsx

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import { Collapsible } from "@kobalte/core";
2+
import { Contract } from "@mutinywallet/mutiny-wasm";
3+
import { createResource, For, Suspense } from "solid-js";
4+
5+
import { Button, InnerCard, VStack } from "~/components";
6+
import { useMegaStore } from "~/state/megaStore";
7+
8+
type RefetchDLCsType = (
9+
info?: unknown
10+
) => Contract[] | Promise<Contract[] | undefined> | null | undefined;
11+
12+
function DLCItem(props: { dlc: Contract; refetch: RefetchDLCsType }) {
13+
const [state, _] = useMegaStore();
14+
15+
const handleRejectDLC = async () => {
16+
await state.mutiny_wallet?.reject_dlc_offer(props.dlc.id);
17+
await props.refetch();
18+
};
19+
20+
const handleAcceptDLC = async () => {
21+
await state.mutiny_wallet?.accept_dlc_offer(props.dlc.id);
22+
};
23+
24+
const handleCloseDLC = async () => {
25+
const userInput = prompt("Enter oracle sigs:");
26+
if (userInput != null) {
27+
await state.mutiny_wallet?.close_dlc(
28+
props.dlc.id,
29+
userInput.trim()
30+
);
31+
}
32+
};
33+
34+
return (
35+
<Collapsible.Root>
36+
<Collapsible.Trigger class="w-full">
37+
<h2 class="truncate rounded bg-neutral-200 px-4 py-2 text-start font-mono text-lg text-black">
38+
{">"} {props.dlc.id}
39+
</h2>
40+
</Collapsible.Trigger>
41+
<Collapsible.Content>
42+
<VStack>
43+
<pre class="overflow-x-auto whitespace-pre-wrap break-all">
44+
{JSON.stringify(props.dlc, null, 2)}
45+
</pre>
46+
<Button intent="green" layout="xs" onClick={handleCloseDLC}>
47+
Close
48+
</Button>
49+
<Button
50+
intent="green"
51+
layout="xs"
52+
onClick={handleAcceptDLC}
53+
>
54+
Accept
55+
</Button>
56+
<Button intent="red" layout="xs" onClick={handleRejectDLC}>
57+
Reject
58+
</Button>
59+
</VStack>
60+
</Collapsible.Content>
61+
</Collapsible.Root>
62+
);
63+
}
64+
65+
export function DLCsList() {
66+
const [state, _] = useMegaStore();
67+
68+
const getDLCs = async () => {
69+
return (await state.mutiny_wallet?.list_dlcs()) as Promise<Contract[]>;
70+
};
71+
72+
const [peers, { refetch }] = createResource(getDLCs);
73+
74+
return (
75+
<>
76+
<InnerCard title="DLCs">
77+
{/* By wrapping this in a suspense I don't cause the page to jump to the top */}
78+
<Suspense>
79+
<VStack>
80+
<For
81+
each={peers.latest}
82+
fallback={<code>No DLCs found.</code>}
83+
>
84+
{(dlc) => <DLCItem dlc={dlc} refetch={refetch} />}
85+
</For>
86+
</VStack>
87+
</Suspense>
88+
<Button layout="small" onClick={refetch}>
89+
Refresh
90+
</Button>
91+
</InnerCard>
92+
</>
93+
);
94+
}

src/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export * from "./ContactForm";
1515
export * from "./ContactViewer";
1616
export * from "./DecryptDialog";
1717
export * from "./DeleteEverything";
18+
export * from "./DLCList";
1819
export * from "./ErrorDisplay";
1920
export * from "./Fee";
2021
export * from "./I18nProvider";

src/router.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
Channels,
2424
Connections,
2525
Currency,
26+
DLC,
2627
EmergencyKit,
2728
Encrypt,
2829
Gift,
@@ -109,6 +110,7 @@ export function Router() {
109110
<Route path="/channels" component={Channels} />
110111
<Route path="/connections" component={Connections} />
111112
<Route path="/currency" component={Currency} />
113+
<Route path="/dlc" component={DLC} />
112114
<Route path="/emergencykit" component={EmergencyKit} />
113115
<Route path="/encrypt" component={Encrypt} />
114116
<Route path="/gift" component={Gift} />

0 commit comments

Comments
 (0)