wagmi 1.4.1 → 2.0.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.
Files changed (293) hide show
  1. package/dist/esm/context.js +16 -0
  2. package/dist/esm/context.js.map +1 -0
  3. package/dist/esm/errors/base.js +20 -0
  4. package/dist/esm/errors/base.js.map +1 -0
  5. package/dist/esm/errors/context.js +13 -0
  6. package/dist/esm/errors/context.js.map +1 -0
  7. package/dist/esm/exports/actions.js +4 -0
  8. package/dist/esm/exports/actions.js.map +1 -0
  9. package/dist/esm/exports/chains.js +4 -0
  10. package/dist/esm/exports/chains.js.map +1 -0
  11. package/dist/esm/exports/connectors.js +4 -0
  12. package/dist/esm/exports/connectors.js.map +1 -0
  13. package/dist/esm/exports/index.js +63 -0
  14. package/dist/esm/exports/index.js.map +1 -0
  15. package/dist/esm/exports/query.js +4 -0
  16. package/dist/esm/exports/query.js.map +1 -0
  17. package/dist/esm/hooks/useAccount.js +10 -0
  18. package/dist/esm/hooks/useAccount.js.map +1 -0
  19. package/dist/esm/hooks/useAccountEffect.js +29 -0
  20. package/dist/esm/hooks/useAccountEffect.js.map +1 -0
  21. package/dist/esm/hooks/useBalance.js +19 -0
  22. package/dist/esm/hooks/useBalance.js.map +1 -0
  23. package/dist/esm/hooks/useBlockNumber.js +37 -0
  24. package/dist/esm/hooks/useBlockNumber.js.map +1 -0
  25. package/dist/esm/hooks/useChainId.js +10 -0
  26. package/dist/esm/hooks/useChainId.js.map +1 -0
  27. package/dist/esm/hooks/useClient.js +10 -0
  28. package/dist/esm/hooks/useClient.js.map +1 -0
  29. package/dist/esm/hooks/useConfig.js +13 -0
  30. package/dist/esm/hooks/useConfig.js.map +1 -0
  31. package/dist/esm/hooks/useConnect.js +22 -0
  32. package/dist/esm/hooks/useConnect.js.map +1 -0
  33. package/dist/esm/hooks/useConnections.js +10 -0
  34. package/dist/esm/hooks/useConnections.js.map +1 -0
  35. package/dist/esm/hooks/useConnectorClient.js +40 -0
  36. package/dist/esm/hooks/useConnectorClient.js.map +1 -0
  37. package/dist/esm/hooks/useContractRead.js +26 -0
  38. package/dist/esm/hooks/useContractRead.js.map +1 -0
  39. package/dist/esm/hooks/useContractReads.js +38 -0
  40. package/dist/esm/hooks/useContractReads.js.map +1 -0
  41. package/dist/esm/hooks/useContractSimulate.js +24 -0
  42. package/dist/esm/hooks/useContractSimulate.js.map +1 -0
  43. package/dist/esm/hooks/useContractWrite.js +20 -0
  44. package/dist/esm/hooks/useContractWrite.js.map +1 -0
  45. package/dist/esm/hooks/useDisconnect.js +23 -0
  46. package/dist/esm/hooks/useDisconnect.js.map +1 -0
  47. package/dist/esm/hooks/useEnsAddress.js +19 -0
  48. package/dist/esm/hooks/useEnsAddress.js.map +1 -0
  49. package/dist/esm/hooks/useEnsAvatar.js +19 -0
  50. package/dist/esm/hooks/useEnsAvatar.js.map +1 -0
  51. package/dist/esm/hooks/useEnsName.js +19 -0
  52. package/dist/esm/hooks/useEnsName.js.map +1 -0
  53. package/dist/esm/hooks/useEnsResolver.js +19 -0
  54. package/dist/esm/hooks/useEnsResolver.js.map +1 -0
  55. package/dist/esm/hooks/useEstimateFeesPerGas.js +19 -0
  56. package/dist/esm/hooks/useEstimateFeesPerGas.js.map +1 -0
  57. package/dist/esm/hooks/useEstimateGas.js +25 -0
  58. package/dist/esm/hooks/useEstimateGas.js.map +1 -0
  59. package/dist/esm/hooks/usePublicClient.js +10 -0
  60. package/dist/esm/hooks/usePublicClient.js.map +1 -0
  61. package/dist/esm/hooks/useReconnect.js +22 -0
  62. package/dist/esm/hooks/useReconnect.js.map +1 -0
  63. package/dist/esm/hooks/useSendTransaction.js +20 -0
  64. package/dist/esm/hooks/useSendTransaction.js.map +1 -0
  65. package/dist/esm/hooks/useSignMessage.js +21 -0
  66. package/dist/esm/hooks/useSignMessage.js.map +1 -0
  67. package/dist/esm/hooks/useSignTypedData.js +20 -0
  68. package/dist/esm/hooks/useSignTypedData.js.map +1 -0
  69. package/dist/esm/hooks/useSwitchAccount.js +22 -0
  70. package/dist/esm/hooks/useSwitchAccount.js.map +1 -0
  71. package/dist/esm/hooks/useSwitchChain.js +21 -0
  72. package/dist/esm/hooks/useSwitchChain.js.map +1 -0
  73. package/dist/esm/hooks/useSyncExternalStoreWithTracked.js +40 -0
  74. package/dist/esm/hooks/useSyncExternalStoreWithTracked.js.map +1 -0
  75. package/dist/esm/hooks/useToken.js +19 -0
  76. package/dist/esm/hooks/useToken.js.map +1 -0
  77. package/dist/esm/hooks/useTransaction.js +19 -0
  78. package/dist/esm/hooks/useTransaction.js.map +1 -0
  79. package/dist/esm/hooks/useWaitForTransactionReceipt.js +19 -0
  80. package/dist/esm/hooks/useWaitForTransactionReceipt.js.map +1 -0
  81. package/dist/esm/hooks/useWalletClient.js +42 -0
  82. package/dist/esm/hooks/useWalletClient.js.map +1 -0
  83. package/dist/esm/hooks/useWatchBlockNumber.js +25 -0
  84. package/dist/esm/hooks/useWatchBlockNumber.js.map +1 -0
  85. package/dist/esm/hooks/useWatchContractEvent.js +25 -0
  86. package/dist/esm/hooks/useWatchContractEvent.js.map +1 -0
  87. package/dist/esm/hooks/useWatchPendingTransactions.js +25 -0
  88. package/dist/esm/hooks/useWatchPendingTransactions.js.map +1 -0
  89. package/dist/esm/tsconfig.build.tsbuildinfo +1 -0
  90. package/dist/esm/types/properties.js +2 -0
  91. package/dist/esm/types/properties.js.map +1 -0
  92. package/dist/esm/utils/getVersion.js +3 -0
  93. package/dist/esm/utils/getVersion.js.map +1 -0
  94. package/dist/esm/utils/query.js +21 -0
  95. package/dist/esm/utils/query.js.map +1 -0
  96. package/dist/esm/version.js +2 -0
  97. package/dist/esm/version.js.map +1 -0
  98. package/dist/types/context.d.ts +11 -0
  99. package/dist/types/context.d.ts.map +1 -0
  100. package/dist/types/errors/base.d.ts +7 -0
  101. package/dist/types/errors/base.d.ts.map +1 -0
  102. package/dist/types/errors/context.d.ts +6 -0
  103. package/dist/types/errors/context.d.ts.map +1 -0
  104. package/dist/types/exports/actions.d.ts +2 -0
  105. package/dist/types/exports/actions.d.ts.map +1 -0
  106. package/dist/types/exports/chains.d.ts +2 -0
  107. package/dist/types/exports/chains.d.ts.map +1 -0
  108. package/dist/types/exports/connectors.d.ts +2 -0
  109. package/dist/types/exports/connectors.d.ts.map +1 -0
  110. package/dist/types/exports/index.d.ts +46 -0
  111. package/dist/types/exports/index.d.ts.map +1 -0
  112. package/dist/types/exports/query.d.ts +2 -0
  113. package/dist/types/exports/query.d.ts.map +1 -0
  114. package/dist/types/hooks/useAccount.d.ts +7 -0
  115. package/dist/types/hooks/useAccount.d.ts.map +1 -0
  116. package/dist/types/hooks/useAccountEffect.d.ts +14 -0
  117. package/dist/types/hooks/useAccountEffect.d.ts.map +1 -0
  118. package/dist/types/hooks/useBalance.d.ts +13 -0
  119. package/dist/types/hooks/useBalance.d.ts.map +1 -0
  120. package/dist/types/hooks/useBlockNumber.d.ts +14 -0
  121. package/dist/types/hooks/useBlockNumber.d.ts.map +1 -0
  122. package/dist/types/hooks/useChainId.d.ts +7 -0
  123. package/dist/types/hooks/useChainId.d.ts.map +1 -0
  124. package/dist/types/hooks/useClient.d.ts +8 -0
  125. package/dist/types/hooks/useClient.d.ts.map +1 -0
  126. package/dist/types/hooks/useConfig.d.ts +7 -0
  127. package/dist/types/hooks/useConfig.d.ts.map +1 -0
  128. package/dist/types/hooks/useConnect.d.ts +16 -0
  129. package/dist/types/hooks/useConnect.d.ts.map +1 -0
  130. package/dist/types/hooks/useConnections.d.ts +7 -0
  131. package/dist/types/hooks/useConnections.d.ts.map +1 -0
  132. package/dist/types/hooks/useConnectorClient.d.ts +12 -0
  133. package/dist/types/hooks/useConnectorClient.d.ts.map +1 -0
  134. package/dist/types/hooks/useContractRead.d.ts +13 -0
  135. package/dist/types/hooks/useContractRead.d.ts.map +1 -0
  136. package/dist/types/hooks/useContractReads.d.ts +13 -0
  137. package/dist/types/hooks/useContractReads.d.ts.map +1 -0
  138. package/dist/types/hooks/useContractSimulate.d.ts +12 -0
  139. package/dist/types/hooks/useContractSimulate.d.ts.map +1 -0
  140. package/dist/types/hooks/useContractWrite.d.ts +15 -0
  141. package/dist/types/hooks/useContractWrite.d.ts.map +1 -0
  142. package/dist/types/hooks/useDisconnect.d.ts +16 -0
  143. package/dist/types/hooks/useDisconnect.d.ts.map +1 -0
  144. package/dist/types/hooks/useEnsAddress.d.ts +12 -0
  145. package/dist/types/hooks/useEnsAddress.d.ts.map +1 -0
  146. package/dist/types/hooks/useEnsAvatar.d.ts +12 -0
  147. package/dist/types/hooks/useEnsAvatar.d.ts.map +1 -0
  148. package/dist/types/hooks/useEnsName.d.ts +12 -0
  149. package/dist/types/hooks/useEnsName.d.ts.map +1 -0
  150. package/dist/types/hooks/useEnsResolver.d.ts +12 -0
  151. package/dist/types/hooks/useEnsResolver.d.ts.map +1 -0
  152. package/dist/types/hooks/useEstimateFeesPerGas.d.ts +13 -0
  153. package/dist/types/hooks/useEstimateFeesPerGas.d.ts.map +1 -0
  154. package/dist/types/hooks/useEstimateGas.d.ts +11 -0
  155. package/dist/types/hooks/useEstimateGas.d.ts.map +1 -0
  156. package/dist/types/hooks/usePublicClient.d.ts +8 -0
  157. package/dist/types/hooks/usePublicClient.d.ts.map +1 -0
  158. package/dist/types/hooks/useReconnect.d.ts +16 -0
  159. package/dist/types/hooks/useReconnect.d.ts.map +1 -0
  160. package/dist/types/hooks/useSendTransaction.d.ts +15 -0
  161. package/dist/types/hooks/useSendTransaction.d.ts.map +1 -0
  162. package/dist/types/hooks/useSignMessage.d.ts +15 -0
  163. package/dist/types/hooks/useSignMessage.d.ts.map +1 -0
  164. package/dist/types/hooks/useSignTypedData.d.ts +15 -0
  165. package/dist/types/hooks/useSignTypedData.d.ts.map +1 -0
  166. package/dist/types/hooks/useSwitchAccount.d.ts +16 -0
  167. package/dist/types/hooks/useSwitchAccount.d.ts.map +1 -0
  168. package/dist/types/hooks/useSwitchChain.d.ts +16 -0
  169. package/dist/types/hooks/useSwitchChain.d.ts.map +1 -0
  170. package/dist/types/hooks/useSyncExternalStoreWithTracked.d.ts +2 -0
  171. package/dist/types/hooks/useSyncExternalStoreWithTracked.d.ts.map +1 -0
  172. package/dist/types/hooks/useToken.d.ts +12 -0
  173. package/dist/types/hooks/useToken.d.ts.map +1 -0
  174. package/dist/types/hooks/useTransaction.d.ts +12 -0
  175. package/dist/types/hooks/useTransaction.d.ts.map +1 -0
  176. package/dist/types/hooks/useWaitForTransactionReceipt.d.ts +12 -0
  177. package/dist/types/hooks/useWaitForTransactionReceipt.d.ts.map +1 -0
  178. package/dist/types/hooks/useWalletClient.d.ts +12 -0
  179. package/dist/types/hooks/useWalletClient.d.ts.map +1 -0
  180. package/dist/types/hooks/useWatchBlockNumber.d.ts +8 -0
  181. package/dist/types/hooks/useWatchBlockNumber.d.ts.map +1 -0
  182. package/dist/types/hooks/useWatchContractEvent.d.ts +9 -0
  183. package/dist/types/hooks/useWatchContractEvent.d.ts.map +1 -0
  184. package/dist/types/hooks/useWatchPendingTransactions.d.ts +8 -0
  185. package/dist/types/hooks/useWatchPendingTransactions.d.ts.map +1 -0
  186. package/dist/types/types/properties.d.ts +8 -0
  187. package/dist/types/types/properties.d.ts.map +1 -0
  188. package/dist/types/utils/getVersion.d.ts +2 -0
  189. package/dist/types/utils/getVersion.d.ts.map +1 -0
  190. package/dist/types/utils/query.d.ts +15 -0
  191. package/dist/types/utils/query.d.ts.map +1 -0
  192. package/dist/types/version.d.ts +2 -0
  193. package/dist/types/version.d.ts.map +1 -0
  194. package/package.json +65 -103
  195. package/src/context.ts +27 -0
  196. package/src/errors/base.ts +13 -0
  197. package/src/errors/context.ts +8 -0
  198. package/src/exports/actions.ts +4 -0
  199. package/src/exports/chains.ts +4 -0
  200. package/src/exports/connectors.ts +4 -0
  201. package/src/exports/index.ts +284 -0
  202. package/src/exports/query.ts +4 -0
  203. package/src/hooks/useAccount.ts +27 -0
  204. package/src/hooks/useAccountEffect.ts +55 -0
  205. package/src/hooks/useBalance.ts +65 -0
  206. package/src/hooks/useBlockNumber.ts +97 -0
  207. package/src/hooks/useChainId.ts +31 -0
  208. package/src/hooks/useClient.ts +43 -0
  209. package/src/hooks/useConfig.ts +22 -0
  210. package/src/hooks/useConnect.ts +80 -0
  211. package/src/hooks/useConnections.ts +27 -0
  212. package/src/hooks/useConnectorClient.ts +95 -0
  213. package/src/hooks/useContractRead.ts +107 -0
  214. package/src/hooks/useContractReads.ts +98 -0
  215. package/src/hooks/useContractSimulate.ts +117 -0
  216. package/src/hooks/useContractWrite.ts +83 -0
  217. package/src/hooks/useDisconnect.ts +68 -0
  218. package/src/hooks/useEnsAddress.ts +61 -0
  219. package/src/hooks/useEnsAvatar.ts +59 -0
  220. package/src/hooks/useEnsName.ts +61 -0
  221. package/src/hooks/useEnsResolver.ts +61 -0
  222. package/src/hooks/useEstimateFeesPerGas.ts +69 -0
  223. package/src/hooks/useEstimateGas.ts +72 -0
  224. package/src/hooks/usePublicClient.ts +45 -0
  225. package/src/hooks/useReconnect.ts +67 -0
  226. package/src/hooks/useSendTransaction.ts +79 -0
  227. package/src/hooks/useSignMessage.ts +65 -0
  228. package/src/hooks/useSignTypedData.ts +66 -0
  229. package/src/hooks/useSwitchAccount.ts +82 -0
  230. package/src/hooks/useSwitchChain.ts +77 -0
  231. package/src/hooks/useSyncExternalStoreWithTracked.ts +67 -0
  232. package/src/hooks/useToken.ts +63 -0
  233. package/src/hooks/useTransaction.ts +68 -0
  234. package/src/hooks/useWaitForTransactionReceipt.ts +74 -0
  235. package/src/hooks/useWalletClient.ts +96 -0
  236. package/src/hooks/useWatchBlockNumber.ts +49 -0
  237. package/src/hooks/useWatchContractEvent.ts +64 -0
  238. package/src/hooks/useWatchPendingTransactions.ts +52 -0
  239. package/src/types/properties.ts +9 -0
  240. package/src/utils/getVersion.ts +3 -0
  241. package/src/utils/query.ts +102 -0
  242. package/src/version.ts +1 -0
  243. package/README.md +0 -30
  244. package/actions/package.json +0 -4
  245. package/chains/package.json +0 -4
  246. package/connectors/coinbaseWallet/package.json +0 -4
  247. package/connectors/injected/package.json +0 -4
  248. package/connectors/ledger/package.json +0 -4
  249. package/connectors/metaMask/package.json +0 -4
  250. package/connectors/mock/package.json +0 -4
  251. package/connectors/package.json +0 -4
  252. package/connectors/safe/package.json +0 -4
  253. package/connectors/walletConnect/package.json +0 -4
  254. package/connectors/walletConnectLegacy/package.json +0 -4
  255. package/dist/actions.d.ts +0 -1
  256. package/dist/actions.js +0 -85
  257. package/dist/chains.d.ts +0 -2
  258. package/dist/chains.js +0 -4
  259. package/dist/connectors/coinbaseWallet.d.ts +0 -1
  260. package/dist/connectors/coinbaseWallet.js +0 -7
  261. package/dist/connectors/index.d.ts +0 -1
  262. package/dist/connectors/index.js +0 -7
  263. package/dist/connectors/injected.d.ts +0 -1
  264. package/dist/connectors/injected.js +0 -7
  265. package/dist/connectors/ledger.d.ts +0 -1
  266. package/dist/connectors/ledger.js +0 -7
  267. package/dist/connectors/metaMask.d.ts +0 -1
  268. package/dist/connectors/metaMask.js +0 -7
  269. package/dist/connectors/mock.d.ts +0 -1
  270. package/dist/connectors/mock.js +0 -7
  271. package/dist/connectors/safe.d.ts +0 -1
  272. package/dist/connectors/safe.js +0 -7
  273. package/dist/connectors/walletConnect.d.ts +0 -1
  274. package/dist/connectors/walletConnect.js +0 -7
  275. package/dist/connectors/walletConnectLegacy.d.ts +0 -1
  276. package/dist/connectors/walletConnectLegacy.js +0 -7
  277. package/dist/index.d.ts +0 -958
  278. package/dist/index.js +0 -2564
  279. package/dist/providers/alchemy.d.ts +0 -1
  280. package/dist/providers/alchemy.js +0 -7
  281. package/dist/providers/infura.d.ts +0 -1
  282. package/dist/providers/infura.js +0 -7
  283. package/dist/providers/jsonRpc.d.ts +0 -1
  284. package/dist/providers/jsonRpc.js +0 -7
  285. package/dist/providers/public.d.ts +0 -1
  286. package/dist/providers/public.js +0 -7
  287. package/dist/window.d.ts +0 -76
  288. package/dist/window.js +0 -1
  289. package/providers/alchemy/package.json +0 -4
  290. package/providers/infura/package.json +0 -4
  291. package/providers/jsonRpc/package.json +0 -4
  292. package/providers/public/package.json +0 -4
  293. package/window/package.json +0 -4
@@ -0,0 +1,45 @@
1
+ 'use client'
2
+
3
+ import {
4
+ type Config,
5
+ type GetPublicClientParameters,
6
+ type GetPublicClientReturnType,
7
+ type ResolvedRegister,
8
+ getPublicClient,
9
+ watchPublicClient,
10
+ } from '@wagmi/core'
11
+ import type { Evaluate } from '@wagmi/core/internal'
12
+ import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector.js'
13
+
14
+ import type { ConfigParameter } from '../types/properties.js'
15
+ import { useConfig } from './useConfig.js'
16
+
17
+ export type UsePublicClientParameters<
18
+ config extends Config = Config,
19
+ chainId extends config['chains'][number]['id'] = config['chains'][number]['id'],
20
+ > = Evaluate<
21
+ GetPublicClientParameters<config, chainId> & ConfigParameter<config>
22
+ >
23
+
24
+ export type UsePublicClientReturnType<
25
+ config extends Config = Config,
26
+ chainId extends config['chains'][number]['id'] = config['chains'][number]['id'],
27
+ > = GetPublicClientReturnType<config, chainId>
28
+
29
+ /** https://alpha.wagmi.sh/react/api/hooks/usePublicClient */
30
+ export function usePublicClient<
31
+ config extends Config = ResolvedRegister['config'],
32
+ chainId extends config['chains'][number]['id'] = config['chains'][number]['id'],
33
+ >(
34
+ parameters: UsePublicClientParameters<config, chainId> = {},
35
+ ): UsePublicClientReturnType<config, chainId> {
36
+ const config = useConfig(parameters)
37
+
38
+ return useSyncExternalStoreWithSelector(
39
+ (onChange) => watchPublicClient(config, { onChange }),
40
+ () => getPublicClient(config, parameters),
41
+ () => getPublicClient(config, parameters),
42
+ (x) => x,
43
+ (a, b) => a.uid === b.uid,
44
+ ) as any
45
+ }
@@ -0,0 +1,67 @@
1
+ 'use client'
2
+
3
+ import { useMutation } from '@tanstack/react-query'
4
+ import { type Connector, type ReconnectError } from '@wagmi/core'
5
+ import type { Evaluate } from '@wagmi/core/internal'
6
+ import {
7
+ type ReconnectData,
8
+ type ReconnectMutate,
9
+ type ReconnectMutateAsync,
10
+ type ReconnectVariables,
11
+ reconnectMutationOptions,
12
+ } from '@wagmi/core/query'
13
+
14
+ import type { ConfigParameter } from '../types/properties.js'
15
+ import type {
16
+ UseMutationParameters,
17
+ UseMutationReturnType,
18
+ } from '../utils/query.js'
19
+ import { useConfig } from './useConfig.js'
20
+
21
+ export type UseReconnectParameters<context = unknown> = Evaluate<
22
+ ConfigParameter & {
23
+ mutation?:
24
+ | UseMutationParameters<
25
+ ReconnectData,
26
+ ReconnectError,
27
+ ReconnectVariables,
28
+ context
29
+ >
30
+ | undefined
31
+ }
32
+ >
33
+
34
+ export type UseReconnectReturnType<context = unknown> = Evaluate<
35
+ UseMutationReturnType<
36
+ ReconnectData,
37
+ ReconnectError,
38
+ ReconnectVariables,
39
+ context
40
+ > & {
41
+ connectors: readonly Connector[]
42
+ reconnect: ReconnectMutate<context>
43
+ reconnectAsync: ReconnectMutateAsync<context>
44
+ }
45
+ >
46
+
47
+ /** https://alpha.wagmi.sh/react/api/hooks/useReconnect */
48
+ export function useReconnect<context = unknown>(
49
+ parameters: UseReconnectParameters<context> = {},
50
+ ): UseReconnectReturnType<context> {
51
+ const { mutation } = parameters
52
+
53
+ const config = useConfig(parameters)
54
+
55
+ const mutationOptions = reconnectMutationOptions(config)
56
+ const { mutate, mutateAsync, ...result } = useMutation({
57
+ ...mutation,
58
+ ...mutationOptions,
59
+ })
60
+
61
+ return {
62
+ ...result,
63
+ connectors: config.connectors,
64
+ reconnect: mutate,
65
+ reconnectAsync: mutateAsync,
66
+ }
67
+ }
@@ -0,0 +1,79 @@
1
+ 'use client'
2
+
3
+ import { useMutation } from '@tanstack/react-query'
4
+ import type {
5
+ Config,
6
+ ResolvedRegister,
7
+ SendTransactionError,
8
+ } from '@wagmi/core'
9
+ import type { Evaluate } from '@wagmi/core/internal'
10
+ import {
11
+ type SendTransactionData,
12
+ type SendTransactionMutate,
13
+ type SendTransactionMutateAsync,
14
+ type SendTransactionVariables,
15
+ sendTransactionMutationOptions,
16
+ } from '@wagmi/core/query'
17
+
18
+ import type { ConfigParameter } from '../types/properties.js'
19
+ import type {
20
+ UseMutationParameters,
21
+ UseMutationReturnType,
22
+ } from '../utils/query.js'
23
+ import { useConfig } from './useConfig.js'
24
+
25
+ export type UseSendTransactionParameters<
26
+ config extends Config = Config,
27
+ context = unknown,
28
+ > = Evaluate<
29
+ ConfigParameter<config> & {
30
+ mutation?:
31
+ | UseMutationParameters<
32
+ SendTransactionData,
33
+ SendTransactionError,
34
+ SendTransactionVariables<config, config['chains'][number]['id']>,
35
+ context
36
+ >
37
+ | undefined
38
+ }
39
+ >
40
+
41
+ export type UseSendTransactionReturnType<
42
+ config extends Config = Config,
43
+ context = unknown,
44
+ > = Evaluate<
45
+ UseMutationReturnType<
46
+ SendTransactionData,
47
+ SendTransactionError,
48
+ SendTransactionVariables<config, config['chains'][number]['id']>,
49
+ context
50
+ > & {
51
+ sendTransaction: SendTransactionMutate<config, context>
52
+ sendTransactionAsync: SendTransactionMutateAsync<config, context>
53
+ }
54
+ >
55
+
56
+ /** https://alpha.wagmi.sh/react/api/hooks/useSendTransaction */
57
+ export function useSendTransaction<
58
+ config extends Config = ResolvedRegister['config'],
59
+ context = unknown,
60
+ >(
61
+ parameters: UseSendTransactionParameters<config, context> = {},
62
+ ): UseSendTransactionReturnType<config, context> {
63
+ const { mutation } = parameters
64
+
65
+ const config = useConfig(parameters)
66
+
67
+ const mutationOptions = sendTransactionMutationOptions(config)
68
+ const { mutate, mutateAsync, ...result } = useMutation({
69
+ ...mutation,
70
+ ...mutationOptions,
71
+ })
72
+
73
+ type Return = UseSendTransactionReturnType<config, context>
74
+ return {
75
+ ...result,
76
+ sendTransaction: mutate as Return['sendTransaction'],
77
+ sendTransactionAsync: mutateAsync as Return['sendTransactionAsync'],
78
+ }
79
+ }
@@ -0,0 +1,65 @@
1
+ 'use client'
2
+
3
+ import { useMutation } from '@tanstack/react-query'
4
+ import { type SignMessageError } from '@wagmi/core'
5
+ import type { Evaluate } from '@wagmi/core/internal'
6
+ import {
7
+ type SignMessageData,
8
+ type SignMessageMutate,
9
+ type SignMessageMutateAsync,
10
+ type SignMessageVariables,
11
+ signMessageMutationOptions,
12
+ } from '@wagmi/core/query'
13
+
14
+ import type { ConfigParameter } from '../types/properties.js'
15
+ import type {
16
+ UseMutationParameters,
17
+ UseMutationReturnType,
18
+ } from '../utils/query.js'
19
+ import { useConfig } from './useConfig.js'
20
+
21
+ export type UseSignMessageParameters<context = unknown> = Evaluate<
22
+ ConfigParameter & {
23
+ mutation?:
24
+ | UseMutationParameters<
25
+ SignMessageData,
26
+ SignMessageError,
27
+ SignMessageVariables,
28
+ context
29
+ >
30
+ | undefined
31
+ }
32
+ >
33
+
34
+ export type UseSignMessageReturnType<context = unknown> = Evaluate<
35
+ UseMutationReturnType<
36
+ SignMessageData,
37
+ SignMessageError,
38
+ SignMessageVariables,
39
+ context
40
+ > & {
41
+ signMessage: SignMessageMutate<context>
42
+ signMessageAsync: SignMessageMutateAsync<context>
43
+ }
44
+ >
45
+
46
+ /** https://alpha.wagmi.sh/react/api/hooks/useSignMessage */
47
+ export function useSignMessage<context = unknown>(
48
+ parameters: UseSignMessageParameters<context> = {},
49
+ ): UseSignMessageReturnType<context> {
50
+ const { mutation } = parameters
51
+
52
+ const config = useConfig(parameters)
53
+
54
+ const mutationOptions = signMessageMutationOptions(config)
55
+ const { mutate, mutateAsync, ...result } = useMutation({
56
+ ...mutation,
57
+ ...mutationOptions,
58
+ })
59
+
60
+ return {
61
+ ...result,
62
+ signMessage: mutate,
63
+ signMessageAsync: mutateAsync,
64
+ }
65
+ }
@@ -0,0 +1,66 @@
1
+ 'use client'
2
+
3
+ import { useMutation } from '@tanstack/react-query'
4
+ import type { SignTypedDataError } from '@wagmi/core'
5
+ import type { Evaluate } from '@wagmi/core/internal'
6
+ import {
7
+ type SignTypedDataData,
8
+ type SignTypedDataMutate,
9
+ type SignTypedDataMutateAsync,
10
+ type SignTypedDataVariables,
11
+ signTypedDataMutationOptions,
12
+ } from '@wagmi/core/query'
13
+
14
+ import type { ConfigParameter } from '../types/properties.js'
15
+ import type {
16
+ UseMutationParameters,
17
+ UseMutationReturnType,
18
+ } from '../utils/query.js'
19
+ import { useConfig } from './useConfig.js'
20
+
21
+ export type UseSignTypedDataParameters<context = unknown> = Evaluate<
22
+ ConfigParameter & {
23
+ mutation?:
24
+ | UseMutationParameters<
25
+ SignTypedDataData,
26
+ SignTypedDataError,
27
+ SignTypedDataVariables,
28
+ context
29
+ >
30
+ | undefined
31
+ }
32
+ >
33
+
34
+ export type UseSignTypedDataReturnType<context = unknown> = Evaluate<
35
+ UseMutationReturnType<
36
+ SignTypedDataData,
37
+ SignTypedDataError,
38
+ SignTypedDataVariables,
39
+ context
40
+ > & {
41
+ signTypedData: SignTypedDataMutate<context>
42
+ signTypedDataAsync: SignTypedDataMutateAsync<context>
43
+ }
44
+ >
45
+
46
+ /** https://alpha.wagmi.sh/react/api/hooks/useSignTypedData */
47
+ export function useSignTypedData<context = unknown>(
48
+ parameters: UseSignTypedDataParameters<context> = {},
49
+ ): UseSignTypedDataReturnType<context> {
50
+ const { mutation } = parameters
51
+
52
+ const config = useConfig(parameters)
53
+
54
+ const mutationOptions = signTypedDataMutationOptions(config)
55
+ const { mutate, mutateAsync, ...result } = useMutation({
56
+ ...mutation,
57
+ ...mutationOptions,
58
+ })
59
+
60
+ type Return = UseSignTypedDataReturnType<context>
61
+ return {
62
+ ...result,
63
+ signTypedData: mutate as Return['signTypedData'],
64
+ signTypedDataAsync: mutateAsync as Return['signTypedDataAsync'],
65
+ }
66
+ }
@@ -0,0 +1,82 @@
1
+ 'use client'
2
+
3
+ import { useMutation } from '@tanstack/react-query'
4
+ import type {
5
+ Config,
6
+ Connector,
7
+ ResolvedRegister,
8
+ SwitchAccountError,
9
+ } from '@wagmi/core'
10
+ import type { Evaluate } from '@wagmi/core/internal'
11
+ import {
12
+ type SwitchAccountData,
13
+ type SwitchAccountMutate,
14
+ type SwitchAccountMutateAsync,
15
+ type SwitchAccountVariables,
16
+ switchAccountMutationOptions,
17
+ } from '@wagmi/core/query'
18
+
19
+ import type { ConfigParameter } from '../types/properties.js'
20
+ import type {
21
+ UseMutationParameters,
22
+ UseMutationReturnType,
23
+ } from '../utils/query.js'
24
+ import { useConfig } from './useConfig.js'
25
+ import { useConnections } from './useConnections.js'
26
+
27
+ export type UseSwitchAccountParameters<
28
+ config extends Config = Config,
29
+ context = unknown,
30
+ > = Evaluate<
31
+ ConfigParameter<config> & {
32
+ mutation?:
33
+ | UseMutationParameters<
34
+ SwitchAccountData<config>,
35
+ SwitchAccountError,
36
+ SwitchAccountVariables,
37
+ context
38
+ >
39
+ | undefined
40
+ }
41
+ >
42
+
43
+ export type UseSwitchAccountReturnType<
44
+ config extends Config = Config,
45
+ context = unknown,
46
+ > = Evaluate<
47
+ UseMutationReturnType<
48
+ SwitchAccountData<config>,
49
+ SwitchAccountError,
50
+ SwitchAccountVariables,
51
+ context
52
+ > & {
53
+ connectors: readonly Connector[]
54
+ switchAccount: SwitchAccountMutate<config, context>
55
+ switchAccountAsync: SwitchAccountMutateAsync<config, context>
56
+ }
57
+ >
58
+
59
+ /** https://alpha.wagmi.sh/react/api/hooks/useSwitchAccount */
60
+ export function useSwitchAccount<
61
+ config extends Config = ResolvedRegister['config'],
62
+ context = unknown,
63
+ >(
64
+ parameters: UseSwitchAccountParameters<config, context> = {},
65
+ ): UseSwitchAccountReturnType<config, context> {
66
+ const { mutation } = parameters
67
+
68
+ const config = useConfig(parameters)
69
+
70
+ const mutationOptions = switchAccountMutationOptions(config)
71
+ const { mutate, mutateAsync, ...result } = useMutation({
72
+ ...mutation,
73
+ ...mutationOptions,
74
+ })
75
+
76
+ return {
77
+ ...result,
78
+ connectors: useConnections().map((connection) => connection.connector),
79
+ switchAccount: mutate,
80
+ switchAccountAsync: mutateAsync,
81
+ }
82
+ }
@@ -0,0 +1,77 @@
1
+ 'use client'
2
+
3
+ import { useMutation } from '@tanstack/react-query'
4
+ import type { Config, ResolvedRegister, SwitchChainError } from '@wagmi/core'
5
+ import type { Evaluate } from '@wagmi/core/internal'
6
+ import {
7
+ type SwitchChainData,
8
+ type SwitchChainMutate,
9
+ type SwitchChainMutateAsync,
10
+ type SwitchChainVariables,
11
+ switchChainMutationOptions,
12
+ } from '@wagmi/core/query'
13
+
14
+ import type { ConfigParameter } from '../types/properties.js'
15
+ import type {
16
+ UseMutationParameters,
17
+ UseMutationReturnType,
18
+ } from '../utils/query.js'
19
+ import { useConfig } from './useConfig.js'
20
+
21
+ export type UseSwitchChainParameters<
22
+ config extends Config = Config,
23
+ context = unknown,
24
+ > = Evaluate<
25
+ ConfigParameter<config> & {
26
+ mutation?:
27
+ | UseMutationParameters<
28
+ SwitchChainData<config, config['chains'][number]['id']>,
29
+ SwitchChainError,
30
+ SwitchChainVariables<config, config['chains'][number]['id']>,
31
+ context
32
+ >
33
+ | undefined
34
+ }
35
+ >
36
+
37
+ export type UseSwitchChainReturnType<
38
+ config extends Config = Config,
39
+ context = unknown,
40
+ > = Evaluate<
41
+ UseMutationReturnType<
42
+ SwitchChainData<config, config['chains'][number]['id']>,
43
+ SwitchChainError,
44
+ SwitchChainVariables<config, config['chains'][number]['id']>,
45
+ context
46
+ > & {
47
+ chains: config['chains']
48
+ switchChain: SwitchChainMutate<config, context>
49
+ switchChainAsync: SwitchChainMutateAsync<config, context>
50
+ }
51
+ >
52
+
53
+ /** https://alpha.wagmi.sh/react/api/hooks/useSwitchChain */
54
+ export function useSwitchChain<
55
+ config extends Config = ResolvedRegister['config'],
56
+ context = unknown,
57
+ >(
58
+ parameters: UseSwitchChainParameters<config, context> = {},
59
+ ): UseSwitchChainReturnType<config, context> {
60
+ const { mutation } = parameters
61
+
62
+ const config = useConfig(parameters)
63
+
64
+ const mutationOptions = switchChainMutationOptions(config)
65
+ const { mutate, mutateAsync, ...result } = useMutation({
66
+ ...mutation,
67
+ ...mutationOptions,
68
+ })
69
+
70
+ type Return = UseSwitchChainReturnType<config, context>
71
+ return {
72
+ ...result,
73
+ chains: config.chains,
74
+ switchChain: mutate as Return['switchChain'],
75
+ switchChainAsync: mutateAsync as Return['switchChainAsync'],
76
+ }
77
+ }
@@ -0,0 +1,67 @@
1
+ 'use client'
2
+
3
+ import { deepEqual } from '@wagmi/core/internal'
4
+ import { useRef } from 'react'
5
+ import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector.js'
6
+
7
+ const isPlainObject = (obj: unknown) =>
8
+ typeof obj === 'object' && !Array.isArray(obj)
9
+
10
+ export function useSyncExternalStoreWithTracked<
11
+ snapshot extends selection,
12
+ selection = snapshot,
13
+ >(
14
+ subscribe: (onStoreChange: () => void) => () => void,
15
+ getSnapshot: () => snapshot,
16
+ getServerSnapshot: undefined | null | (() => snapshot) = getSnapshot,
17
+ isEqual: (a: selection, b: selection) => boolean = deepEqual,
18
+ ) {
19
+ const trackedKeys = useRef<string[]>([])
20
+ const result = useSyncExternalStoreWithSelector(
21
+ subscribe,
22
+ getSnapshot,
23
+ getServerSnapshot,
24
+ (x) => x,
25
+ (a, b) => {
26
+ if (isPlainObject(a) && isPlainObject(b) && trackedKeys.current.length) {
27
+ for (const key of trackedKeys.current) {
28
+ const equal = isEqual(
29
+ (a as { [_a: string]: any })[key],
30
+ (b as { [_b: string]: any })[key],
31
+ )
32
+ if (!equal) return false
33
+ }
34
+ return true
35
+ }
36
+ return isEqual(a, b)
37
+ },
38
+ )
39
+
40
+ if (isPlainObject(result)) {
41
+ const trackedResult = { ...result }
42
+ Object.defineProperties(
43
+ trackedResult,
44
+ Object.entries(trackedResult as { [key: string]: any }).reduce(
45
+ (res, [key, value]) => {
46
+ return {
47
+ ...res,
48
+ [key]: {
49
+ configurable: false,
50
+ enumerable: true,
51
+ get: () => {
52
+ if (!trackedKeys.current.includes(key)) {
53
+ trackedKeys.current.push(key)
54
+ }
55
+ return value
56
+ },
57
+ },
58
+ }
59
+ },
60
+ {},
61
+ ),
62
+ )
63
+ return trackedResult
64
+ }
65
+
66
+ return result
67
+ }
@@ -0,0 +1,63 @@
1
+ 'use client'
2
+
3
+ import type { Config, GetTokenError, ResolvedRegister } from '@wagmi/core'
4
+ import { type Evaluate } from '@wagmi/core/internal'
5
+ import {
6
+ type GetTokenData,
7
+ type GetTokenOptions,
8
+ type GetTokenQueryFnData,
9
+ type GetTokenQueryKey,
10
+ getTokenQueryOptions,
11
+ } from '@wagmi/core/query'
12
+
13
+ import type { ConfigParameter } from '../types/properties.js'
14
+ import {
15
+ type UseQueryParameters,
16
+ type UseQueryReturnType,
17
+ useQuery,
18
+ } from '../utils/query.js'
19
+ import { useChainId } from './useChainId.js'
20
+ import { useConfig } from './useConfig.js'
21
+
22
+ export type UseTokenParameters<
23
+ config extends Config = Config,
24
+ selectData = GetTokenData,
25
+ > = Evaluate<
26
+ GetTokenOptions<config> &
27
+ ConfigParameter<config> & {
28
+ query?:
29
+ | UseQueryParameters<
30
+ GetTokenQueryFnData,
31
+ GetTokenError,
32
+ selectData,
33
+ GetTokenQueryKey<config>
34
+ >
35
+ | undefined
36
+ }
37
+ >
38
+
39
+ export type UseTokenReturnType<selectData = GetTokenData> = UseQueryReturnType<
40
+ selectData,
41
+ GetTokenError
42
+ >
43
+
44
+ /** https://alpha.wagmi.sh/react/api/hooks/useToken */
45
+ export function useToken<
46
+ config extends Config = ResolvedRegister['config'],
47
+ selectData = GetTokenData,
48
+ >(
49
+ parameters: UseTokenParameters<config, selectData> = {},
50
+ ): UseTokenReturnType<selectData> {
51
+ const { address, query = {} } = parameters
52
+
53
+ const config = useConfig(parameters)
54
+ const chainId = useChainId()
55
+
56
+ const queryOptions = getTokenQueryOptions(config, {
57
+ ...parameters,
58
+ chainId: parameters.chainId ?? chainId,
59
+ })
60
+ const enabled = Boolean(address && (query.enabled ?? true))
61
+
62
+ return useQuery({ ...queryOptions, ...query, enabled })
63
+ }
@@ -0,0 +1,68 @@
1
+ 'use client'
2
+
3
+ import type { Config, GetTransactionError, ResolvedRegister } from '@wagmi/core'
4
+ import { type Evaluate } from '@wagmi/core/internal'
5
+ import {
6
+ type GetTransactionData,
7
+ type GetTransactionOptions,
8
+ type GetTransactionQueryFnData,
9
+ type GetTransactionQueryKey,
10
+ getTransactionQueryOptions,
11
+ } from '@wagmi/core/query'
12
+
13
+ import type { ConfigParameter } from '../types/properties.js'
14
+ import {
15
+ type UseQueryParameters,
16
+ type UseQueryReturnType,
17
+ useQuery,
18
+ } from '../utils/query.js'
19
+ import { useChainId } from './useChainId.js'
20
+ import { useConfig } from './useConfig.js'
21
+
22
+ export type UseTransactionParameters<
23
+ config extends Config = Config,
24
+ chainId extends config['chains'][number]['id'] = config['chains'][number]['id'],
25
+ selectData = GetTransactionData<config, chainId>,
26
+ > = Evaluate<
27
+ GetTransactionOptions<config, chainId> &
28
+ ConfigParameter<config> & {
29
+ query?:
30
+ | UseQueryParameters<
31
+ GetTransactionQueryFnData<config, chainId>,
32
+ GetTransactionError,
33
+ selectData,
34
+ GetTransactionQueryKey<config, chainId>
35
+ >
36
+ | undefined
37
+ }
38
+ >
39
+
40
+ export type UseTransactionReturnType<
41
+ config extends Config = Config,
42
+ chainId extends config['chains'][number]['id'] = config['chains'][number]['id'],
43
+ selectData = GetTransactionData<config, chainId>,
44
+ > = UseQueryReturnType<selectData, GetTransactionError>
45
+
46
+ /** https://alpha.wagmi.sh/react/api/hooks/useTransaction */
47
+ export function useTransaction<
48
+ config extends Config = ResolvedRegister['config'],
49
+ chainId extends config['chains'][number]['id'] = config['chains'][number]['id'],
50
+ selectData = GetTransactionData<config, chainId>,
51
+ >(
52
+ parameters: UseTransactionParameters<config, chainId, selectData> = {},
53
+ ): UseTransactionReturnType<config, chainId, selectData> {
54
+ const { blockHash, blockNumber, blockTag, hash, query = {} } = parameters
55
+
56
+ const config = useConfig(parameters)
57
+ const chainId = useChainId()
58
+
59
+ const queryOptions = getTransactionQueryOptions(config, {
60
+ ...parameters,
61
+ chainId: parameters.chainId ?? chainId,
62
+ })
63
+ const enabled = Boolean(
64
+ !(blockHash && blockNumber && blockTag && hash) && (query.enabled ?? true),
65
+ )
66
+
67
+ return useQuery({ ...queryOptions, ...query, enabled })
68
+ }