-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
- Loading branch information
There are no files selected for viewing
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 GitHub Actions / Build iOS
|
||
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 iOS
|
||
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 iOS
|
||
}; | ||
|
||
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 GitHub Actions / Build iOS
|
||
} | ||
}; | ||
|
||
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 GitHub Actions / Build iOS
|
||
}; | ||
|
||
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> | ||
</> | ||
); | ||
} |
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 GitHub Actions / Build iOS
|
||
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 GitHub Actions / Build iOS
|
||
</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> | ||
); | ||
} |