|
1 | 1 | <script lang="ts"> |
2 | 2 | import { lib } from "$lib"; |
3 | 3 | import { Ui } from "@repo/ui"; |
4 | | - import { createQuery } from "@tanstack/svelte-query"; |
5 | 4 | import { ethers } from "ethers"; |
6 | | - import { assert } from "ts-essentials"; |
| 5 | + import type { Address } from "viem"; |
7 | 6 | import { z } from "zod"; |
8 | 7 | import { zAddress } from "./utils"; |
9 | 8 |
|
10 | 9 | let { |
11 | | - jwt, |
12 | | - signer, |
13 | | - disabled, |
| 10 | + address, |
14 | 11 | }: { |
15 | | - jwt: string | undefined; |
16 | | - signer: ethers.Wallet; |
17 | | - disabled: boolean; |
| 12 | + address: Address; |
18 | 13 | } = $props(); |
19 | | -
|
20 | | - let balanceQuery = $derived( |
21 | | - createQuery( |
22 | | - { |
23 | | - queryKey: ["balance", jwt && ethers.id(jwt)], |
24 | | - queryFn: async () => { |
25 | | - let raw: bigint; |
26 | | - if (!jwt) { |
27 | | - raw = 0n; |
28 | | - } else { |
29 | | - throw new Error("not implemented"); |
30 | | - // const account = await lib.jwtAccount.getAccount(jwt, signer); |
31 | | - // raw = await signer.provider!.getBalance(account.address); |
32 | | - } |
33 | | - return `${ethers.formatEther(raw)} ETH`; |
34 | | - }, |
35 | | - }, |
36 | | - lib.queries.queryClient, |
37 | | - ), |
38 | | - ); |
39 | 14 | </script> |
40 | 15 |
|
41 | 16 | <Ui.Card.Root> |
42 | 17 | <Ui.Card.Header> |
43 | 18 | <Ui.Card.Title>Send ETH</Ui.Card.Title> |
44 | 19 | </Ui.Card.Header> |
45 | 20 | <Ui.Card.Content> |
46 | | - <div> |
47 | | - Balance: <Ui.Query query={$balanceQuery}> |
48 | | - {#snippet success(data)} |
49 | | - {data} |
50 | | - {/snippet} |
51 | | - </Ui.Query> |
52 | | - </div> |
53 | | - |
54 | 21 | <Ui.Form |
55 | 22 | schema={z.object({ |
56 | 23 | recipient: zAddress(), |
57 | 24 | amount: z.string(), |
58 | 25 | })} |
59 | 26 | onsubmit={async (data) => { |
60 | | - assert(jwt, "no session"); |
61 | | - throw new Error("not implemented"); |
62 | | - // const bundlerClient = getBundlerClient( |
63 | | - // await ethersSignerToWalletClient(signer), |
64 | | - // ); |
65 | | - // const account = await lib.jwtAccount.getAccount(jwt, signer); |
66 | | - // const tx = await bundlerClient.sendUserOperation({ |
67 | | - // account, |
68 | | - // calls: [ |
69 | | - // { |
70 | | - // to: data.recipient as Address, |
71 | | - // value: ethers.parseEther(data.amount), |
72 | | - // }, |
73 | | - // ], |
74 | | - // }); |
75 | | - // console.log("tx", tx); |
76 | | - // Ui.toast.success("Transaction sent successfully"); |
| 27 | + const cred = await lib.webAuthn.getCredential(); |
| 28 | + const tx = await lib.eip7702.executeTx({ |
| 29 | + credentialId: cred.id, |
| 30 | + address, |
| 31 | + to: data.recipient, |
| 32 | + value: ethers.parseEther(data.amount), |
| 33 | + }); |
| 34 | + console.log("tx", tx); |
| 35 | + lib.queries.invalidateAll(); |
| 36 | + Ui.toast.success("Transaction sent successfully"); |
77 | 37 | }} |
78 | 38 | > |
79 | 39 | {#snippet children(form, formData)} |
|
95 | 55 | <Ui.Form.FieldErrors /> |
96 | 56 | </Ui.Form.Field> |
97 | 57 |
|
98 | | - <Ui.Form.SubmitButton variant="default"> |
99 | | - {disabled ? "Create a session first" : "Send"} |
100 | | - </Ui.Form.SubmitButton> |
| 58 | + <Ui.Form.SubmitButton variant="default">Send</Ui.Form.SubmitButton> |
101 | 59 | {/snippet} |
102 | 60 | </Ui.Form> |
103 | 61 | </Ui.Card.Content> |
|
0 commit comments