thirdweb 5.98.2 → 5.99.1-nightly-1985de89aae5196233789221ad06f1b6554d27fc-20250513000404

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.
Files changed (173) hide show
  1. package/dist/cjs/exports/react.js +11 -8
  2. package/dist/cjs/exports/react.js.map +1 -1
  3. package/dist/cjs/exports/react.native.js +11 -8
  4. package/dist/cjs/exports/react.native.js.map +1 -1
  5. package/dist/cjs/exports/storage.js +3 -1
  6. package/dist/cjs/exports/storage.js.map +1 -1
  7. package/dist/cjs/exports/wallets/eip5792.js +7 -3
  8. package/dist/cjs/exports/wallets/eip5792.js.map +1 -1
  9. package/dist/cjs/react/core/hooks/wallets/useCapabilities.js +5 -6
  10. package/dist/cjs/react/core/hooks/wallets/useCapabilities.js.map +1 -1
  11. package/dist/cjs/react/core/hooks/wallets/useSendAndConfirmCalls.js +99 -0
  12. package/dist/cjs/react/core/hooks/wallets/useSendAndConfirmCalls.js.map +1 -0
  13. package/dist/cjs/react/core/hooks/wallets/useSendCalls.js +32 -40
  14. package/dist/cjs/react/core/hooks/wallets/useSendCalls.js.map +1 -1
  15. package/dist/cjs/react/core/hooks/wallets/useWaitForCallsReceipt.js +38 -0
  16. package/dist/cjs/react/core/hooks/wallets/useWaitForCallsReceipt.js.map +1 -0
  17. package/dist/cjs/react/core/providers/thirdweb-provider.js +4 -3
  18. package/dist/cjs/react/core/providers/thirdweb-provider.js.map +1 -1
  19. package/dist/cjs/utils/storage/inMemoryStorage.js +16 -0
  20. package/dist/cjs/utils/storage/inMemoryStorage.js.map +1 -0
  21. package/dist/cjs/version.js +1 -1
  22. package/dist/cjs/version.js.map +1 -1
  23. package/dist/cjs/wallets/coinbase/coinbase-web.js +2 -85
  24. package/dist/cjs/wallets/coinbase/coinbase-web.js.map +1 -1
  25. package/dist/cjs/wallets/eip5792/get-calls-status.js +54 -15
  26. package/dist/cjs/wallets/eip5792/get-calls-status.js.map +1 -1
  27. package/dist/cjs/wallets/eip5792/get-capabilities.js +21 -8
  28. package/dist/cjs/wallets/eip5792/get-capabilities.js.map +1 -1
  29. package/dist/cjs/wallets/eip5792/send-and-confirm-calls.js +41 -0
  30. package/dist/cjs/wallets/eip5792/send-and-confirm-calls.js.map +1 -0
  31. package/dist/cjs/wallets/eip5792/send-calls.js +27 -14
  32. package/dist/cjs/wallets/eip5792/send-calls.js.map +1 -1
  33. package/dist/cjs/wallets/eip5792/show-calls-status.js +8 -7
  34. package/dist/cjs/wallets/eip5792/show-calls-status.js.map +1 -1
  35. package/dist/cjs/wallets/eip5792/{wait-for-bundle.js → wait-for-calls-receipt.js} +23 -10
  36. package/dist/cjs/wallets/eip5792/wait-for-calls-receipt.js.map +1 -0
  37. package/dist/cjs/wallets/in-app/core/eip5972/in-app-wallet-calls.js +15 -10
  38. package/dist/cjs/wallets/in-app/core/eip5972/in-app-wallet-calls.js.map +1 -1
  39. package/dist/cjs/wallets/in-app/core/eip5972/in-app-wallet-capabilities.js +13 -3
  40. package/dist/cjs/wallets/in-app/core/eip5972/in-app-wallet-capabilities.js.map +1 -1
  41. package/dist/cjs/wallets/in-app/web/in-app.js +5 -1
  42. package/dist/cjs/wallets/in-app/web/in-app.js.map +1 -1
  43. package/dist/cjs/wallets/smart/lib/smart-wallet-capabilities.js +4 -2
  44. package/dist/cjs/wallets/smart/lib/smart-wallet-capabilities.js.map +1 -1
  45. package/dist/esm/exports/react.js +5 -3
  46. package/dist/esm/exports/react.js.map +1 -1
  47. package/dist/esm/exports/react.native.js +5 -3
  48. package/dist/esm/exports/react.native.js.map +1 -1
  49. package/dist/esm/exports/storage.js +1 -0
  50. package/dist/esm/exports/storage.js.map +1 -1
  51. package/dist/esm/exports/wallets/eip5792.js +3 -1
  52. package/dist/esm/exports/wallets/eip5792.js.map +1 -1
  53. package/dist/esm/react/core/hooks/wallets/useCapabilities.js +5 -6
  54. package/dist/esm/react/core/hooks/wallets/useCapabilities.js.map +1 -1
  55. package/dist/esm/react/core/hooks/wallets/useSendAndConfirmCalls.js +96 -0
  56. package/dist/esm/react/core/hooks/wallets/useSendAndConfirmCalls.js.map +1 -0
  57. package/dist/esm/react/core/hooks/wallets/useSendCalls.js +32 -40
  58. package/dist/esm/react/core/hooks/wallets/useSendCalls.js.map +1 -1
  59. package/dist/esm/react/core/hooks/wallets/useWaitForCallsReceipt.js +35 -0
  60. package/dist/esm/react/core/hooks/wallets/useWaitForCallsReceipt.js.map +1 -0
  61. package/dist/esm/react/core/providers/thirdweb-provider.js +4 -3
  62. package/dist/esm/react/core/providers/thirdweb-provider.js.map +1 -1
  63. package/dist/esm/utils/storage/inMemoryStorage.js +13 -0
  64. package/dist/esm/utils/storage/inMemoryStorage.js.map +1 -0
  65. package/dist/esm/version.js +1 -1
  66. package/dist/esm/version.js.map +1 -1
  67. package/dist/esm/wallets/coinbase/coinbase-web.js +2 -81
  68. package/dist/esm/wallets/coinbase/coinbase-web.js.map +1 -1
  69. package/dist/esm/wallets/eip5792/get-calls-status.js +54 -15
  70. package/dist/esm/wallets/eip5792/get-calls-status.js.map +1 -1
  71. package/dist/esm/wallets/eip5792/get-capabilities.js +22 -9
  72. package/dist/esm/wallets/eip5792/get-capabilities.js.map +1 -1
  73. package/dist/esm/wallets/eip5792/send-and-confirm-calls.js +38 -0
  74. package/dist/esm/wallets/eip5792/send-and-confirm-calls.js.map +1 -0
  75. package/dist/esm/wallets/eip5792/send-calls.js +28 -15
  76. package/dist/esm/wallets/eip5792/send-calls.js.map +1 -1
  77. package/dist/esm/wallets/eip5792/show-calls-status.js +9 -8
  78. package/dist/esm/wallets/eip5792/show-calls-status.js.map +1 -1
  79. package/dist/esm/wallets/eip5792/{wait-for-bundle.js → wait-for-calls-receipt.js} +22 -9
  80. package/dist/esm/wallets/eip5792/wait-for-calls-receipt.js.map +1 -0
  81. package/dist/esm/wallets/in-app/core/eip5972/in-app-wallet-calls.js +15 -10
  82. package/dist/esm/wallets/in-app/core/eip5972/in-app-wallet-calls.js.map +1 -1
  83. package/dist/esm/wallets/in-app/core/eip5972/in-app-wallet-capabilities.js +13 -3
  84. package/dist/esm/wallets/in-app/core/eip5972/in-app-wallet-capabilities.js.map +1 -1
  85. package/dist/esm/wallets/in-app/web/in-app.js +5 -1
  86. package/dist/esm/wallets/in-app/web/in-app.js.map +1 -1
  87. package/dist/esm/wallets/smart/lib/smart-wallet-capabilities.js +4 -2
  88. package/dist/esm/wallets/smart/lib/smart-wallet-capabilities.js.map +1 -1
  89. package/dist/types/exports/react.d.ts +4 -3
  90. package/dist/types/exports/react.d.ts.map +1 -1
  91. package/dist/types/exports/react.native.d.ts +4 -3
  92. package/dist/types/exports/react.native.d.ts.map +1 -1
  93. package/dist/types/exports/storage.d.ts +1 -0
  94. package/dist/types/exports/storage.d.ts.map +1 -1
  95. package/dist/types/exports/wallets/eip5792.d.ts +3 -1
  96. package/dist/types/exports/wallets/eip5792.d.ts.map +1 -1
  97. package/dist/types/react/core/hooks/wallets/useCapabilities.d.ts +1 -0
  98. package/dist/types/react/core/hooks/wallets/useCapabilities.d.ts.map +1 -1
  99. package/dist/types/react/core/hooks/wallets/useSendAndConfirmCalls.d.ts +66 -0
  100. package/dist/types/react/core/hooks/wallets/useSendAndConfirmCalls.d.ts.map +1 -0
  101. package/dist/types/react/core/hooks/wallets/useSendCalls.d.ts +8 -11
  102. package/dist/types/react/core/hooks/wallets/useSendCalls.d.ts.map +1 -1
  103. package/dist/types/react/core/hooks/wallets/useWaitForCallsReceipt.d.ts +32 -0
  104. package/dist/types/react/core/hooks/wallets/useWaitForCallsReceipt.d.ts.map +1 -0
  105. package/dist/types/react/core/providers/thirdweb-provider.d.ts.map +1 -1
  106. package/dist/types/utils/storage/inMemoryStorage.d.ts +3 -0
  107. package/dist/types/utils/storage/inMemoryStorage.d.ts.map +1 -0
  108. package/dist/types/version.d.ts +1 -1
  109. package/dist/types/version.d.ts.map +1 -1
  110. package/dist/types/wallets/coinbase/coinbase-web.d.ts +2 -30
  111. package/dist/types/wallets/coinbase/coinbase-web.d.ts.map +1 -1
  112. package/dist/types/wallets/eip5792/get-calls-status.d.ts +5 -6
  113. package/dist/types/wallets/eip5792/get-calls-status.d.ts.map +1 -1
  114. package/dist/types/wallets/eip5792/get-capabilities.d.ts +2 -1
  115. package/dist/types/wallets/eip5792/get-capabilities.d.ts.map +1 -1
  116. package/dist/types/wallets/eip5792/send-and-confirm-calls.d.ts +39 -0
  117. package/dist/types/wallets/eip5792/send-and-confirm-calls.d.ts.map +1 -0
  118. package/dist/types/wallets/eip5792/send-calls.d.ts +12 -5
  119. package/dist/types/wallets/eip5792/send-calls.d.ts.map +1 -1
  120. package/dist/types/wallets/eip5792/show-calls-status.d.ts +2 -2
  121. package/dist/types/wallets/eip5792/show-calls-status.d.ts.map +1 -1
  122. package/dist/types/wallets/eip5792/types.d.ts +33 -4
  123. package/dist/types/wallets/eip5792/types.d.ts.map +1 -1
  124. package/dist/types/wallets/eip5792/{wait-for-bundle.d.ts → wait-for-calls-receipt.d.ts} +21 -9
  125. package/dist/types/wallets/eip5792/wait-for-calls-receipt.d.ts.map +1 -0
  126. package/dist/types/wallets/in-app/core/eip5972/in-app-wallet-calls.d.ts +3 -3
  127. package/dist/types/wallets/in-app/core/eip5972/in-app-wallet-calls.d.ts.map +1 -1
  128. package/dist/types/wallets/in-app/core/eip5972/in-app-wallet-capabilities.d.ts +3 -3
  129. package/dist/types/wallets/in-app/core/eip5972/in-app-wallet-capabilities.d.ts.map +1 -1
  130. package/dist/types/wallets/in-app/web/in-app.d.ts +5 -1
  131. package/dist/types/wallets/in-app/web/in-app.d.ts.map +1 -1
  132. package/dist/types/wallets/smart/lib/smart-wallet-capabilities.d.ts +2 -2
  133. package/dist/types/wallets/smart/lib/smart-wallet-capabilities.d.ts.map +1 -1
  134. package/package.json +1 -1
  135. package/src/exports/react.native.ts +6 -3
  136. package/src/exports/react.ts +6 -3
  137. package/src/exports/storage.ts +1 -0
  138. package/src/exports/wallets/eip5792.ts +5 -3
  139. package/src/react/core/hooks/wallets/useCapabilities.ts +6 -6
  140. package/src/react/core/hooks/wallets/useSendAndConfirmCalls.ts +114 -0
  141. package/src/react/core/hooks/wallets/useSendCalls.ts +33 -50
  142. package/src/react/core/hooks/wallets/useWaitForCallsReceipt.ts +43 -0
  143. package/src/react/core/providers/thirdweb-provider.tsx +4 -3
  144. package/src/utils/storage/inMemoryStorage.ts +15 -0
  145. package/src/version.ts +1 -1
  146. package/src/wallets/coinbase/coinbase-web.ts +6 -117
  147. package/src/wallets/eip5792/get-calls-status.test.ts +27 -33
  148. package/src/wallets/eip5792/get-calls-status.ts +68 -19
  149. package/src/wallets/eip5792/get-capabilities.test.ts +10 -10
  150. package/src/wallets/eip5792/get-capabilities.ts +33 -11
  151. package/src/wallets/eip5792/send-and-confirm-calls.ts +48 -0
  152. package/src/wallets/eip5792/send-calls.test.ts +7 -7
  153. package/src/wallets/eip5792/send-calls.ts +43 -21
  154. package/src/wallets/eip5792/show-calls-status.test.ts +3 -3
  155. package/src/wallets/eip5792/show-calls-status.ts +13 -12
  156. package/src/wallets/eip5792/types.ts +43 -4
  157. package/src/wallets/eip5792/{wait-for-bundle.test.ts → wait-for-calls-receipt.test.ts} +19 -9
  158. package/src/wallets/eip5792/{wait-for-bundle.ts → wait-for-calls-receipt.ts} +26 -16
  159. package/src/wallets/in-app/core/eip5972/in-app-wallet-calls.ts +17 -16
  160. package/src/wallets/in-app/core/eip5972/in-app-wallet-capabilities.ts +14 -3
  161. package/src/wallets/in-app/web/in-app.ts +5 -1
  162. package/src/wallets/in-app/web/lib/in-app-backend.test.ts +27 -0
  163. package/src/wallets/smart/lib/smart-wallet-capabilities.ts +5 -2
  164. package/dist/cjs/react/core/hooks/wallets/useCallsStatus.js +0 -41
  165. package/dist/cjs/react/core/hooks/wallets/useCallsStatus.js.map +0 -1
  166. package/dist/cjs/wallets/eip5792/wait-for-bundle.js.map +0 -1
  167. package/dist/esm/react/core/hooks/wallets/useCallsStatus.js +0 -38
  168. package/dist/esm/react/core/hooks/wallets/useCallsStatus.js.map +0 -1
  169. package/dist/esm/wallets/eip5792/wait-for-bundle.js.map +0 -1
  170. package/dist/types/react/core/hooks/wallets/useCallsStatus.d.ts +0 -26
  171. package/dist/types/react/core/hooks/wallets/useCallsStatus.d.ts.map +0 -1
  172. package/dist/types/wallets/eip5792/wait-for-bundle.d.ts.map +0 -1
  173. package/src/react/core/hooks/wallets/useCallsStatus.ts +0 -48
@@ -0,0 +1,114 @@
1
+ import {
2
+ type UseMutationResult,
3
+ useMutation,
4
+ useQueryClient,
5
+ } from "@tanstack/react-query";
6
+ import { sendAndConfirmCalls } from "../../../../wallets/eip5792/send-and-confirm-calls.js";
7
+ import type { SendCallsOptions } from "../../../../wallets/eip5792/send-calls.js";
8
+ import type { GetCallsStatusResponse } from "../../../../wallets/eip5792/types.js";
9
+ import type { Wallet } from "../../../../wallets/interfaces/wallet.js";
10
+ import { invalidateWalletBalance } from "../../providers/invalidateWalletBalance.js";
11
+ import { useActiveWallet } from "./useActiveWallet.js";
12
+
13
+ /**
14
+ * A hook to send [EIP-5792](https://eips.ethereum.org/EIPS/eip-5792) calls to a wallet.
15
+ * This hook works with all Thirdweb wallets (in-app and smart) and certain injected wallets that already support EIP-5792.
16
+ * Transactions will be batched and sponsored when those capabilities are supported, otherwise they will be sent as individual transactions.
17
+ *
18
+ * When calls are sent, all contracts that are interacted with will have their corresponding reads revalidated via React Query.
19
+ *
20
+ * This hook is dependent on the wallet's support for EIP-5792 and could fail.
21
+ * The mutation function will use your currently connected wallet by default, but you can pass it a specific wallet to use if you'd like.
22
+ *
23
+ * @returns A React Query mutation object to interact with {@link sendAndConfirmCalls}
24
+ * @throws an error if the wallet does not support EIP-5792.
25
+ * @returns The ID of the bundle of the calls.
26
+ *
27
+ * @beta
28
+ * @example
29
+ * ```tsx
30
+ * import { useSendCalls } from "thirdweb/react";
31
+ *
32
+ * const sendTx1 = approve({
33
+ contract: USDT_CONTRACT,
34
+ amount: 100,
35
+ spender: "0x33d9B8BEfE81027E2C859EDc84F5636cbb202Ed6",
36
+ });
37
+ * const sendTx2 = approve({
38
+ contract: USDT_CONTRACT,
39
+ amount: 100,
40
+ spender: "0x2a4f24F935Eb178e3e7BA9B53A5Ee6d8407C0709",
41
+ });
42
+ * const { mutate: sendCalls, data: result } = useSendAndConfirmCalls();
43
+ * await sendCalls({
44
+ * client,
45
+ * calls: [sendTx1, sendTx2],
46
+ * });
47
+ *
48
+ * console.log("Transaction hash:", result.receipts?.[0]?.transactionHash);
49
+ * ```
50
+
51
+ * Sponsor transactions with a paymaster:
52
+ * ```ts
53
+ * const { mutate: sendAndConfirmCalls, data: id } = useSendAndConfirmCalls();
54
+ * const result = await sendAndConfirmCalls({
55
+ * client,
56
+ * calls: [sendTx1, sendTx2],
57
+ * capabilities: {
58
+ * paymasterService: {
59
+ * url: `https://${CHAIN.id}.bundler.thirdweb.com/${client.clientId}`
60
+ * }
61
+ * }
62
+ * });
63
+ * console.log("Transaction hash:", result.receipts?.[0]?.transactionHash);
64
+ * ```
65
+ *
66
+ * We recommend proxying any paymaster calls via an API route you setup and control.
67
+ * @extension EIP5792
68
+ */
69
+ export function useSendAndConfirmCalls(args?: {
70
+ maxBlocksWaitTime?: number;
71
+ }): UseMutationResult<
72
+ GetCallsStatusResponse,
73
+ Error,
74
+ Omit<SendCallsOptions, "chain" | "wallet"> & { wallet?: Wallet } // Optional wallet override
75
+ > {
76
+ const activeWallet = useActiveWallet();
77
+ const queryClient = useQueryClient();
78
+
79
+ return useMutation({
80
+ mutationFn: async (options) => {
81
+ const { wallet = activeWallet } = options;
82
+ if (!wallet) {
83
+ throw new Error(
84
+ "Failed to send transactions, no connected wallet found.",
85
+ );
86
+ }
87
+
88
+ return sendAndConfirmCalls({
89
+ ...options,
90
+ wallet,
91
+ maxBlocksWaitTime: args?.maxBlocksWaitTime,
92
+ });
93
+ },
94
+ onSettled: async (_result, _error, variables) => {
95
+ // Attempt to invalidate any reads related to the sent transactions
96
+ const call = variables.calls[0];
97
+ if (!call) {
98
+ return;
99
+ }
100
+ const chain = call.__contract?.chain || call.chain;
101
+
102
+ for (const call of variables.calls) {
103
+ queryClient.invalidateQueries({
104
+ queryKey: [
105
+ "readContract",
106
+ call.__contract?.chain.id || call.chain.id,
107
+ call.__contract?.address || call.to,
108
+ ],
109
+ });
110
+ }
111
+ invalidateWalletBalance(queryClient, chain.id);
112
+ },
113
+ });
114
+ }
@@ -3,16 +3,12 @@ import {
3
3
  useMutation,
4
4
  useQueryClient,
5
5
  } from "@tanstack/react-query";
6
- import type { ThirdwebClient } from "../../../../client/client.js";
7
6
  import {
8
7
  type SendCallsOptions,
8
+ type SendCallsResult,
9
9
  sendCalls,
10
10
  } from "../../../../wallets/eip5792/send-calls.js";
11
- import type {
12
- GetCallsStatusResponse,
13
- WalletSendCallsId,
14
- } from "../../../../wallets/eip5792/types.js";
15
- import { waitForBundle } from "../../../../wallets/eip5792/wait-for-bundle.js";
11
+ import { waitForCallsReceipt } from "../../../../wallets/eip5792/wait-for-calls-receipt.js";
16
12
  import type { Wallet } from "../../../../wallets/interfaces/wallet.js";
17
13
  import { invalidateWalletBalance } from "../../providers/invalidateWalletBalance.js";
18
14
  import { useActiveWallet } from "./useActiveWallet.js";
@@ -46,7 +42,7 @@ import { useActiveWallet } from "./useActiveWallet.js";
46
42
  amount: 100,
47
43
  spender: "0x2a4f24F935Eb178e3e7BA9B53A5Ee6d8407C0709",
48
44
  });
49
- * const { mutate: sendCalls, data: bundleId } = useSendCalls({ client });
45
+ * const { mutate: sendCalls, data: id } = useSendCalls();
50
46
  * await sendCalls({
51
47
  * wallet,
52
48
  * client,
@@ -55,16 +51,19 @@ import { useActiveWallet } from "./useActiveWallet.js";
55
51
  * ```
56
52
  * Await the bundle's full confirmation:
57
53
  * ```tsx
58
- * const { mutate: sendCalls, data: bundleId } = useSendCalls({ client, waitForResult: true });
54
+ * const { mutate: sendCalls, data } = useSendCalls();
55
+ * const { data: result, isLoading } = useWaitForCallsReceipt(data);
59
56
  * await sendCalls({
60
57
  * wallet,
61
58
  * client,
62
59
  * calls: [sendTx1, sendTx2],
63
60
  * });
61
+ *
62
+ * console.log("Receipts:", result.receipts);
64
63
  * ```
65
64
  * Sponsor transactions with a paymaster:
66
65
  * ```ts
67
- * const { mutate: sendCalls, data: bundleId } = useSendCalls();
66
+ * const { mutate: sendCalls, data: id } = useSendCalls();
68
67
  * await sendCalls({
69
68
  * client,
70
69
  * calls: [sendTx1, sendTx2],
@@ -75,15 +74,11 @@ import { useActiveWallet } from "./useActiveWallet.js";
75
74
  * }
76
75
  * });
77
76
  * ```
78
- *
79
77
  * We recommend proxying any paymaster calls via an API route you setup and control.
80
78
  * @extension EIP5792
81
79
  */
82
- export function useSendCalls({
83
- client,
84
- waitForResult = true,
85
- }: { client: ThirdwebClient; waitForResult?: boolean }): UseMutationResult<
86
- GetCallsStatusResponse | WalletSendCallsId,
80
+ export function useSendCalls(): UseMutationResult<
81
+ SendCallsResult,
87
82
  Error,
88
83
  Omit<SendCallsOptions, "chain" | "wallet"> & { wallet?: Wallet } // Optional wallet override
89
84
  > {
@@ -100,52 +95,40 @@ export function useSendCalls({
100
95
  );
101
96
  }
102
97
 
103
- const callsPromise = sendCalls({ ...options, wallet });
104
- if (!waitForResult) {
105
- return callsPromise;
106
- }
107
-
108
- const result = await waitForBundle({
109
- bundleId: await callsPromise,
110
- wallet,
111
- client,
112
- chain,
113
- });
114
- return result;
98
+ return sendCalls({ ...options, wallet });
115
99
  },
116
- onSettled: async (_result, _error, variables) => {
100
+ onSettled: async (result, _error, variables) => {
117
101
  // Attempt to invalidate any reads related to the sent transactions
118
- const chain = activeWallet?.getChain();
119
- if (!_result || !activeWallet || !chain) {
102
+ if (!result) {
103
+ return;
104
+ }
105
+ const call = variables.calls[0];
106
+ if (!call) {
120
107
  return;
121
108
  }
109
+ const chain = call.__contract?.chain || call.chain;
122
110
 
123
- if (typeof _result === "string") {
124
- await waitForBundle({
125
- bundleId: _result,
126
- wallet: activeWallet,
127
- client,
128
- chain,
129
- }).catch((error) => {
111
+ waitForCallsReceipt(result)
112
+ .then(() => {
113
+ for (const call of variables.calls) {
114
+ queryClient.invalidateQueries({
115
+ queryKey: [
116
+ "readContract",
117
+ call.__contract?.chain.id || chain.id,
118
+ call.__contract?.address || call.to,
119
+ ],
120
+ });
121
+ }
122
+ invalidateWalletBalance(queryClient, chain.id);
123
+ })
124
+ .catch((error) => {
130
125
  console.error(
131
126
  "Failed to confirm sent bundle and invalidate queries",
132
- _result,
127
+ result,
133
128
  error,
134
129
  );
135
130
  return undefined;
136
131
  });
137
- }
138
-
139
- for (const call of variables.calls) {
140
- queryClient.invalidateQueries({
141
- queryKey: [
142
- "readContract",
143
- call.__contract?.chain.id,
144
- call.__contract?.address,
145
- ],
146
- });
147
- }
148
- invalidateWalletBalance(queryClient, chain.id);
149
132
  },
150
133
  });
151
134
  }
@@ -0,0 +1,43 @@
1
+ import { useQuery } from "@tanstack/react-query";
2
+ import type { SendCallsResult } from "../../../../wallets/eip5792/send-calls.js";
3
+ import { waitForCallsReceipt } from "../../../../wallets/eip5792/wait-for-calls-receipt.js";
4
+
5
+ /**
6
+ * A hook to wait for the receipt of eip5792 calls.
7
+ * @param options - The options for the hook.
8
+ * @returns A useQuery object.
9
+ * @example
10
+ * ```tsx
11
+ * const { data: receipt, isLoading } = useWaitForCallsReceipt({ id, client, chain, wallet });
12
+ * ```
13
+ *
14
+ * Example with useSendCalls:
15
+ * ```tsx
16
+ * const { mutate: sendCalls, data } = useSendCalls();
17
+ * const { data: receipt, isLoading } = useWaitForCallsReceipt(data);
18
+ * ```
19
+ * @extension EIP5792
20
+ */
21
+ export function useWaitForCallsReceipt(
22
+ args:
23
+ | (SendCallsResult & {
24
+ maxBlocksWaitTime?: number;
25
+ queryOptions?: { enabled?: boolean };
26
+ })
27
+ | undefined,
28
+ ) {
29
+ return useQuery({
30
+ queryKey: ["waitForCallsReceipt", args?.id] as const,
31
+ queryFn: async () => {
32
+ if (!args?.id) {
33
+ throw new Error("No call result provided");
34
+ }
35
+ return waitForCallsReceipt({
36
+ ...args,
37
+ maxBlocksWaitTime: args.maxBlocksWaitTime,
38
+ });
39
+ },
40
+ enabled: !!args?.id && (args?.queryOptions?.enabled ?? true),
41
+ retry: false,
42
+ });
43
+ }
@@ -46,13 +46,14 @@ export function ThirdwebProviderCore(props: {
46
46
  // invalidate any readContract queries for this chainId:contractAddress
47
47
  [
48
48
  "readContract",
49
- variables.__contract?.chain.id,
50
- variables.__contract?.address,
49
+ variables.__contract?.chain.id ||
50
+ variables.chain.id,
51
+ variables.__contract?.address || variables.to,
51
52
  ] as const,
52
53
  }),
53
54
  invalidateWalletBalance(
54
55
  queryClient,
55
- variables.__contract?.chain.id,
56
+ variables.__contract?.chain.id || variables.chain.id,
56
57
  ),
57
58
  ]);
58
59
  });
@@ -0,0 +1,15 @@
1
+ import type { AsyncStorage } from "./AsyncStorage.js";
2
+
3
+ const store = new Map<string, string>();
4
+
5
+ export const inMemoryStorage: AsyncStorage = {
6
+ getItem: async (key: string) => {
7
+ return store.get(key) ?? null;
8
+ },
9
+ setItem: async (key: string, value: string) => {
10
+ store.set(key, value);
11
+ },
12
+ removeItem: async (key: string) => {
13
+ store.delete(key);
14
+ },
15
+ };
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = "5.98.2";
1
+ export const version = "5.99.1-nightly-1985de89aae5196233789221ad06f1b6554d27fc-20250513000404";
@@ -1,14 +1,8 @@
1
1
  import type { ProviderInterface } from "@coinbase/wallet-sdk";
2
+ import type { Preference } from "@coinbase/wallet-sdk/dist/core/provider/interface.js";
2
3
  import type { Address } from "abitype";
3
4
  import * as ox__Hex from "ox/Hex";
4
5
  import * as ox__TypedData from "ox/TypedData";
5
- import type { Account, Wallet } from "../interfaces/wallet.js";
6
- import type { SendTransactionOption } from "../interfaces/wallet.js";
7
- import type { AppMetadata, DisconnectFn, SwitchChainFn } from "../types.js";
8
- import { getValidPublicRPCUrl } from "../utils/chains.js";
9
- import { normalizeChainId } from "../utils/normalizeChainId.js";
10
-
11
- import type { Preference } from "@coinbase/wallet-sdk/dist/core/provider/interface.js";
12
6
  import { trackTransaction } from "../../analytics/track/transaction.js";
13
7
  import type { Chain } from "../../chains/types.js";
14
8
  import { getCachedChain, getChainMetadata } from "../../chains/utils.js";
@@ -22,14 +16,12 @@ import {
22
16
  } from "../../utils/encoding/hex.js";
23
17
  import { parseTypedData } from "../../utils/signatures/helpers/parse-typed-data.js";
24
18
  import { COINBASE } from "../constants.js";
25
- import type {
26
- GetCallsStatusResponse,
27
- WalletCapabilities,
28
- WalletCapabilitiesRecord,
29
- WalletSendCallsId,
30
- WalletSendCallsParameters,
31
- } from "../eip5792/types.js";
19
+ import type { Account, Wallet } from "../interfaces/wallet.js";
20
+ import type { SendTransactionOption } from "../interfaces/wallet.js";
21
+ import type { AppMetadata, DisconnectFn, SwitchChainFn } from "../types.js";
22
+ import { getValidPublicRPCUrl } from "../utils/chains.js";
32
23
  import { getDefaultAppMetadata } from "../utils/defaultDappMetadata.js";
24
+ import { normalizeChainId } from "../utils/normalizeChainId.js";
33
25
  import type { WalletEmitter } from "../wallet-emitter.js";
34
26
  import type {
35
27
  CreateWalletArgs,
@@ -171,109 +163,6 @@ export function isCoinbaseSDKWallet(
171
163
  return wallet.id === COINBASE;
172
164
  }
173
165
 
174
- /**
175
- * @internal
176
- */
177
- export async function coinbaseSDKWalletGetCapabilities(args: {
178
- wallet: Wallet<typeof COINBASE>;
179
- }) {
180
- const { wallet } = args;
181
-
182
- const account = wallet.getAccount();
183
- if (!account) {
184
- return {
185
- message: `Can't get capabilities, no account connected for wallet: ${wallet.id}`,
186
- };
187
- }
188
-
189
- const config = wallet.getConfig();
190
- const provider = await getCoinbaseWebProvider(config);
191
- try {
192
- return (await provider.request({
193
- method: "wallet_getCapabilities",
194
- params: [account.address],
195
- })) as WalletCapabilitiesRecord<WalletCapabilities, number>;
196
- } catch (error: unknown) {
197
- if (/unsupport|not support/i.test((error as Error).message)) {
198
- return {
199
- message: `${wallet.id} does not support wallet_getCapabilities, reach out to them directly to request EIP-5792 support.`,
200
- };
201
- }
202
- throw error;
203
- }
204
- }
205
-
206
- /**
207
- * @internal
208
- */
209
- export async function coinbaseSDKWalletSendCalls(args: {
210
- wallet: Wallet<typeof COINBASE>;
211
- params: WalletSendCallsParameters;
212
- }) {
213
- const { wallet, params } = args;
214
-
215
- const config = wallet.getConfig();
216
- const provider = await getCoinbaseWebProvider(config);
217
-
218
- try {
219
- return (await provider.request({
220
- method: "wallet_sendCalls",
221
- params,
222
- })) as WalletSendCallsId;
223
- } catch (error) {
224
- if (/unsupport|not support/i.test((error as Error).message)) {
225
- throw new Error(
226
- `${wallet.id} does not support wallet_sendCalls, reach out to them directly to request EIP-5792 support.`,
227
- );
228
- }
229
- throw error;
230
- }
231
- }
232
-
233
- /**
234
- * @internal
235
- */
236
- export async function coinbaseSDKWalletShowCallsStatus(args: {
237
- wallet: Wallet<typeof COINBASE>;
238
- bundleId: string;
239
- }) {
240
- const { wallet, bundleId } = args;
241
-
242
- const provider = await getCoinbaseWebProvider(wallet.getConfig());
243
-
244
- try {
245
- return await provider.request({
246
- method: "wallet_showCallsStatus",
247
- params: [bundleId],
248
- });
249
- } catch (error: unknown) {
250
- if (/unsupport|not support/i.test((error as Error).message)) {
251
- throw new Error(
252
- `${wallet.id} does not support wallet_showCallsStatus, reach out to them directly to request EIP-5792 support.`,
253
- );
254
- }
255
- throw error;
256
- }
257
- }
258
-
259
- /**
260
- * @internal
261
- */
262
- export async function coinbaseSDKWalletGetCallsStatus(args: {
263
- wallet: Wallet<typeof COINBASE>;
264
- bundleId: string;
265
- }) {
266
- const { wallet, bundleId } = args;
267
-
268
- const config = wallet.getConfig();
269
- const provider = await getCoinbaseWebProvider(config);
270
-
271
- return provider.request({
272
- method: "wallet_getCallsStatus",
273
- params: [bundleId],
274
- }) as Promise<GetCallsStatusResponse>;
275
- }
276
-
277
166
  function createAccount({
278
167
  provider,
279
168
  address,
@@ -89,7 +89,7 @@ describe.sequential("injected wallet", async () => {
89
89
  const promise = getCallsStatus({
90
90
  wallet: wallet,
91
91
  client: TEST_CLIENT,
92
- bundleId: "test",
92
+ id: "test",
93
93
  });
94
94
 
95
95
  await expect(promise).rejects.toMatchInlineSnapshot(
@@ -107,17 +107,23 @@ describe.sequential("injected wallet", async () => {
107
107
  const result = await getCallsStatus({
108
108
  wallet: wallet,
109
109
  client: TEST_CLIENT,
110
- bundleId: "test",
110
+ id: "test",
111
111
  });
112
112
 
113
113
  expect(mocks.injectedRequest).toHaveBeenCalledWith({
114
114
  method: "wallet_getCallsStatus",
115
115
  params: ["test"],
116
116
  });
117
- expect(result).toEqual({
118
- status: "CONFIRMED",
119
- receipts: [],
120
- });
117
+ expect(result).toMatchInlineSnapshot(`
118
+ {
119
+ "atomic": false,
120
+ "chainId": undefined,
121
+ "receipts": [],
122
+ "status": "success",
123
+ "statusCode": 200,
124
+ "version": "2.0.0",
125
+ }
126
+ `);
121
127
  });
122
128
 
123
129
  test("without support should fail", async () => {
@@ -127,7 +133,7 @@ describe.sequential("injected wallet", async () => {
127
133
  const promise = getCallsStatus({
128
134
  wallet: wallet,
129
135
  client: TEST_CLIENT,
130
- bundleId: "test",
136
+ id: "test",
131
137
  });
132
138
 
133
139
  await expect(promise).rejects.toMatchInlineSnapshot(
@@ -152,19 +158,15 @@ describe.sequential("in-app wallet", async () => {
152
158
  });
153
159
  wallet.getChain = vi.fn().mockReturnValue(ANVIL_CHAIN);
154
160
 
155
- const bundleId = await sendCalls({
161
+ const callResult = await sendCalls({
156
162
  wallet: wallet,
157
163
  ...SEND_CALLS_OPTIONS,
158
164
  });
159
165
 
160
- const result = await getCallsStatus({
161
- wallet: wallet,
162
- client: TEST_CLIENT,
163
- bundleId,
164
- });
166
+ const result = await getCallsStatus(callResult);
165
167
 
166
- expect(result.status).toEqual("CONFIRMED");
167
- expect(result.receipts.length).toEqual(2);
168
+ expect(result.status).toEqual("success");
169
+ expect(result.receipts?.length).toEqual(2);
168
170
  });
169
171
 
170
172
  test("with smart account", async () => {
@@ -177,19 +179,15 @@ describe.sequential("in-app wallet", async () => {
177
179
  sendBatchTransaction,
178
180
  });
179
181
 
180
- const bundleId = await sendCalls({
182
+ const callResult = await sendCalls({
181
183
  wallet: wallet,
182
184
  ...SEND_CALLS_OPTIONS,
183
185
  });
184
186
 
185
- const result = await getCallsStatus({
186
- wallet: wallet,
187
- client: TEST_CLIENT,
188
- bundleId,
189
- });
187
+ const result = await getCallsStatus(callResult);
190
188
 
191
- expect(result.status).toEqual("CONFIRMED");
192
- expect(result.receipts.length).toEqual(1);
189
+ expect(result.status).toEqual("success");
190
+ expect(result.receipts?.length).toEqual(1);
193
191
  });
194
192
 
195
193
  test("with pending transaction", async () => {
@@ -202,26 +200,22 @@ describe.sequential("in-app wallet", async () => {
202
200
  sendTransaction,
203
201
  });
204
202
 
205
- const bundleId = await sendCalls({
203
+ const callResult = await sendCalls({
206
204
  wallet: wallet,
207
205
  ...SEND_CALLS_OPTIONS,
208
206
  });
209
207
 
210
- const result = await getCallsStatus({
211
- wallet: wallet,
212
- client: TEST_CLIENT,
213
- bundleId,
214
- });
208
+ const result = await getCallsStatus(callResult);
215
209
 
216
- expect(result.status).toEqual("PENDING");
217
- expect(result.receipts.length).toEqual(0);
210
+ expect(result.status).toEqual("pending");
211
+ expect(result.receipts?.length).toEqual(0);
218
212
  });
219
213
 
220
214
  test("unknown bundle id should fail", async () => {
221
215
  const promise = getCallsStatus({
222
216
  wallet: wallet,
223
217
  client: TEST_CLIENT,
224
- bundleId: "unknown",
218
+ id: "unknown",
225
219
  });
226
220
 
227
221
  await expect(promise).rejects.toMatchInlineSnapshot(
@@ -235,7 +229,7 @@ describe.sequential("in-app wallet", async () => {
235
229
  const promise = getCallsStatus({
236
230
  wallet: wallet,
237
231
  client: TEST_CLIENT,
238
- bundleId: "test",
232
+ id: "test",
239
233
  });
240
234
 
241
235
  await expect(promise).rejects.toMatchInlineSnapshot(