thirdweb 5.98.1 → 5.99.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/exports/react.js +11 -8
- package/dist/cjs/exports/react.js.map +1 -1
- package/dist/cjs/exports/react.native.js +11 -8
- package/dist/cjs/exports/react.native.js.map +1 -1
- package/dist/cjs/exports/wallets/eip5792.js +7 -3
- package/dist/cjs/exports/wallets/eip5792.js.map +1 -1
- package/dist/cjs/extensions/erc20/read/getCurrencyMetadata.js +2 -2
- package/dist/cjs/extensions/erc20/read/getCurrencyMetadata.js.map +1 -1
- package/dist/cjs/react/core/hooks/wallets/useCapabilities.js +5 -6
- package/dist/cjs/react/core/hooks/wallets/useCapabilities.js.map +1 -1
- package/dist/cjs/react/core/hooks/wallets/useSendAndConfirmCalls.js +99 -0
- package/dist/cjs/react/core/hooks/wallets/useSendAndConfirmCalls.js.map +1 -0
- package/dist/cjs/react/core/hooks/wallets/useSendCalls.js +32 -40
- package/dist/cjs/react/core/hooks/wallets/useSendCalls.js.map +1 -1
- package/dist/cjs/react/core/hooks/wallets/useWaitForCallsReceipt.js +38 -0
- package/dist/cjs/react/core/hooks/wallets/useWaitForCallsReceipt.js.map +1 -0
- package/dist/cjs/react/core/providers/thirdweb-provider.js +4 -3
- package/dist/cjs/react/core/providers/thirdweb-provider.js.map +1 -1
- package/dist/cjs/react/native/ui/connect/ConnectButton.js +4 -1
- package/dist/cjs/react/native/ui/connect/ConnectButton.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/ConnectButton.js +6 -4
- package/dist/cjs/react/web/ui/ConnectWallet/ConnectButton.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/Modal/ConnectEmbed.js +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/Modal/ConnectEmbed.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/fiat/OnRampScreen.js +5 -15
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/fiat/OnRampScreen.js.map +1 -1
- package/dist/cjs/react/web/ui/PayEmbed.js +8 -1
- package/dist/cjs/react/web/ui/PayEmbed.js.map +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/wallets/coinbase/coinbase-web.js +2 -85
- package/dist/cjs/wallets/coinbase/coinbase-web.js.map +1 -1
- package/dist/cjs/wallets/connection/autoConnectCore.js +29 -12
- package/dist/cjs/wallets/connection/autoConnectCore.js.map +1 -1
- package/dist/cjs/wallets/eip5792/get-calls-status.js +54 -15
- package/dist/cjs/wallets/eip5792/get-calls-status.js.map +1 -1
- package/dist/cjs/wallets/eip5792/get-capabilities.js +21 -8
- package/dist/cjs/wallets/eip5792/get-capabilities.js.map +1 -1
- package/dist/cjs/wallets/eip5792/send-and-confirm-calls.js +41 -0
- package/dist/cjs/wallets/eip5792/send-and-confirm-calls.js.map +1 -0
- package/dist/cjs/wallets/eip5792/send-calls.js +27 -14
- package/dist/cjs/wallets/eip5792/send-calls.js.map +1 -1
- package/dist/cjs/wallets/eip5792/show-calls-status.js +8 -7
- package/dist/cjs/wallets/eip5792/show-calls-status.js.map +1 -1
- package/dist/cjs/wallets/eip5792/{wait-for-bundle.js → wait-for-calls-receipt.js} +23 -10
- package/dist/cjs/wallets/eip5792/wait-for-calls-receipt.js.map +1 -0
- package/dist/cjs/wallets/in-app/core/eip5972/in-app-wallet-calls.js +15 -10
- package/dist/cjs/wallets/in-app/core/eip5972/in-app-wallet-calls.js.map +1 -1
- package/dist/cjs/wallets/in-app/core/eip5972/in-app-wallet-capabilities.js +13 -3
- package/dist/cjs/wallets/in-app/core/eip5972/in-app-wallet-capabilities.js.map +1 -1
- package/dist/cjs/wallets/in-app/core/wallet/is-in-app-signer.js +15 -0
- package/dist/cjs/wallets/in-app/core/wallet/is-in-app-signer.js.map +1 -0
- package/dist/cjs/wallets/smart/lib/smart-wallet-capabilities.js +4 -2
- package/dist/cjs/wallets/smart/lib/smart-wallet-capabilities.js.map +1 -1
- package/dist/esm/exports/react.js +5 -3
- package/dist/esm/exports/react.js.map +1 -1
- package/dist/esm/exports/react.native.js +5 -3
- package/dist/esm/exports/react.native.js.map +1 -1
- package/dist/esm/exports/wallets/eip5792.js +3 -1
- package/dist/esm/exports/wallets/eip5792.js.map +1 -1
- package/dist/esm/extensions/erc20/read/getCurrencyMetadata.js +2 -2
- package/dist/esm/extensions/erc20/read/getCurrencyMetadata.js.map +1 -1
- package/dist/esm/react/core/hooks/wallets/useCapabilities.js +5 -6
- package/dist/esm/react/core/hooks/wallets/useCapabilities.js.map +1 -1
- package/dist/esm/react/core/hooks/wallets/useSendAndConfirmCalls.js +96 -0
- package/dist/esm/react/core/hooks/wallets/useSendAndConfirmCalls.js.map +1 -0
- package/dist/esm/react/core/hooks/wallets/useSendCalls.js +32 -40
- package/dist/esm/react/core/hooks/wallets/useSendCalls.js.map +1 -1
- package/dist/esm/react/core/hooks/wallets/useWaitForCallsReceipt.js +35 -0
- package/dist/esm/react/core/hooks/wallets/useWaitForCallsReceipt.js.map +1 -0
- package/dist/esm/react/core/providers/thirdweb-provider.js +4 -3
- package/dist/esm/react/core/providers/thirdweb-provider.js.map +1 -1
- package/dist/esm/react/native/ui/connect/ConnectButton.js +4 -1
- package/dist/esm/react/native/ui/connect/ConnectButton.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/ConnectButton.js +6 -4
- package/dist/esm/react/web/ui/ConnectWallet/ConnectButton.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/Modal/ConnectEmbed.js +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/Modal/ConnectEmbed.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/fiat/OnRampScreen.js +1 -11
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/fiat/OnRampScreen.js.map +1 -1
- package/dist/esm/react/web/ui/PayEmbed.js +8 -1
- package/dist/esm/react/web/ui/PayEmbed.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/wallets/coinbase/coinbase-web.js +2 -81
- package/dist/esm/wallets/coinbase/coinbase-web.js.map +1 -1
- package/dist/esm/wallets/connection/autoConnectCore.js +29 -12
- package/dist/esm/wallets/connection/autoConnectCore.js.map +1 -1
- package/dist/esm/wallets/eip5792/get-calls-status.js +54 -15
- package/dist/esm/wallets/eip5792/get-calls-status.js.map +1 -1
- package/dist/esm/wallets/eip5792/get-capabilities.js +22 -9
- package/dist/esm/wallets/eip5792/get-capabilities.js.map +1 -1
- package/dist/esm/wallets/eip5792/send-and-confirm-calls.js +38 -0
- package/dist/esm/wallets/eip5792/send-and-confirm-calls.js.map +1 -0
- package/dist/esm/wallets/eip5792/send-calls.js +28 -15
- package/dist/esm/wallets/eip5792/send-calls.js.map +1 -1
- package/dist/esm/wallets/eip5792/show-calls-status.js +9 -8
- package/dist/esm/wallets/eip5792/show-calls-status.js.map +1 -1
- package/dist/esm/wallets/eip5792/{wait-for-bundle.js → wait-for-calls-receipt.js} +22 -9
- package/dist/esm/wallets/eip5792/wait-for-calls-receipt.js.map +1 -0
- package/dist/esm/wallets/in-app/core/eip5972/in-app-wallet-calls.js +15 -10
- package/dist/esm/wallets/in-app/core/eip5972/in-app-wallet-calls.js.map +1 -1
- package/dist/esm/wallets/in-app/core/eip5972/in-app-wallet-capabilities.js +13 -3
- package/dist/esm/wallets/in-app/core/eip5972/in-app-wallet-capabilities.js.map +1 -1
- package/dist/esm/wallets/in-app/core/wallet/is-in-app-signer.js +12 -0
- package/dist/esm/wallets/in-app/core/wallet/is-in-app-signer.js.map +1 -0
- package/dist/esm/wallets/smart/lib/smart-wallet-capabilities.js +4 -2
- package/dist/esm/wallets/smart/lib/smart-wallet-capabilities.js.map +1 -1
- package/dist/types/exports/react.d.ts +4 -3
- package/dist/types/exports/react.d.ts.map +1 -1
- package/dist/types/exports/react.native.d.ts +4 -3
- package/dist/types/exports/react.native.d.ts.map +1 -1
- package/dist/types/exports/wallets/eip5792.d.ts +3 -1
- package/dist/types/exports/wallets/eip5792.d.ts.map +1 -1
- package/dist/types/react/core/hooks/wallets/useCapabilities.d.ts +1 -0
- package/dist/types/react/core/hooks/wallets/useCapabilities.d.ts.map +1 -1
- package/dist/types/react/core/hooks/wallets/useSendAndConfirmCalls.d.ts +66 -0
- package/dist/types/react/core/hooks/wallets/useSendAndConfirmCalls.d.ts.map +1 -0
- package/dist/types/react/core/hooks/wallets/useSendCalls.d.ts +8 -11
- package/dist/types/react/core/hooks/wallets/useSendCalls.d.ts.map +1 -1
- package/dist/types/react/core/hooks/wallets/useWaitForCallsReceipt.d.ts +32 -0
- package/dist/types/react/core/hooks/wallets/useWaitForCallsReceipt.d.ts.map +1 -0
- package/dist/types/react/core/providers/thirdweb-provider.d.ts.map +1 -1
- package/dist/types/react/native/ui/connect/ConnectButton.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/ConnectButton.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/Modal/ConnectEmbed.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/fiat/OnRampScreen.d.ts.map +1 -1
- package/dist/types/react/web/ui/PayEmbed.d.ts +1 -1
- package/dist/types/react/web/ui/PayEmbed.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/types/wallets/coinbase/coinbase-web.d.ts +2 -30
- package/dist/types/wallets/coinbase/coinbase-web.d.ts.map +1 -1
- package/dist/types/wallets/connection/autoConnectCore.d.ts.map +1 -1
- package/dist/types/wallets/connection/types.d.ts +9 -0
- package/dist/types/wallets/connection/types.d.ts.map +1 -1
- package/dist/types/wallets/eip5792/get-calls-status.d.ts +5 -6
- package/dist/types/wallets/eip5792/get-calls-status.d.ts.map +1 -1
- package/dist/types/wallets/eip5792/get-capabilities.d.ts +2 -1
- package/dist/types/wallets/eip5792/get-capabilities.d.ts.map +1 -1
- package/dist/types/wallets/eip5792/send-and-confirm-calls.d.ts +39 -0
- package/dist/types/wallets/eip5792/send-and-confirm-calls.d.ts.map +1 -0
- package/dist/types/wallets/eip5792/send-calls.d.ts +12 -5
- package/dist/types/wallets/eip5792/send-calls.d.ts.map +1 -1
- package/dist/types/wallets/eip5792/show-calls-status.d.ts +2 -2
- package/dist/types/wallets/eip5792/show-calls-status.d.ts.map +1 -1
- package/dist/types/wallets/eip5792/types.d.ts +33 -4
- package/dist/types/wallets/eip5792/types.d.ts.map +1 -1
- package/dist/types/wallets/eip5792/{wait-for-bundle.d.ts → wait-for-calls-receipt.d.ts} +21 -9
- package/dist/types/wallets/eip5792/wait-for-calls-receipt.d.ts.map +1 -0
- package/dist/types/wallets/in-app/core/eip5972/in-app-wallet-calls.d.ts +3 -3
- package/dist/types/wallets/in-app/core/eip5972/in-app-wallet-calls.d.ts.map +1 -1
- package/dist/types/wallets/in-app/core/eip5972/in-app-wallet-capabilities.d.ts +3 -3
- package/dist/types/wallets/in-app/core/eip5972/in-app-wallet-capabilities.d.ts.map +1 -1
- package/dist/types/wallets/in-app/core/wallet/is-in-app-signer.d.ts +6 -0
- package/dist/types/wallets/in-app/core/wallet/is-in-app-signer.d.ts.map +1 -0
- package/dist/types/wallets/smart/lib/smart-wallet-capabilities.d.ts +2 -2
- package/dist/types/wallets/smart/lib/smart-wallet-capabilities.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/exports/react.native.ts +6 -3
- package/src/exports/react.ts +6 -3
- package/src/exports/wallets/eip5792.ts +5 -3
- package/src/extensions/erc20/read/getCurrencyMetadata.ts +2 -2
- package/src/react/core/hooks/wallets/useCapabilities.ts +6 -6
- package/src/react/core/hooks/wallets/useSendAndConfirmCalls.ts +114 -0
- package/src/react/core/hooks/wallets/useSendCalls.ts +33 -50
- package/src/react/core/hooks/wallets/useWaitForCallsReceipt.ts +43 -0
- package/src/react/core/providers/thirdweb-provider.tsx +4 -3
- package/src/react/native/ui/connect/ConnectButton.tsx +4 -1
- package/src/react/web/ui/ConnectWallet/ConnectButton.tsx +11 -3
- package/src/react/web/ui/ConnectWallet/Modal/ConnectEmbed.tsx +1 -0
- package/src/react/web/ui/ConnectWallet/screens/Buy/fiat/OnRampScreen.tsx +1 -21
- package/src/react/web/ui/PayEmbed.tsx +15 -1
- package/src/version.ts +1 -1
- package/src/wallets/coinbase/coinbase-web.ts +6 -117
- package/src/wallets/connection/autoConnectCore.ts +33 -12
- package/src/wallets/connection/types.ts +10 -0
- package/src/wallets/eip5792/get-calls-status.test.ts +27 -33
- package/src/wallets/eip5792/get-calls-status.ts +68 -19
- package/src/wallets/eip5792/get-capabilities.test.ts +10 -10
- package/src/wallets/eip5792/get-capabilities.ts +33 -11
- package/src/wallets/eip5792/send-and-confirm-calls.ts +48 -0
- package/src/wallets/eip5792/send-calls.test.ts +7 -7
- package/src/wallets/eip5792/send-calls.ts +43 -21
- package/src/wallets/eip5792/show-calls-status.test.ts +3 -3
- package/src/wallets/eip5792/show-calls-status.ts +13 -12
- package/src/wallets/eip5792/types.ts +43 -4
- package/src/wallets/eip5792/{wait-for-bundle.test.ts → wait-for-calls-receipt.test.ts} +19 -9
- package/src/wallets/eip5792/{wait-for-bundle.ts → wait-for-calls-receipt.ts} +26 -16
- package/src/wallets/in-app/core/eip5972/in-app-wallet-calls.ts +17 -16
- package/src/wallets/in-app/core/eip5972/in-app-wallet-capabilities.ts +14 -3
- package/src/wallets/in-app/core/wallet/is-in-app-signer.ts +21 -0
- package/src/wallets/smart/lib/smart-wallet-capabilities.ts +5 -2
- package/dist/cjs/react/core/hooks/wallets/useCallsStatus.js +0 -41
- package/dist/cjs/react/core/hooks/wallets/useCallsStatus.js.map +0 -1
- package/dist/cjs/wallets/eip5792/wait-for-bundle.js.map +0 -1
- package/dist/esm/react/core/hooks/wallets/useCallsStatus.js +0 -38
- package/dist/esm/react/core/hooks/wallets/useCallsStatus.js.map +0 -1
- package/dist/esm/wallets/eip5792/wait-for-bundle.js.map +0 -1
- package/dist/types/react/core/hooks/wallets/useCallsStatus.d.ts +0 -26
- package/dist/types/react/core/hooks/wallets/useCallsStatus.d.ts.map +0 -1
- package/dist/types/wallets/eip5792/wait-for-bundle.d.ts.map +0 -1
- package/src/react/core/hooks/wallets/useCallsStatus.ts +0 -48
@@ -124,8 +124,8 @@ describe.sequential("in-app wallet", async () => {
|
|
124
124
|
paymasterService: {
|
125
125
|
supported: false,
|
126
126
|
},
|
127
|
-
|
128
|
-
|
127
|
+
atomic: {
|
128
|
+
status: "unsupported",
|
129
129
|
},
|
130
130
|
},
|
131
131
|
});
|
@@ -167,8 +167,8 @@ describe.sequential("in-app wallet", async () => {
|
|
167
167
|
paymasterService: {
|
168
168
|
supported: true,
|
169
169
|
},
|
170
|
-
|
171
|
-
|
170
|
+
atomic: {
|
171
|
+
status: "supported",
|
172
172
|
},
|
173
173
|
},
|
174
174
|
});
|
@@ -196,8 +196,8 @@ describe.sequential("in-app wallet", async () => {
|
|
196
196
|
paymasterService: {
|
197
197
|
supported: false,
|
198
198
|
},
|
199
|
-
|
200
|
-
|
199
|
+
atomic: {
|
200
|
+
status: "supported",
|
201
201
|
},
|
202
202
|
},
|
203
203
|
});
|
@@ -259,8 +259,8 @@ describe.sequential("smart wallet", async () => {
|
|
259
259
|
paymasterService: {
|
260
260
|
supported: true,
|
261
261
|
},
|
262
|
-
|
263
|
-
|
262
|
+
atomic: {
|
263
|
+
status: "supported",
|
264
264
|
},
|
265
265
|
},
|
266
266
|
});
|
@@ -280,8 +280,8 @@ describe.sequential("smart wallet", async () => {
|
|
280
280
|
|
281
281
|
expect(capabilities).toEqual({
|
282
282
|
[FORKED_ETHEREUM_CHAIN.id]: {
|
283
|
-
|
284
|
-
|
283
|
+
atomic: {
|
284
|
+
status: "supported",
|
285
285
|
},
|
286
286
|
paymasterService: {
|
287
287
|
supported: false,
|
@@ -1,8 +1,12 @@
|
|
1
1
|
import { getAddress } from "../../utils/address.js";
|
2
2
|
import type { Prettify } from "../../utils/type-utils.js";
|
3
|
-
import {
|
3
|
+
import {
|
4
|
+
type CoinbaseWalletCreationOptions,
|
5
|
+
isCoinbaseSDKWallet,
|
6
|
+
} from "../coinbase/coinbase-web.js";
|
4
7
|
import { isInAppWallet } from "../in-app/core/wallet/index.js";
|
5
8
|
import { getInjectedProvider } from "../injected/index.js";
|
9
|
+
import type { Ethereum } from "../interfaces/ethereum.js";
|
6
10
|
import type { Wallet } from "../interfaces/wallet.js";
|
7
11
|
import { isWalletConnect } from "../wallet-connect/controller.js";
|
8
12
|
import type { WalletId } from "../wallet-types.js";
|
@@ -10,6 +14,7 @@ import type { WalletCapabilities, WalletCapabilitiesRecord } from "./types.js";
|
|
10
14
|
|
11
15
|
export type GetCapabilitiesOptions<ID extends WalletId = WalletId> = {
|
12
16
|
wallet: Wallet<ID>;
|
17
|
+
chainId?: number;
|
13
18
|
};
|
14
19
|
|
15
20
|
export type GetCapabilitiesResult = Prettify<
|
@@ -38,6 +43,7 @@ export type GetCapabilitiesResult = Prettify<
|
|
38
43
|
*/
|
39
44
|
export async function getCapabilities<const ID extends WalletId = WalletId>({
|
40
45
|
wallet,
|
46
|
+
chainId,
|
41
47
|
}: GetCapabilitiesOptions<ID>): Promise<GetCapabilitiesResult> {
|
42
48
|
const account = wallet.getAccount();
|
43
49
|
if (!account) {
|
@@ -60,13 +66,6 @@ export async function getCapabilities<const ID extends WalletId = WalletId>({
|
|
60
66
|
return inAppWalletGetCapabilities({ wallet });
|
61
67
|
}
|
62
68
|
|
63
|
-
if (isCoinbaseSDKWallet(wallet)) {
|
64
|
-
const { coinbaseSDKWalletGetCapabilities } = await import(
|
65
|
-
"../coinbase/coinbase-web.js"
|
66
|
-
);
|
67
|
-
return coinbaseSDKWalletGetCapabilities({ wallet });
|
68
|
-
}
|
69
|
-
|
70
69
|
// TODO: Add Wallet Connect support
|
71
70
|
if (isWalletConnect(wallet)) {
|
72
71
|
return {
|
@@ -74,14 +73,37 @@ export async function getCapabilities<const ID extends WalletId = WalletId>({
|
|
74
73
|
};
|
75
74
|
}
|
76
75
|
|
77
|
-
|
78
|
-
|
76
|
+
let provider: Ethereum;
|
77
|
+
if (isCoinbaseSDKWallet(wallet)) {
|
78
|
+
const { getCoinbaseWebProvider } = await import(
|
79
|
+
"../coinbase/coinbase-web.js"
|
80
|
+
);
|
81
|
+
const config = wallet.getConfig() as CoinbaseWalletCreationOptions;
|
82
|
+
provider = (await getCoinbaseWebProvider(config)) as Ethereum;
|
83
|
+
} else {
|
84
|
+
provider = getInjectedProvider(wallet.id);
|
85
|
+
}
|
79
86
|
|
80
87
|
try {
|
81
|
-
|
88
|
+
const result = await provider.request({
|
82
89
|
method: "wallet_getCapabilities",
|
83
90
|
params: [getAddress(account.address)],
|
84
91
|
});
|
92
|
+
const capabilities = {} as WalletCapabilitiesRecord<
|
93
|
+
WalletCapabilities,
|
94
|
+
number
|
95
|
+
>;
|
96
|
+
for (const [chainId, capabilities_] of Object.entries(result)) {
|
97
|
+
capabilities[Number(chainId)] = {};
|
98
|
+
const capabilitiesCopy = {} as WalletCapabilities;
|
99
|
+
for (const [key, value] of Object.entries(capabilities_)) {
|
100
|
+
capabilitiesCopy[key] = value;
|
101
|
+
}
|
102
|
+
capabilities[Number(chainId)] = capabilitiesCopy;
|
103
|
+
}
|
104
|
+
return (
|
105
|
+
typeof chainId === "number" ? capabilities[chainId] : capabilities
|
106
|
+
) as never;
|
85
107
|
} catch (error: unknown) {
|
86
108
|
if (/unsupport|not support|not available/i.test((error as Error).message)) {
|
87
109
|
return {
|
@@ -0,0 +1,48 @@
|
|
1
|
+
import type { WalletId } from "../wallet-types.js";
|
2
|
+
import { type SendCallsOptions, sendCalls } from "./send-calls.js";
|
3
|
+
import type { GetCallsStatusResponse } from "./types.js";
|
4
|
+
import { waitForCallsReceipt } from "./wait-for-calls-receipt.js";
|
5
|
+
|
6
|
+
/**
|
7
|
+
* Send and confirm calls in a single transaction.
|
8
|
+
*
|
9
|
+
* This is a convenience function that sends the calls with `sendCalls` and then waits for the receipts with `waitForCallsReceipt`.
|
10
|
+
*
|
11
|
+
* @param options - The options for sending and confirming calls.
|
12
|
+
* @returns The receipts of the calls.
|
13
|
+
* @example
|
14
|
+
* ```ts
|
15
|
+
* const call1 = approve({
|
16
|
+
* contract: USDT_CONTRACT,
|
17
|
+
* amount: 100,
|
18
|
+
* spender: "0x2a4f24F935Eb178e3e7BA9B53A5Ee6d8407C0709",
|
19
|
+
* });
|
20
|
+
* const call2 = transfer({
|
21
|
+
* contract: USDT_CONTRACT,
|
22
|
+
* to: "0x2a4f24F935Eb178e3e7BA9B53A5Ee6d8407C0709",
|
23
|
+
* amount: 100,
|
24
|
+
* });
|
25
|
+
* const result = await sendAndConfirmCalls({
|
26
|
+
* calls: [call1, call2],
|
27
|
+
* wallet: wallet,
|
28
|
+
* });
|
29
|
+
* console.log("Transaction receipts:", result.receipts);
|
30
|
+
* ```
|
31
|
+
* @extension EIP5792
|
32
|
+
* @beta
|
33
|
+
*/
|
34
|
+
export async function sendAndConfirmCalls<const ID extends WalletId>(
|
35
|
+
options: SendCallsOptions<ID> & {
|
36
|
+
/**
|
37
|
+
* The maximum number of blocks to wait for the calls to be confirmed.
|
38
|
+
* @defaultValue 100
|
39
|
+
*/
|
40
|
+
maxBlocksWaitTime?: number;
|
41
|
+
},
|
42
|
+
): Promise<GetCallsStatusResponse> {
|
43
|
+
const sendCallsResult = await sendCalls(options);
|
44
|
+
return waitForCallsReceipt({
|
45
|
+
...sendCallsResult,
|
46
|
+
maxBlocksWaitTime: options.maxBlocksWaitTime,
|
47
|
+
});
|
48
|
+
}
|
@@ -111,7 +111,7 @@ describe.sequential("injected wallet", () => {
|
|
111
111
|
|
112
112
|
const result = await sendCalls({ wallet, ...SEND_CALLS_OPTIONS });
|
113
113
|
|
114
|
-
expect(result).toEqual("0x123456");
|
114
|
+
expect(result.id).toEqual("0x123456");
|
115
115
|
expect(mocks.injectedRequest).toHaveBeenCalledWith({
|
116
116
|
method: "wallet_sendCalls",
|
117
117
|
params: [
|
@@ -132,7 +132,7 @@ describe.sequential("injected wallet", () => {
|
|
132
132
|
capabilities: undefined,
|
133
133
|
chainId: numberToHex(ANVIL_CHAIN.id),
|
134
134
|
from: TEST_ACCOUNT_A.address,
|
135
|
-
version: "
|
135
|
+
version: "2.0.0",
|
136
136
|
},
|
137
137
|
],
|
138
138
|
});
|
@@ -159,7 +159,7 @@ describe.sequential("injected wallet", () => {
|
|
159
159
|
calls: [preparedTx, preparedTx2],
|
160
160
|
});
|
161
161
|
|
162
|
-
expect(result).toEqual("0x123456");
|
162
|
+
expect(result.id).toEqual("0x123456");
|
163
163
|
expect(mocks.injectedRequest).toHaveBeenCalledWith({
|
164
164
|
method: "wallet_sendCalls",
|
165
165
|
params: [
|
@@ -180,7 +180,7 @@ describe.sequential("injected wallet", () => {
|
|
180
180
|
capabilities: undefined,
|
181
181
|
chainId: numberToHex(ANVIL_CHAIN.id),
|
182
182
|
from: TEST_ACCOUNT_A.address,
|
183
|
-
version: "
|
183
|
+
version: "2.0.0",
|
184
184
|
},
|
185
185
|
],
|
186
186
|
});
|
@@ -194,7 +194,7 @@ describe.sequential("injected wallet", () => {
|
|
194
194
|
...SEND_CALLS_OPTIONS,
|
195
195
|
});
|
196
196
|
|
197
|
-
expect(result).toEqual("0x123456");
|
197
|
+
expect(result.id).toEqual("0x123456");
|
198
198
|
expect(mocks.injectedRequest).toHaveBeenCalledWith({
|
199
199
|
method: "wallet_sendCalls",
|
200
200
|
params: [
|
@@ -215,7 +215,7 @@ describe.sequential("injected wallet", () => {
|
|
215
215
|
capabilities: undefined,
|
216
216
|
chainId: numberToHex(sepolia.id),
|
217
217
|
from: TEST_ACCOUNT_A.address,
|
218
|
-
version: "
|
218
|
+
version: "2.0.0",
|
219
219
|
},
|
220
220
|
],
|
221
221
|
});
|
@@ -231,7 +231,7 @@ describe.sequential("injected wallet", () => {
|
|
231
231
|
});
|
232
232
|
|
233
233
|
await expect(promise).rejects.toMatchInlineSnapshot(
|
234
|
-
|
234
|
+
`[Error: io.metamask errored calling wallet_sendCalls, with error: {"code":-32601,"message":"some nonsense the wallet sends us about not supporting"}]`,
|
235
235
|
);
|
236
236
|
});
|
237
237
|
});
|
@@ -6,14 +6,19 @@ import { encode } from "../../transaction/actions/encode.js";
|
|
6
6
|
import type { PreparedTransaction } from "../../transaction/prepare-transaction.js";
|
7
7
|
import { type Address, getAddress } from "../../utils/address.js";
|
8
8
|
import { type Hex, numberToHex } from "../../utils/encoding/hex.js";
|
9
|
+
import { stringify } from "../../utils/json.js";
|
9
10
|
import {
|
10
11
|
type PromisedObject,
|
11
12
|
resolvePromisedValue,
|
12
13
|
} from "../../utils/promise/resolve-promised-value.js";
|
13
|
-
import type { OneOf } from "../../utils/type-utils.js";
|
14
|
-
import {
|
14
|
+
import type { OneOf, Prettify } from "../../utils/type-utils.js";
|
15
|
+
import {
|
16
|
+
type CoinbaseWalletCreationOptions,
|
17
|
+
isCoinbaseSDKWallet,
|
18
|
+
} from "../coinbase/coinbase-web.js";
|
15
19
|
import { isInAppWallet } from "../in-app/core/wallet/index.js";
|
16
20
|
import { getInjectedProvider } from "../injected/index.js";
|
21
|
+
import type { Ethereum } from "../interfaces/ethereum.js";
|
17
22
|
import type { Wallet } from "../interfaces/wallet.js";
|
18
23
|
import { isSmartWallet } from "../smart/index.js";
|
19
24
|
import { isWalletConnect } from "../wallet-connect/controller.js";
|
@@ -44,16 +49,21 @@ export type SendCallsOptions<
|
|
44
49
|
ID extends WalletId = WalletId,
|
45
50
|
abi extends Abi = [],
|
46
51
|
abiFunction extends AbiFunction = AbiFunction,
|
47
|
-
> = {
|
52
|
+
> = Prettify<{
|
48
53
|
wallet: Wallet<ID>;
|
49
54
|
calls: PreparedSendCall<abi, abiFunction>[];
|
50
55
|
capabilities?: WalletSendCallsParameters[number]["capabilities"];
|
51
56
|
version?: WalletSendCallsParameters[number]["version"];
|
52
57
|
chain?: Chain;
|
53
58
|
atomicRequired?: boolean;
|
54
|
-
}
|
59
|
+
}>;
|
55
60
|
|
56
|
-
export type SendCallsResult =
|
61
|
+
export type SendCallsResult = Prettify<{
|
62
|
+
id: WalletSendCallsId;
|
63
|
+
client: ThirdwebClient;
|
64
|
+
chain: Chain;
|
65
|
+
wallet: Wallet;
|
66
|
+
}>;
|
57
67
|
|
58
68
|
/**
|
59
69
|
* Send [EIP-5792](https://eips.ethereum.org/EIPS/eip-5792) calls to a wallet.
|
@@ -81,6 +91,7 @@ export type SendCallsResult = WalletSendCallsId;
|
|
81
91
|
*
|
82
92
|
* const client = createThirdwebClient({ clientId: ... });
|
83
93
|
* const wallet = createWallet("com.coinbase.wallet");
|
94
|
+
* await wallet.connect({ client });
|
84
95
|
*
|
85
96
|
* const sendTx1 = approve({
|
86
97
|
contract: USDT_CONTRACT,
|
@@ -110,8 +121,9 @@ export type SendCallsResult = WalletSendCallsId;
|
|
110
121
|
* }
|
111
122
|
* }
|
112
123
|
* });
|
113
|
-
* We recommend proxying any paymaster calls via an API route you setup and control.
|
114
124
|
* ```
|
125
|
+
* We recommend proxying any paymaster calls via an API route you setup and control.
|
126
|
+
*
|
115
127
|
* @extension EIP5792
|
116
128
|
*/
|
117
129
|
export async function sendCalls<const ID extends WalletId>(
|
@@ -121,7 +133,7 @@ export async function sendCalls<const ID extends WalletId>(
|
|
121
133
|
wallet,
|
122
134
|
calls,
|
123
135
|
capabilities,
|
124
|
-
version = "
|
136
|
+
version = "2.0.0",
|
125
137
|
chain = wallet.getChain(),
|
126
138
|
} = options;
|
127
139
|
|
@@ -138,12 +150,19 @@ export async function sendCalls<const ID extends WalletId>(
|
|
138
150
|
);
|
139
151
|
}
|
140
152
|
|
153
|
+
const firstCall = options.calls[0];
|
154
|
+
if (!firstCall) {
|
155
|
+
throw new Error("No calls to send");
|
156
|
+
}
|
157
|
+
const client = firstCall.client;
|
158
|
+
|
141
159
|
// These conveniently operate the same
|
142
160
|
if (isSmartWallet(wallet) || isInAppWallet(wallet)) {
|
143
161
|
const { inAppWalletSendCalls } = await import(
|
144
162
|
"../in-app/core/eip5972/in-app-wallet-calls.js"
|
145
163
|
);
|
146
|
-
|
164
|
+
const id = await inAppWalletSendCalls({ account, calls });
|
165
|
+
return { id, client, chain, wallet };
|
147
166
|
}
|
148
167
|
|
149
168
|
const preparedCalls: EIP5792Call[] = await Promise.all(
|
@@ -182,31 +201,34 @@ export async function sendCalls<const ID extends WalletId>(
|
|
182
201
|
},
|
183
202
|
];
|
184
203
|
|
204
|
+
if (isWalletConnect(wallet)) {
|
205
|
+
throw new Error("sendCalls is not yet supported for Wallet Connect");
|
206
|
+
}
|
207
|
+
|
208
|
+
let provider: Ethereum;
|
185
209
|
if (isCoinbaseSDKWallet(wallet)) {
|
186
|
-
const {
|
210
|
+
const { getCoinbaseWebProvider } = await import(
|
187
211
|
"../coinbase/coinbase-web.js"
|
188
212
|
);
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
}
|
194
|
-
|
195
|
-
if (isWalletConnect(wallet)) {
|
196
|
-
throw new Error("sendCalls is not yet supported for Wallet Connect");
|
213
|
+
const config = wallet.getConfig() as CoinbaseWalletCreationOptions;
|
214
|
+
provider = (await getCoinbaseWebProvider(config)) as Ethereum;
|
215
|
+
} else {
|
216
|
+
provider = getInjectedProvider(wallet.id);
|
197
217
|
}
|
198
218
|
|
199
|
-
// Default to injected wallet
|
200
|
-
const provider = getInjectedProvider(wallet.id);
|
201
219
|
try {
|
202
|
-
|
220
|
+
const callId = await provider.request({
|
203
221
|
method: "wallet_sendCalls",
|
204
222
|
params: injectedWalletCallParams as ViemWalletSendCallsParameters, // The viem type definition is slightly different
|
205
223
|
});
|
224
|
+
if (typeof callId === "object" && "id" in callId) {
|
225
|
+
return { id: callId.id, client, chain, wallet };
|
226
|
+
}
|
227
|
+
return { id: callId, client, chain, wallet };
|
206
228
|
} catch (error) {
|
207
229
|
if (/unsupport|not support/i.test((error as Error).message)) {
|
208
230
|
throw new Error(
|
209
|
-
`${wallet.id}
|
231
|
+
`${wallet.id} errored calling wallet_sendCalls, with error: ${error instanceof Error ? error.message : stringify(error)}`,
|
210
232
|
);
|
211
233
|
}
|
212
234
|
throw error;
|
@@ -26,7 +26,7 @@ describe.sequential("injected wallet", async () => {
|
|
26
26
|
const wallet: Wallet<typeof METAMASK> = createWallet(METAMASK);
|
27
27
|
|
28
28
|
test("should run", async () => {
|
29
|
-
await showCallsStatus({ wallet,
|
29
|
+
await showCallsStatus({ wallet, id: "test" });
|
30
30
|
|
31
31
|
expect(mocks.injectedRequest).toHaveBeenCalledWith({
|
32
32
|
method: "wallet_showCallsStatus",
|
@@ -38,7 +38,7 @@ describe.sequential("injected wallet", async () => {
|
|
38
38
|
mocks.injectedRequest.mockRejectedValue(RAW_UNSUPPORTED_ERROR);
|
39
39
|
const promise = showCallsStatus({
|
40
40
|
wallet: wallet as Wallet<InjectedSupportedWalletIds>,
|
41
|
-
|
41
|
+
id: "test",
|
42
42
|
});
|
43
43
|
|
44
44
|
await expect(promise).rejects.toMatchInlineSnapshot(
|
@@ -53,7 +53,7 @@ describe.sequential("other wallets", async () => {
|
|
53
53
|
test("do not support", async () => {
|
54
54
|
const promise = showCallsStatus({
|
55
55
|
wallet: wallet as Wallet<InjectedSupportedWalletIds>,
|
56
|
-
|
56
|
+
id: "test",
|
57
57
|
});
|
58
58
|
|
59
59
|
await expect(promise).rejects.toMatchInlineSnapshot(
|
@@ -1,6 +1,10 @@
|
|
1
|
-
import {
|
1
|
+
import {
|
2
|
+
getCoinbaseWebProvider,
|
3
|
+
isCoinbaseSDKWallet,
|
4
|
+
} from "../coinbase/coinbase-web.js";
|
2
5
|
import { isInAppWallet } from "../in-app/core/wallet/index.js";
|
3
6
|
import { getInjectedProvider } from "../injected/index.js";
|
7
|
+
import type { Ethereum } from "../interfaces/ethereum.js";
|
4
8
|
import type { Wallet } from "../interfaces/wallet.js";
|
5
9
|
import { isSmartWallet } from "../smart/index.js";
|
6
10
|
import { isWalletConnect } from "../wallet-connect/controller.js";
|
@@ -8,7 +12,7 @@ import type { WalletSendCallsId } from "./types.js";
|
|
8
12
|
|
9
13
|
type ShowCallsStatusOptions = {
|
10
14
|
wallet: Wallet;
|
11
|
-
|
15
|
+
id: WalletSendCallsId;
|
12
16
|
};
|
13
17
|
|
14
18
|
/**
|
@@ -37,7 +41,7 @@ type ShowCallsStatusOptions = {
|
|
37
41
|
*/
|
38
42
|
export async function showCallsStatus({
|
39
43
|
wallet,
|
40
|
-
|
44
|
+
id,
|
41
45
|
}: ShowCallsStatusOptions): Promise<void> {
|
42
46
|
if (
|
43
47
|
isSmartWallet(wallet) ||
|
@@ -49,21 +53,18 @@ export async function showCallsStatus({
|
|
49
53
|
);
|
50
54
|
}
|
51
55
|
|
56
|
+
let provider: Ethereum;
|
52
57
|
if (isCoinbaseSDKWallet(wallet)) {
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
return;
|
58
|
+
provider = (await getCoinbaseWebProvider(wallet.getConfig())) as Ethereum;
|
59
|
+
} else {
|
60
|
+
// Default to injected wallet
|
61
|
+
provider = getInjectedProvider(wallet.id);
|
58
62
|
}
|
59
63
|
|
60
|
-
// Default to injected wallet
|
61
|
-
const provider = getInjectedProvider(wallet.id);
|
62
|
-
|
63
64
|
try {
|
64
65
|
return await provider.request({
|
65
66
|
method: "wallet_showCallsStatus",
|
66
|
-
params: [
|
67
|
+
params: [id],
|
67
68
|
});
|
68
69
|
} catch (error: unknown) {
|
69
70
|
if (/unsupport|not support/i.test((error as Error).message)) {
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import type { Address } from "../../utils/address.js";
|
2
2
|
import type { Hex } from "../../utils/encoding/hex.js";
|
3
|
-
import type { OneOf } from "../../utils/type-utils.js";
|
3
|
+
import type { OneOf, Prettify } from "../../utils/type-utils.js";
|
4
4
|
|
5
5
|
export type WalletCapabilities = {
|
6
6
|
[capability: string]: unknown;
|
@@ -42,9 +42,48 @@ export type EIP5792Call = OneOf<
|
|
42
42
|
}
|
43
43
|
>;
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
type WalletGetCallsStatusReturnType<
|
46
|
+
numberType = Hex,
|
47
|
+
bigintType = Hex,
|
48
|
+
receiptStatus = Hex,
|
49
|
+
> = Prettify<{
|
50
|
+
atomic: boolean;
|
51
|
+
chainId: numberType;
|
52
|
+
id: string;
|
53
|
+
receipts?: WalletCallReceipt<bigintType, receiptStatus>[] | undefined;
|
54
|
+
status: number;
|
55
|
+
version: string;
|
56
|
+
}>;
|
57
|
+
|
58
|
+
export type GetCallsStatusResponse = Prettify<
|
59
|
+
Omit<
|
60
|
+
WalletGetCallsStatusReturnType<number, bigint, "success" | "reverted">,
|
61
|
+
"status"
|
62
|
+
> & {
|
63
|
+
statusCode: number;
|
64
|
+
status: "pending" | "success" | "failure" | undefined;
|
65
|
+
}
|
66
|
+
>;
|
67
|
+
|
68
|
+
export type GetCallsStatusRawResponse = {
|
69
|
+
version: string;
|
70
|
+
id: `0x${string}`;
|
71
|
+
chainId: `0x${string}`;
|
72
|
+
status: number; // See "Status Codes"
|
73
|
+
atomic: boolean;
|
74
|
+
receipts?: {
|
75
|
+
logs: {
|
76
|
+
address: `0x${string}`;
|
77
|
+
data: `0x${string}`;
|
78
|
+
topics: `0x${string}`[];
|
79
|
+
}[];
|
80
|
+
status: `0x${string}`; // Hex 1 or 0 for success or failure, respectively
|
81
|
+
blockHash: `0x${string}`;
|
82
|
+
blockNumber: `0x${string}`;
|
83
|
+
gasUsed: `0x${string}`;
|
84
|
+
transactionHash: `0x${string}`;
|
85
|
+
}[];
|
86
|
+
capabilities?: Record<string, unknown>;
|
48
87
|
};
|
49
88
|
|
50
89
|
export type WalletCallReceipt<quantity = Hex, status = Hex> = {
|
@@ -3,16 +3,16 @@ import { ANVIL_CHAIN } from "../../../test/src/chains.js";
|
|
3
3
|
import { TEST_CLIENT } from "../../../test/src/test-clients.js";
|
4
4
|
import { TEST_ACCOUNT_A } from "../../../test/src/test-wallets.js";
|
5
5
|
import * as watchBlockNumberExports from "../../rpc/watchBlockNumber.js";
|
6
|
-
import * as getCallsStatusExports from "../../wallets/eip5792/get-calls-status.js";
|
7
6
|
import { METAMASK } from "../constants.js";
|
8
7
|
import { createWallet } from "../create-wallet.js";
|
8
|
+
import * as getCallsStatusExports from "./get-calls-status.js";
|
9
9
|
import type { GetCallsStatusResponse } from "./types.js";
|
10
|
-
import {
|
10
|
+
import { waitForCallsReceipt } from "./wait-for-calls-receipt.js";
|
11
11
|
|
12
|
-
const
|
12
|
+
const MOCK_CALL_ID = "0x1234567890abcdef";
|
13
13
|
|
14
14
|
const MOCK_SUCCESS_RECEIPT: GetCallsStatusResponse = {
|
15
|
-
status: "
|
15
|
+
status: "success",
|
16
16
|
receipts: [
|
17
17
|
{
|
18
18
|
logs: [],
|
@@ -25,11 +25,21 @@ const MOCK_SUCCESS_RECEIPT: GetCallsStatusResponse = {
|
|
25
25
|
gasUsed: 12345n,
|
26
26
|
},
|
27
27
|
],
|
28
|
+
atomic: false,
|
29
|
+
chainId: 1,
|
30
|
+
id: MOCK_CALL_ID,
|
31
|
+
version: "2.0.0",
|
32
|
+
statusCode: 200,
|
28
33
|
};
|
29
34
|
|
30
35
|
const MOCK_PENDING_RECEIPT: GetCallsStatusResponse = {
|
31
|
-
status: "
|
36
|
+
status: "pending",
|
32
37
|
receipts: [],
|
38
|
+
atomic: false,
|
39
|
+
chainId: 1,
|
40
|
+
id: MOCK_CALL_ID,
|
41
|
+
version: "2.0.0",
|
42
|
+
statusCode: 100,
|
33
43
|
};
|
34
44
|
|
35
45
|
const mockGetCallsStatus = vi.spyOn(getCallsStatusExports, "getCallsStatus");
|
@@ -61,10 +71,10 @@ describe("waitForBundle", () => {
|
|
61
71
|
mockGetCallsStatus.mockResolvedValueOnce(MOCK_SUCCESS_RECEIPT);
|
62
72
|
|
63
73
|
// can't `await` here because we still need to be able to increment the block number below
|
64
|
-
const res =
|
74
|
+
const res = waitForCallsReceipt({
|
65
75
|
chain: ANVIL_CHAIN,
|
66
76
|
client: TEST_CLIENT,
|
67
|
-
|
77
|
+
id: MOCK_CALL_ID,
|
68
78
|
wallet,
|
69
79
|
});
|
70
80
|
|
@@ -76,10 +86,10 @@ describe("waitForBundle", () => {
|
|
76
86
|
it("should reject with an error when bundle is not complete after waiting 10 blocks", async () => {
|
77
87
|
mockGetCallsStatus.mockRejectedValue(MOCK_PENDING_RECEIPT);
|
78
88
|
|
79
|
-
const result =
|
89
|
+
const result = waitForCallsReceipt({
|
80
90
|
chain: ANVIL_CHAIN,
|
81
91
|
client: TEST_CLIENT,
|
82
|
-
|
92
|
+
id: MOCK_CALL_ID,
|
83
93
|
wallet,
|
84
94
|
maxBlocksWaitTime: 10,
|
85
95
|
});
|