Skip to content

Commit d38deec

Browse files
Fix getCallStatus via EIP1193 provider (#8639)
1 parent a3ea002 commit d38deec

10 files changed

Lines changed: 134 additions & 6 deletions

File tree

.changeset/yummy-sloths-live.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Fix getCallStatus via EIP1193 provider

apps/wagmi-demo/src/App.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import type { ConnectionOptions } from "@thirdweb-dev/wagmi-adapter";
22
import { ConnectButton } from "thirdweb/react";
3+
import { stringify } from "thirdweb/utils";
34
import { createWallet } from "thirdweb/wallets";
45
import {
56
useAccount,
6-
useCallsStatus,
77
useConnect,
88
useDisconnect,
99
useSendCalls,
1010
useSendTransaction,
11+
useWaitForCallsStatus,
1112
} from "wagmi";
1213
import { chain, client, thirdwebChainForWallet, wallet } from "./wagmi.js";
1314

@@ -28,7 +29,7 @@ function App() {
2829
data: callStatus,
2930
isLoading: isLoadingCallStatus,
3031
error: callStatusError,
31-
} = useCallsStatus({
32+
} = useWaitForCallsStatus({
3233
id: data?.id || "",
3334
query: {
3435
enabled: !!data?.id,
@@ -42,7 +43,7 @@ function App() {
4243
<div>
4344
status: {account.status}
4445
<br />
45-
addresses: {JSON.stringify(account.addresses)}
46+
addresses: {stringify(account.addresses)}
4647
<br />
4748
chainId: {account.chainId}
4849
</div>
@@ -122,6 +123,12 @@ function App() {
122123
calls: [
123124
{
124125
to: "0x70997970c51812dc3a010c7d01b50e0d17dc79c8",
126+
data: "0x1234",
127+
value: 0n,
128+
},
129+
{
130+
to: "0x70997970c51812dc3a010c7d01b50e0d17dc79c8",
131+
data: "0x1234",
125132
value: 0n,
126133
},
127134
],
@@ -145,7 +152,7 @@ function App() {
145152
</div>
146153
<div>
147154
{callStatus
148-
? `Success: ${JSON.stringify(callStatus, null, 2)}`
155+
? `Success: ${stringify(callStatus, null, 2)}`
149156
: callStatusError
150157
? callStatusError?.message
151158
: ""}

packages/thirdweb/src/adapters/eip1193/to-eip1193.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,15 @@ export function toProvider(options: ToEip1193ProviderOptions): EIP1193Provider {
194194
if (!account) {
195195
throw new Error("Account not connected");
196196
}
197-
if (!account.getCallsStatus) {
197+
if (!account.getCallsStatusRaw) {
198198
throw new Error("Wallet does not support EIP-5792");
199199
}
200-
return account.getCallsStatus({
200+
const result = await account.getCallsStatusRaw({
201201
id: request.params[0],
202202
chain: chain,
203203
client: client,
204204
});
205+
return result;
205206
}
206207
default:
207208
return rpcClient(request);

packages/thirdweb/src/wallets/coinbase/coinbase-web.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,22 @@ function createAccount({
326326
throw error;
327327
}
328328
},
329+
async getCallsStatusRaw(options) {
330+
try {
331+
const rawResponse = (await provider.request({
332+
method: "wallet_getCallsStatus",
333+
params: [options.id],
334+
})) as GetCallsStatusRawResponse;
335+
return rawResponse;
336+
} catch (error) {
337+
if (/unsupport|not support/i.test((error as Error).message)) {
338+
throw new Error(
339+
`${COINBASE} does not support wallet_getCallsStatus, reach out to them directly to request EIP-5792 support.`,
340+
);
341+
}
342+
throw error;
343+
}
344+
},
329345
async getCapabilities(options) {
330346
const chainId = options.chainId;
331347
try {

packages/thirdweb/src/wallets/in-app/core/eip5792/in-app-wallet-calls.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type { Hex } from "../../../../utils/encoding/hex.js";
1010
import { randomBytesHex } from "../../../../utils/random.js";
1111
import type { PreparedSendCall } from "../../../eip5792/send-calls.js";
1212
import type {
13+
GetCallsStatusRawResponse,
1314
GetCallsStatusResponse,
1415
WalletCallReceipt,
1516
} from "../../../eip5792/types.js";
@@ -108,3 +109,52 @@ export async function inAppWalletGetCallsStatus(args: {
108109
version: "2.0.0",
109110
};
110111
}
112+
113+
/**
114+
* @internal
115+
*/
116+
export async function inAppWalletGetCallsStatusRaw(args: {
117+
chain: Chain;
118+
client: ThirdwebClient;
119+
id: string;
120+
}): Promise<GetCallsStatusRawResponse> {
121+
const { chain, client, id } = args;
122+
123+
const bundle = bundlesToTransactions.get(id);
124+
if (!bundle) {
125+
throw new Error("Failed to get calls status, unknown bundle id");
126+
}
127+
128+
const request = getRpcClient({ chain, client });
129+
let status = 200; // BATCH_STATE_CONFIRMED
130+
const receipts: GetCallsStatusRawResponse["receipts"] = [];
131+
132+
for (const hash of bundle) {
133+
try {
134+
const receipt = await eth_getTransactionReceipt(request, { hash });
135+
receipts.push({
136+
blockHash: receipt.blockHash,
137+
blockNumber: `0x${receipt.blockNumber.toString(16)}` as `0x${string}`,
138+
gasUsed: `0x${receipt.gasUsed.toString(16)}` as `0x${string}`,
139+
logs: receipt.logs.map((l) => ({
140+
address: l.address as `0x${string}`,
141+
data: l.data as `0x${string}`,
142+
topics: l.topics as `0x${string}`[],
143+
})),
144+
status: receipt.status === "success" ? "0x1" : "0x0",
145+
transactionHash: receipt.transactionHash as `0x${string}`,
146+
});
147+
} catch {
148+
status = 100; // BATCH_STATE_PENDING
149+
}
150+
}
151+
152+
return {
153+
atomic: false,
154+
chainId: `0x${chain.id.toString(16)}` as `0x${string}`,
155+
id: id as `0x${string}`,
156+
receipts,
157+
status,
158+
version: "2.0.0",
159+
};
160+
}

packages/thirdweb/src/wallets/in-app/core/eip7702/minimal-account.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,12 @@ export const create7702MinimalAccount = (args: {
351351
);
352352
return inAppWalletGetCallsStatus(options);
353353
},
354+
getCallsStatusRaw: async (options) => {
355+
const { inAppWalletGetCallsStatusRaw } = await import(
356+
"../eip5792/in-app-wallet-calls.js"
357+
);
358+
return inAppWalletGetCallsStatusRaw(options);
359+
},
354360
getCapabilities: async (options) => {
355361
return {
356362
[options.chainId ?? 1]: {

packages/thirdweb/src/wallets/in-app/core/wallet/enclave-wallet.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,12 @@ export class EnclaveWallet implements IWebWallet {
287287
);
288288
return inAppWalletGetCallsStatus(options);
289289
},
290+
getCallsStatusRaw: async (options) => {
291+
const { inAppWalletGetCallsStatusRaw } = await import(
292+
"../eip5792/in-app-wallet-calls.js"
293+
);
294+
return inAppWalletGetCallsStatusRaw(options);
295+
},
290296
getCapabilities: async (options) => {
291297
return {
292298
[options.chainId ?? 1]: {

packages/thirdweb/src/wallets/injected/index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,22 @@ function createAccount({
373373
throw error;
374374
}
375375
},
376+
async getCallsStatusRaw(options) {
377+
try {
378+
const rawResponse = (await provider.request({
379+
method: "wallet_getCallsStatus",
380+
params: [options.id],
381+
})) as GetCallsStatusRawResponse;
382+
return rawResponse;
383+
} catch (error) {
384+
if (/unsupport|not support/i.test((error as Error).message)) {
385+
throw new Error(
386+
`${id} does not support wallet_getCallsStatus, reach out to them directly to request EIP-5792 support.`,
387+
);
388+
}
389+
throw error;
390+
}
391+
},
376392
async getCapabilities(options) {
377393
const chainIdFilter = options.chainId;
378394
try {

packages/thirdweb/src/wallets/interfaces/wallet.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import type {
1919
SendCallsResult,
2020
} from "../eip5792/send-calls.js";
2121
import type {
22+
GetCallsStatusRawResponse,
2223
GetCallsStatusResponse,
2324
WalletSendCallsId,
2425
} from "../eip5792/types.js";
@@ -325,6 +326,14 @@ export type Account = {
325326
chain: Chain;
326327
client: ThirdwebClient;
327328
}) => Promise<GetCallsStatusResponse>;
329+
/**
330+
* EIP-5792: Get the raw (unprocessed) status of the given call bundle
331+
*/
332+
getCallsStatusRaw?: (options: {
333+
id: WalletSendCallsId;
334+
chain: Chain;
335+
client: ThirdwebClient;
336+
}) => Promise<GetCallsStatusRawResponse>;
328337
/**
329338
* EIP-5792: Get the capabilities of the wallet
330339
*/

packages/thirdweb/src/wallets/smart/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,12 @@ async function createSmartAccount(
389389
);
390390
return inAppWalletGetCallsStatus(options);
391391
},
392+
getCallsStatusRaw: async (options) => {
393+
const { inAppWalletGetCallsStatusRaw } = await import(
394+
"../in-app/core/eip5792/in-app-wallet-calls.js"
395+
);
396+
return inAppWalletGetCallsStatusRaw(options);
397+
},
392398
getCapabilities: async (options) => {
393399
return {
394400
[options.chainId ?? 1]: {
@@ -567,6 +573,12 @@ function createZkSyncAccount(args: {
567573
);
568574
return inAppWalletGetCallsStatus(options);
569575
},
576+
getCallsStatusRaw: async (options) => {
577+
const { inAppWalletGetCallsStatusRaw } = await import(
578+
"../in-app/core/eip5792/in-app-wallet-calls.js"
579+
);
580+
return inAppWalletGetCallsStatusRaw(options);
581+
},
570582
getCapabilities: async (options) => {
571583
return {
572584
[options.chainId ?? 1]: {

0 commit comments

Comments
 (0)