Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dlcs #753

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

dlcs #753

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions src/components/DLCList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
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(

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

Check failure on line 69 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 69 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 [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>
</>
);
}
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
Loading
Loading