Skip to content

Commit

Permalink
dlcs
Browse files Browse the repository at this point in the history
  • Loading branch information
benthecarman committed Dec 5, 2023
1 parent 3629627 commit 2039e8c
Show file tree
Hide file tree
Showing 6 changed files with 216 additions and 0 deletions.
95 changes: 95 additions & 0 deletions src/components/DLCList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import {Collapsible} from "@kobalte/core";
import {Contract} from "@mutinywallet/mutiny-wasm";

Check failure on line 2 in src/components/DLCList.tsx

View workflow job for this annotation

GitHub Actions / Build iOS

'"@mutinywallet/mutiny-wasm"' has no exported member named 'Contract'. Did you mean 'Contact'?

Check failure on line 2 in src/components/DLCList.tsx

View workflow job for this annotation

GitHub Actions / Build APK

'"@mutinywallet/mutiny-wasm"' has no exported member named 'Contract'. Did you mean 'Contact'?
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);

Check failure on line 16 in src/components/DLCList.tsx

View workflow job for this annotation

GitHub Actions / Build iOS

Property 'reject_dlc_offer' does not exist on type 'MutinyWallet'.

Check failure on line 16 in src/components/DLCList.tsx

View workflow job for this annotation

GitHub Actions / Build APK

Property 'reject_dlc_offer' does not exist on type 'MutinyWallet'.
await props.refetch();
};

const handleAcceptDLC = async () => {
await state.mutiny_wallet?.accept_dlc_offer(props.dlc.id);

Check failure on line 21 in src/components/DLCList.tsx

View workflow job for this annotation

GitHub Actions / Build iOS

Property 'accept_dlc_offer' does not exist on type 'MutinyWallet'.

Check failure on line 21 in src/components/DLCList.tsx

View workflow job for this annotation

GitHub Actions / Build APK

Property 'accept_dlc_offer' does not exist on type 'MutinyWallet'.
};

const handleCloseDLC = async () => {
const userInput = prompt("Enter oracle sigs:");
if (userInput != null) {
await state.mutiny_wallet?.close_dlc(props.dlc.id, userInput.trim());

Check failure on line 27 in src/components/DLCList.tsx

View workflow job for this annotation

GitHub Actions / Build iOS

Property 'close_dlc' does not exist on type 'MutinyWallet'.

Check failure on line 27 in src/components/DLCList.tsx

View workflow job for this annotation

GitHub Actions / Build APK

Property 'close_dlc' does not exist on type 'MutinyWallet'.
}
};

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[]>;

Check failure on line 70 in src/components/DLCList.tsx

View workflow job for this annotation

GitHub Actions / Build iOS

Property 'list_dlcs' does not exist on type 'MutinyWallet'.

Check failure on line 70 in src/components/DLCList.tsx

View workflow job for this annotation

GitHub Actions / Build APK

Property 'list_dlcs' does not exist on type 'MutinyWallet'.
};

const [peers, {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={peers.latest}
fallback={<code>No DLCs found.</code>}
>
{(dlc) => <DLCItem dlc={dlc} refetch={refetch}/>}
</For>
</VStack>
</Suspense>
<Button layout="small" onClick={refetch}>
Refresh
</Button>
</InnerCard>
</>
);
}
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export * from "./ContactForm";
export * from "./ContactViewer";
export * from "./DecryptDialog";
export * from "./DeleteEverything";
export * from "./DLCList";
export * from "./ErrorDisplay";
export * from "./Fee";
export * from "./I18nProvider";
Expand Down
2 changes: 2 additions & 0 deletions src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
Channels,
Connections,
Currency,
DLC,
EmergencyKit,
Encrypt,
Gift,
Expand Down Expand Up @@ -109,6 +110,7 @@ export function Router() {
<Route path="/channels" component={Channels} />
<Route path="/connections" component={Connections} />
<Route path="/currency" component={Currency} />
<Route path="/dlc" component={DLC} />
<Route path="/emergencykit" component={EmergencyKit} />
<Route path="/encrypt" component={Encrypt} />
<Route path="/gift" component={Gift} />
Expand Down
113 changes: 113 additions & 0 deletions src/routes/settings/DLC.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import { TextField } from "@kobalte/core";
import { createSignal } from "solid-js";

import {
BackLink,
Button,
DefaultMain,
DLCsList,
InnerCard,
LargeHeader,
MutinyWalletGuard,
NavBar,
SafeArea
} from "~/components";
import { useI18n } from "~/i18n/context";
import { useMegaStore } from "~/state/megaStore";

export function DLC() {
const i18n = useI18n();
const [state, _] = useMegaStore();

const [pubkey, setPubkey] = createSignal("");
const [oracleAnn, setOracleAnn] = createSignal("");

const onSubmit = async (e: SubmitEvent) => {
e.preventDefault();

const pk = pubkey().trim();
const oracle = oracleAnn().trim();

const size = 10000;
const outcomePayouts = [
{
outcome: "a",
payout: {
offer: size * 2,
accept: 0
}
},
{
outcome: "b",
payout: {
offer: 0,
accept: size * 2
}
}
];

const id = await state.mutiny_wallet?.test_send_dlc_offer(

Check failure on line 49 in src/routes/settings/DLC.tsx

View workflow job for this annotation

GitHub Actions / Build iOS

Property 'test_send_dlc_offer' does not exist on type 'MutinyWallet'.

Check failure on line 49 in src/routes/settings/DLC.tsx

View workflow job for this annotation

GitHub Actions / Build APK

Property 'test_send_dlc_offer' does not exist on type 'MutinyWallet'.
BigInt(size),
{ outcomePayouts },
oracle,
pk
);

// attestation
// ac5c1962f85ae0e6479da7ca5ce6dea1452c96dd7b4d6f26f45d7a2376a96421000105a47373c364053e8e2369fcfcfb7d7e08d6cae6e64a350bddb876cafb1760891ad9e74453873e04bce964cd810f20401d36725d69693a88703d3d47ff5a3c27000201610162

console.log("DLC contract id: " + id || "none");
};

return (
<MutinyWalletGuard>
<SafeArea>
<DefaultMain>
<BackLink
href="/settings"
title={i18n.t("settings.header")}
/>
<LargeHeader>DLC Testing</LargeHeader>
<InnerCard>
<LargeHeader>
My DLC Key: {state.mutiny_wallet?.get_dlc_key()}

Check failure on line 73 in src/routes/settings/DLC.tsx

View workflow job for this annotation

GitHub Actions / Build iOS

Property 'get_dlc_key' does not exist on type 'MutinyWallet'.

Check failure on line 73 in src/routes/settings/DLC.tsx

View workflow job for this annotation

GitHub Actions / Build APK

Property 'get_dlc_key' does not exist on type 'MutinyWallet'.
</LargeHeader>
<form class="flex flex-col gap-4" onSubmit={onSubmit}>
<TextField.Root
value={pubkey()}
onChange={setPubkey}
class="flex flex-col gap-4"
>
<TextField.Label class="text-sm font-semibold uppercase">
Pubkey
</TextField.Label>
<TextField.Input
class="w-full rounded-lg p-2 text-black"
placeholder=""
/>
</TextField.Root>
<TextField.Root
value={oracleAnn()}
onChange={setOracleAnn}
class="flex flex-col gap-4"
>
<TextField.Label class="text-sm font-semibold uppercase">
Oracle Announcement
</TextField.Label>
<TextField.Input
class="w-full rounded-lg p-2 text-black"
placeholder=""
/>
</TextField.Root>
<Button layout="small" type="submit">
Test
</Button>
</form>
</InnerCard>
<DLCsList />
</DefaultMain>
<NavBar activeTab="settings" />
</SafeArea>
</MutinyWalletGuard>
);
}
4 changes: 4 additions & 0 deletions src/routes/settings/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ export function Settings() {
{
href: "/settings/syncnostrcontacts",
text: "Sync Nostr Contacts"
},
{
href: "/settings/dlc",
text: "DLC Testing"
}
]}
/>
Expand Down
1 change: 1 addition & 0 deletions src/routes/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export * from "./Backup";
export * from "./Channels";
export * from "./Connections";
export * from "./Currency";
export * from "./DLC";
export * from "./EmergencyKit";
export * from "./Encrypt";
export * from "./Gift";
Expand Down

0 comments on commit 2039e8c

Please sign in to comment.