Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/yummy-sloths-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Fix getCallStatus via EIP1193 provider
15 changes: 11 additions & 4 deletions apps/wagmi-demo/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import type { ConnectionOptions } from "@thirdweb-dev/wagmi-adapter";
import { ConnectButton } from "thirdweb/react";
import { stringify } from "thirdweb/utils";
import { createWallet } from "thirdweb/wallets";
import {
useAccount,
useCallsStatus,
useConnect,
useDisconnect,
useSendCalls,
useSendTransaction,
useWaitForCallsStatus,
} from "wagmi";
import { chain, client, thirdwebChainForWallet, wallet } from "./wagmi.js";

Expand All @@ -28,7 +29,7 @@ function App() {
data: callStatus,
isLoading: isLoadingCallStatus,
error: callStatusError,
} = useCallsStatus({
} = useWaitForCallsStatus({
id: data?.id || "",
query: {
enabled: !!data?.id,
Expand All @@ -42,7 +43,7 @@ function App() {
<div>
status: {account.status}
<br />
addresses: {JSON.stringify(account.addresses)}
addresses: {stringify(account.addresses)}
<br />
chainId: {account.chainId}
</div>
Expand Down Expand Up @@ -122,6 +123,12 @@ function App() {
calls: [
{
to: "0x70997970c51812dc3a010c7d01b50e0d17dc79c8",
data: "0x1234",
value: 0n,
},
{
to: "0x70997970c51812dc3a010c7d01b50e0d17dc79c8",
data: "0x1234",
value: 0n,
},
],
Expand All @@ -145,7 +152,7 @@ function App() {
</div>
<div>
{callStatus
? `Success: ${JSON.stringify(callStatus, null, 2)}`
? `Success: ${stringify(callStatus, null, 2)}`
: callStatusError
? callStatusError?.message
: ""}
Expand Down
5 changes: 3 additions & 2 deletions packages/thirdweb/src/adapters/eip1193/to-eip1193.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,15 @@ export function toProvider(options: ToEip1193ProviderOptions): EIP1193Provider {
if (!account) {
throw new Error("Account not connected");
}
if (!account.getCallsStatus) {
if (!account.getCallsStatusRaw) {
throw new Error("Wallet does not support EIP-5792");
}
return account.getCallsStatus({
const result = await account.getCallsStatusRaw({
id: request.params[0],
chain: chain,
client: client,
});
return result;
}
default:
return rpcClient(request);
Expand Down
16 changes: 16 additions & 0 deletions packages/thirdweb/src/wallets/coinbase/coinbase-web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,22 @@ function createAccount({
throw error;
}
},
async getCallsStatusRaw(options) {
try {
const rawResponse = (await provider.request({
method: "wallet_getCallsStatus",
params: [options.id],
})) as GetCallsStatusRawResponse;
return rawResponse;
} catch (error) {
if (/unsupport|not support/i.test((error as Error).message)) {
throw new Error(
`${COINBASE} does not support wallet_getCallsStatus, reach out to them directly to request EIP-5792 support.`,
);
}
throw error;
}
},
async getCapabilities(options) {
const chainId = options.chainId;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { Hex } from "../../../../utils/encoding/hex.js";
import { randomBytesHex } from "../../../../utils/random.js";
import type { PreparedSendCall } from "../../../eip5792/send-calls.js";
import type {
GetCallsStatusRawResponse,
GetCallsStatusResponse,
WalletCallReceipt,
} from "../../../eip5792/types.js";
Expand Down Expand Up @@ -108,3 +109,52 @@ export async function inAppWalletGetCallsStatus(args: {
version: "2.0.0",
};
}

/**
* @internal
*/
export async function inAppWalletGetCallsStatusRaw(args: {
chain: Chain;
client: ThirdwebClient;
id: string;
}): Promise<GetCallsStatusRawResponse> {
const { chain, client, id } = args;

const bundle = bundlesToTransactions.get(id);
if (!bundle) {
throw new Error("Failed to get calls status, unknown bundle id");
}

const request = getRpcClient({ chain, client });
let status = 200; // BATCH_STATE_CONFIRMED
const receipts: GetCallsStatusRawResponse["receipts"] = [];

for (const hash of bundle) {
try {
const receipt = await eth_getTransactionReceipt(request, { hash });
receipts.push({
blockHash: receipt.blockHash,
blockNumber: `0x${receipt.blockNumber.toString(16)}` as `0x${string}`,
gasUsed: `0x${receipt.gasUsed.toString(16)}` as `0x${string}`,
logs: receipt.logs.map((l) => ({
address: l.address as `0x${string}`,
data: l.data as `0x${string}`,
topics: l.topics as `0x${string}`[],
})),
status: receipt.status === "success" ? "0x1" : "0x0",
transactionHash: receipt.transactionHash as `0x${string}`,
});
} catch {
status = 100; // BATCH_STATE_PENDING
}
}

return {
atomic: false,
chainId: `0x${chain.id.toString(16)}` as `0x${string}`,
id: id as `0x${string}`,
receipts,
status,
version: "2.0.0",
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,12 @@ export const create7702MinimalAccount = (args: {
);
return inAppWalletGetCallsStatus(options);
},
getCallsStatusRaw: async (options) => {
const { inAppWalletGetCallsStatusRaw } = await import(
"../eip5792/in-app-wallet-calls.js"
);
return inAppWalletGetCallsStatusRaw(options);
},
getCapabilities: async (options) => {
return {
[options.chainId ?? 1]: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,12 @@ export class EnclaveWallet implements IWebWallet {
);
return inAppWalletGetCallsStatus(options);
},
getCallsStatusRaw: async (options) => {
const { inAppWalletGetCallsStatusRaw } = await import(
"../eip5792/in-app-wallet-calls.js"
);
return inAppWalletGetCallsStatusRaw(options);
},
getCapabilities: async (options) => {
return {
[options.chainId ?? 1]: {
Expand Down
16 changes: 16 additions & 0 deletions packages/thirdweb/src/wallets/injected/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,22 @@ function createAccount({
throw error;
}
},
async getCallsStatusRaw(options) {
try {
const rawResponse = (await provider.request({
method: "wallet_getCallsStatus",
params: [options.id],
})) as GetCallsStatusRawResponse;
return rawResponse;
} catch (error) {
if (/unsupport|not support/i.test((error as Error).message)) {
throw new Error(
`${id} does not support wallet_getCallsStatus, reach out to them directly to request EIP-5792 support.`,
);
}
throw error;
}
},
async getCapabilities(options) {
const chainIdFilter = options.chainId;
try {
Expand Down
9 changes: 9 additions & 0 deletions packages/thirdweb/src/wallets/interfaces/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import type {
SendCallsResult,
} from "../eip5792/send-calls.js";
import type {
GetCallsStatusRawResponse,
GetCallsStatusResponse,
WalletSendCallsId,
} from "../eip5792/types.js";
Expand Down Expand Up @@ -325,6 +326,14 @@ export type Account = {
chain: Chain;
client: ThirdwebClient;
}) => Promise<GetCallsStatusResponse>;
/**
* EIP-5792: Get the raw (unprocessed) status of the given call bundle
*/
getCallsStatusRaw?: (options: {
id: WalletSendCallsId;
chain: Chain;
client: ThirdwebClient;
}) => Promise<GetCallsStatusRawResponse>;
/**
* EIP-5792: Get the capabilities of the wallet
*/
Expand Down
12 changes: 12 additions & 0 deletions packages/thirdweb/src/wallets/smart/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,12 @@ async function createSmartAccount(
);
return inAppWalletGetCallsStatus(options);
},
getCallsStatusRaw: async (options) => {
const { inAppWalletGetCallsStatusRaw } = await import(
"../in-app/core/eip5792/in-app-wallet-calls.js"
);
return inAppWalletGetCallsStatusRaw(options);
},
getCapabilities: async (options) => {
return {
[options.chainId ?? 1]: {
Expand Down Expand Up @@ -567,6 +573,12 @@ function createZkSyncAccount(args: {
);
return inAppWalletGetCallsStatus(options);
},
getCallsStatusRaw: async (options) => {
const { inAppWalletGetCallsStatusRaw } = await import(
"../in-app/core/eip5792/in-app-wallet-calls.js"
);
return inAppWalletGetCallsStatusRaw(options);
},
getCapabilities: async (options) => {
return {
[options.chainId ?? 1]: {
Expand Down
Loading