-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3629627
commit a2e0ed5
Showing
6 changed files
with
389 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 GitHub Actions / Build APK
|
||
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 GitHub Actions / Build APK
|
||
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 GitHub Actions / Build APK
|
||
}; | ||
|
||
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 GitHub Actions / Build APK
|
||
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 GitHub Actions / Build APK
|
||
}; | ||
|
||
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> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.