Skip to content

Commit 6eeaa66

Browse files
committed
feat: implement wallet_getCallsStatus request handler
1 parent e2b48e4 commit 6eeaa66

3 files changed

Lines changed: 55 additions & 0 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import type { Hex, Log, WalletGetCallsStatusReturnType } from "viem"
2+
import type { UserOperationReceipt } from "viem/account-abstraction"
3+
4+
/**
5+
* Converts an array of user operation receipts into the {@link WalletGetCallsStatusReturnType} format.
6+
* If no receipts are provided, returns a `"PENDING"` status.
7+
*
8+
* @param receipts - Array of UserOperationReceipt objects or null.
9+
* @returns WalletGetCallsStatusReturnType with formatted receipt data.
10+
*/
11+
export function convertUserOpReceiptToCallStatus(
12+
receipts: UserOperationReceipt[] | null,
13+
): WalletGetCallsStatusReturnType {
14+
if (!receipts || receipts.length === 0) {
15+
return { status: "PENDING" }
16+
}
17+
18+
return {
19+
status: "CONFIRMED",
20+
receipts: receipts.map(({ receipt, logs, success }) => ({
21+
logs: logs.map((log: Log<bigint, number, false>) => ({
22+
address: log.address as Hex,
23+
data: log.data as Hex,
24+
topics: log.topics as Hex[],
25+
})),
26+
status: (success ? "0x1" : "0x0") as Hex,
27+
blockHash: receipt.blockHash as Hex,
28+
blockNumber: `0x${receipt.blockNumber.toString(16)}` as Hex,
29+
gasUsed: `0x${receipt.gasUsed.toString(16)}` as Hex,
30+
transactionHash: receipt.transactionHash as Hex,
31+
})),
32+
} satisfies WalletGetCallsStatusReturnType
33+
}

apps/iframe/src/requests/permissionless.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import { getUser } from "#src/state/user"
4242
import { getWalletClient } from "#src/state/walletClient"
4343
import type { AppURL } from "#src/utils/appURL"
4444
import { checkIfRequestRequiresConfirmation } from "#src/utils/checkIfRequestRequiresConfirmation"
45+
import { convertUserOpReceiptToCallStatus } from "./modules/boop-batcher/helpers"
4546
import { sendResponse } from "./sendResponse"
4647
import { appForSourceID, checkAuthenticated } from "./utils"
4748

@@ -290,6 +291,26 @@ export async function dispatchHandlers(request: ProviderMsgsFromApp[Msgs.Request
290291
return capabilities satisfies GetCapabilitiesReturnType
291292
}
292293

294+
case "wallet_getCallsStatus": {
295+
// TODO if the batch was atomic, this handler MUST return only a single receipt
296+
try {
297+
const [hash] = request.payload.params as Hash[]
298+
if (!hash) {
299+
throw new Error("Transaction hash is missing.")
300+
}
301+
const smartAccountClient = (await getSmartAccountClient()) as ExtendedSmartAccountClient
302+
303+
const userOpReceipt = await smartAccountClient.getUserOperationReceipt({
304+
hash: hash,
305+
})
306+
307+
return convertUserOpReceiptToCallStatus(userOpReceipt ? [userOpReceipt] : null)
308+
} catch (error) {
309+
console.error(error)
310+
throw error
311+
}
312+
}
313+
293314
case HappyMethodNames.REQUEST_SESSION_KEY: {
294315
const user = getUser()
295316
const targetContractAddress = request.payload.params[0] as Address

support/wallet-common/lib/interfaces/permissions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ const safeList = new Set([
6767
"web3_clientVersion",
6868
"web3_sha3",
6969
"wallet_getCapabilities",
70+
"wallet_getCallsStatus",
7071
])
7172

7273
/**

0 commit comments

Comments
 (0)