|
1 | | -import { Hex, encodeFunctionData, parseEventLogs } from "viem"; |
| 1 | +import { Hex, encodeFunctionData, parseEventLogs, zeroAddress } from "viem"; |
2 | 2 | import { useMutation, useQueryClient } from "@tanstack/react-query"; |
3 | 3 | import { getAction } from "viem/utils"; |
4 | 4 | import { entryPoint07Abi, sendUserOperation, waitForUserOperationReceipt } from "viem/account-abstraction"; |
@@ -84,6 +84,8 @@ export function useSetupSession({ connector, userClient }: { connector: Connecto |
84 | 84 | }); |
85 | 85 | console.log("got send calls ID", id); |
86 | 86 |
|
| 87 | + // TODO: switch to `waitForCallsStatus`, but needs to be able to run "headless" (no popup) |
| 88 | + |
87 | 89 | const bundlerClient = createBundlerClient({ |
88 | 90 | transport: getBundlerTransport(client.chain), |
89 | 91 | client, |
@@ -112,6 +114,29 @@ export function useSetupSession({ connector, userClient }: { connector: Connecto |
112 | 114 | ], |
113 | 115 | }), |
114 | 116 | ); |
| 117 | + |
| 118 | + // create session account instead of doing lazily |
| 119 | + await (async () => { |
| 120 | + console.log("creating session account by sending empty user op"); |
| 121 | + const hash = await getAction( |
| 122 | + sessionClient, |
| 123 | + sendUserOperation, |
| 124 | + "sendUserOperation", |
| 125 | + )({ |
| 126 | + calls: [{ to: zeroAddress }], |
| 127 | + }); |
| 128 | + |
| 129 | + const receipt = await getAction( |
| 130 | + bundlerClient, |
| 131 | + waitForUserOperationReceipt, |
| 132 | + "waitForUserOperationReceipt", |
| 133 | + )({ hash }); |
| 134 | + console.log("got user op receipt", receipt); |
| 135 | + |
| 136 | + if (!receipt.success) { |
| 137 | + console.error("not successful?", receipt); |
| 138 | + } |
| 139 | + })(); |
115 | 140 | } else if (userClient.account.type === "smart") { |
116 | 141 | // Set up session for smart account wallet |
117 | 142 | const calls = []; |
|
0 commit comments