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

Commit e13275f

Browse files
committed
dlcs
1 parent 43faf46 commit e13275f

File tree

6 files changed

+216
-0
lines changed

6 files changed

+216
-0
lines changed

src/components/DLCList.tsx

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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(props.dlc.id, userInput.trim());
28+
}
29+
};
30+
31+
return (
32+
<Collapsible.Root>
33+
<Collapsible.Trigger class="w-full">
34+
<h2 class="truncate rounded bg-neutral-200 px-4 py-2 text-start font-mono text-lg text-black">
35+
{">"} {props.dlc.id}
36+
</h2>
37+
</Collapsible.Trigger>
38+
<Collapsible.Content>
39+
<VStack>
40+
<pre class="overflow-x-auto whitespace-pre-wrap break-all">
41+
{JSON.stringify(props.dlc, null, 2)}
42+
</pre>
43+
<Button
44+
intent="green"
45+
layout="xs"
46+
onClick={handleCloseDLC}
47+
>
48+
Close
49+
</Button>
50+
<Button
51+
intent="green"
52+
layout="xs"
53+
onClick={handleAcceptDLC}
54+
>
55+
Accept
56+
</Button>
57+
<Button intent="red" layout="xs" onClick={handleRejectDLC}>
58+
Reject
59+
</Button>
60+
</VStack>
61+
</Collapsible.Content>
62+
</Collapsible.Root>
63+
);
64+
}
65+
66+
export function DLCsList() {
67+
const [state, _] = useMegaStore();
68+
69+
const getDLCs = async () => {
70+
return (await state.mutiny_wallet?.list_dlcs()) as Promise<Contract[]>;
71+
};
72+
73+
const [peers, {refetch}] = createResource(getDLCs);
74+
75+
return (
76+
<>
77+
<InnerCard title="DLCs">
78+
{/* By wrapping this in a suspense I don't cause the page to jump to the top */}
79+
<Suspense>
80+
<VStack>
81+
<For
82+
each={peers.latest}
83+
fallback={<code>No DLCs found.</code>}
84+
>
85+
{(dlc) => <DLCItem dlc={dlc} refetch={refetch}/>}
86+
</For>
87+
</VStack>
88+
</Suspense>
89+
<Button layout="small" onClick={refetch}>
90+
Refresh
91+
</Button>
92+
</InnerCard>
93+
</>
94+
);
95+
}

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} />

src/routes/settings/DLC.tsx

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import { TextField } from "@kobalte/core";
2+
import { createSignal } from "solid-js";
3+
4+
import {
5+
BackLink,
6+
Button,
7+
DefaultMain,
8+
DLCsList,
9+
InnerCard,
10+
LargeHeader,
11+
MutinyWalletGuard,
12+
NavBar,
13+
SafeArea
14+
} from "~/components";
15+
import { useI18n } from "~/i18n/context";
16+
import { useMegaStore } from "~/state/megaStore";
17+
18+
export function DLC() {
19+
const i18n = useI18n();
20+
const [state, _] = useMegaStore();
21+
22+
const [pubkey, setPubkey] = createSignal("");
23+
const [oracleAnn, setOracleAnn] = createSignal("");
24+
25+
const onSubmit = async (e: SubmitEvent) => {
26+
e.preventDefault();
27+
28+
const pk = pubkey().trim();
29+
const oracle = oracleAnn().trim();
30+
31+
const size = 10000;
32+
const outcomePayouts = [
33+
{
34+
outcome: "a",
35+
payout: {
36+
offer: size * 2,
37+
accept: 0
38+
}
39+
},
40+
{
41+
outcome: "b",
42+
payout: {
43+
offer: 0,
44+
accept: size * 2
45+
}
46+
}
47+
];
48+
49+
const id = await state.mutiny_wallet?.test_send_dlc_offer(
50+
BigInt(size),
51+
{ outcomePayouts },
52+
oracle,
53+
pk
54+
);
55+
56+
// attestation
57+
// ac5c1962f85ae0e6479da7ca5ce6dea1452c96dd7b4d6f26f45d7a2376a96421000105a47373c364053e8e2369fcfcfb7d7e08d6cae6e64a350bddb876cafb1760891ad9e74453873e04bce964cd810f20401d36725d69693a88703d3d47ff5a3c27000201610162
58+
59+
console.log("DLC contract id: " + id || "none");
60+
};
61+
62+
return (
63+
<MutinyWalletGuard>
64+
<SafeArea>
65+
<DefaultMain>
66+
<BackLink
67+
href="/settings"
68+
title={i18n.t("settings.header")}
69+
/>
70+
<LargeHeader>DLC Testing</LargeHeader>
71+
<InnerCard>
72+
<LargeHeader>
73+
My DLC Key: {state.mutiny_wallet?.get_dlc_key()}
74+
</LargeHeader>
75+
<form class="flex flex-col gap-4" onSubmit={onSubmit}>
76+
<TextField.Root
77+
value={pubkey()}
78+
onChange={setPubkey}
79+
class="flex flex-col gap-4"
80+
>
81+
<TextField.Label class="text-sm font-semibold uppercase">
82+
Pubkey
83+
</TextField.Label>
84+
<TextField.Input
85+
class="w-full rounded-lg p-2 text-black"
86+
placeholder=""
87+
/>
88+
</TextField.Root>
89+
<TextField.Root
90+
value={oracleAnn()}
91+
onChange={setOracleAnn}
92+
class="flex flex-col gap-4"
93+
>
94+
<TextField.Label class="text-sm font-semibold uppercase">
95+
Oracle Announcement
96+
</TextField.Label>
97+
<TextField.Input
98+
class="w-full rounded-lg p-2 text-black"
99+
placeholder=""
100+
/>
101+
</TextField.Root>
102+
<Button layout="small" type="submit">
103+
Test
104+
</Button>
105+
</form>
106+
</InnerCard>
107+
<DLCsList />
108+
</DefaultMain>
109+
<NavBar activeTab="settings" />
110+
</SafeArea>
111+
</MutinyWalletGuard>
112+
);
113+
}

src/routes/settings/Root.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ export function Settings() {
155155
{
156156
href: "/settings/syncnostrcontacts",
157157
text: "Sync Nostr Contacts"
158+
},
159+
{
160+
href: "/settings/dlc",
161+
text: "DLC Testing"
158162
}
159163
]}
160164
/>

src/routes/settings/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export * from "./Backup";
44
export * from "./Channels";
55
export * from "./Connections";
66
export * from "./Currency";
7+
export * from "./DLC";
78
export * from "./EmergencyKit";
89
export * from "./Encrypt";
910
export * from "./Gift";

0 commit comments

Comments
 (0)