tempo.ts 0.10.2 → 0.10.3

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 (41) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/viem/Actions/index.d.ts +1 -0
  3. package/dist/viem/Actions/index.d.ts.map +1 -1
  4. package/dist/viem/Actions/index.js +1 -0
  5. package/dist/viem/Actions/index.js.map +1 -1
  6. package/dist/viem/Actions/nonce.d.ts +257 -0
  7. package/dist/viem/Actions/nonce.d.ts.map +1 -0
  8. package/dist/viem/Actions/nonce.js +226 -0
  9. package/dist/viem/Actions/nonce.js.map +1 -0
  10. package/dist/viem/Addresses.d.ts +1 -0
  11. package/dist/viem/Addresses.d.ts.map +1 -1
  12. package/dist/viem/Addresses.js +1 -0
  13. package/dist/viem/Addresses.js.map +1 -1
  14. package/dist/wagmi/Actions/index.d.ts +1 -0
  15. package/dist/wagmi/Actions/index.d.ts.map +1 -1
  16. package/dist/wagmi/Actions/index.js +1 -0
  17. package/dist/wagmi/Actions/index.js.map +1 -1
  18. package/dist/wagmi/Actions/nonce.d.ts +147 -0
  19. package/dist/wagmi/Actions/nonce.d.ts.map +1 -0
  20. package/dist/wagmi/Actions/nonce.js +169 -0
  21. package/dist/wagmi/Actions/nonce.js.map +1 -0
  22. package/dist/wagmi/Hooks/index.d.ts +1 -0
  23. package/dist/wagmi/Hooks/index.d.ts.map +1 -1
  24. package/dist/wagmi/Hooks/index.js +1 -0
  25. package/dist/wagmi/Hooks/index.js.map +1 -1
  26. package/dist/wagmi/Hooks/nonce.d.ts +110 -0
  27. package/dist/wagmi/Hooks/nonce.d.ts.map +1 -0
  28. package/dist/wagmi/Hooks/nonce.js +144 -0
  29. package/dist/wagmi/Hooks/nonce.js.map +1 -0
  30. package/package.json +1 -1
  31. package/src/viem/Actions/index.ts +1 -0
  32. package/src/viem/Actions/nonce.test.ts +193 -0
  33. package/src/viem/Actions/nonce.ts +345 -0
  34. package/src/viem/Addresses.ts +1 -0
  35. package/src/viem/Chain.test.ts +9 -9
  36. package/src/wagmi/Actions/index.ts +1 -0
  37. package/src/wagmi/Actions/nonce.test.ts +141 -0
  38. package/src/wagmi/Actions/nonce.ts +271 -0
  39. package/src/wagmi/Hooks/index.ts +1 -0
  40. package/src/wagmi/Hooks/nonce.test.ts +207 -0
  41. package/src/wagmi/Hooks/nonce.ts +230 -0
@@ -0,0 +1,230 @@
1
+ import type { DefaultError } from '@tanstack/query-core'
2
+ import type { Config, ResolvedRegister } from '@wagmi/core'
3
+ import { useEffect } from 'react'
4
+ import { useChainId, useConfig } from 'wagmi'
5
+ import type { ConfigParameter, QueryParameter } from 'wagmi/internal'
6
+ import { type UseQueryReturnType, useQuery } from 'wagmi/query'
7
+
8
+ import type { ExactPartial, UnionCompute } from '../../internal/types.js'
9
+ import {
10
+ getNonce,
11
+ getNonceKeyCount,
12
+ watchActiveKeyCountChanged,
13
+ watchNonceIncremented,
14
+ } from '../Actions/nonce.js'
15
+
16
+ /**
17
+ * Hook for getting the nonce for an account and nonce key.
18
+ *
19
+ * @example
20
+ * ```tsx
21
+ * import { Hooks } from 'tempo.ts/wagmi'
22
+ *
23
+ * function App() {
24
+ * const { data, isLoading } = Hooks.nonce.useNonce({
25
+ * account: '0x...',
26
+ * nonceKey: 1n,
27
+ * })
28
+ *
29
+ * if (isLoading) return <div>Loading...</div>
30
+ * return <div>Nonce: {data?.toString()}</div>
31
+ * }
32
+ * ```
33
+ *
34
+ * @param parameters - Parameters.
35
+ * @returns Query result with nonce value.
36
+ */
37
+ export function useNonce<
38
+ config extends Config = ResolvedRegister['config'],
39
+ selectData = getNonce.ReturnValue,
40
+ >(parameters: useNonce.Parameters<config, selectData> = {}) {
41
+ const { account, nonceKey, query = {} } = parameters
42
+
43
+ const config = useConfig(parameters)
44
+ const chainId = useChainId({ config })
45
+
46
+ const options = getNonce.queryOptions(config, {
47
+ ...parameters,
48
+ chainId: parameters.chainId ?? chainId,
49
+ query: undefined,
50
+ })
51
+ const enabled = Boolean(
52
+ account && nonceKey !== undefined && (query.enabled ?? true),
53
+ )
54
+
55
+ return useQuery({ ...query, ...options, enabled })
56
+ }
57
+
58
+ export declare namespace useNonce {
59
+ export type Parameters<
60
+ config extends Config = ResolvedRegister['config'],
61
+ selectData = getNonce.ReturnValue,
62
+ > = ConfigParameter<config> &
63
+ QueryParameter<
64
+ getNonce.ReturnValue,
65
+ DefaultError,
66
+ selectData,
67
+ getNonce.QueryKey<config>
68
+ > &
69
+ ExactPartial<
70
+ Omit<getNonce.queryOptions.Parameters<config, selectData>, 'query'>
71
+ >
72
+
73
+ export type ReturnValue<selectData = getNonce.ReturnValue> =
74
+ UseQueryReturnType<selectData, Error>
75
+ }
76
+
77
+ /**
78
+ * Hook for getting the number of active nonce keys for an account.
79
+ *
80
+ * @example
81
+ * ```tsx
82
+ * import { Hooks } from 'tempo.ts/wagmi'
83
+ *
84
+ * function App() {
85
+ * const { data, isLoading } = Hooks.nonce.useNonceKeyCount({
86
+ * account: '0x...',
87
+ * })
88
+ *
89
+ * if (isLoading) return <div>Loading...</div>
90
+ * return <div>Active keys: {data?.toString()}</div>
91
+ * }
92
+ * ```
93
+ *
94
+ * @param parameters - Parameters.
95
+ * @returns Query result with active nonce key count.
96
+ */
97
+ export function useNonceKeyCount<
98
+ config extends Config = ResolvedRegister['config'],
99
+ selectData = getNonceKeyCount.ReturnValue,
100
+ >(parameters: useNonceKeyCount.Parameters<config, selectData> = {}) {
101
+ const { account, query = {} } = parameters
102
+
103
+ const config = useConfig(parameters)
104
+ const chainId = useChainId({ config })
105
+
106
+ const options = getNonceKeyCount.queryOptions(config, {
107
+ ...parameters,
108
+ chainId: parameters.chainId ?? chainId,
109
+ query: undefined,
110
+ })
111
+ const enabled = Boolean(account && (query.enabled ?? true))
112
+
113
+ return useQuery({ ...query, ...options, enabled })
114
+ }
115
+
116
+ export declare namespace useNonceKeyCount {
117
+ export type Parameters<
118
+ config extends Config = ResolvedRegister['config'],
119
+ selectData = getNonceKeyCount.ReturnValue,
120
+ > = ConfigParameter<config> &
121
+ QueryParameter<
122
+ getNonceKeyCount.ReturnValue,
123
+ DefaultError,
124
+ selectData,
125
+ getNonceKeyCount.QueryKey<config>
126
+ > &
127
+ ExactPartial<
128
+ Omit<
129
+ getNonceKeyCount.queryOptions.Parameters<config, selectData>,
130
+ 'query'
131
+ >
132
+ >
133
+
134
+ export type ReturnValue<selectData = getNonceKeyCount.ReturnValue> =
135
+ UseQueryReturnType<selectData, Error>
136
+ }
137
+
138
+ /**
139
+ * Hook for watching nonce incremented events.
140
+ *
141
+ * @example
142
+ * ```tsx
143
+ * import { Hooks } from 'tempo.ts/wagmi'
144
+ *
145
+ * function App() {
146
+ * Hooks.nonce.useWatchNonceIncremented({
147
+ * onNonceIncremented(args, log) {
148
+ * console.log('Nonce incremented:', args)
149
+ * },
150
+ * })
151
+ *
152
+ * return <div>Watching for nonce increments...</div>
153
+ * }
154
+ * ```
155
+ *
156
+ * @param parameters - Parameters.
157
+ */
158
+ export function useWatchNonceIncremented<
159
+ config extends Config = ResolvedRegister['config'],
160
+ >(parameters: useWatchNonceIncremented.Parameters<config> = {}) {
161
+ const { enabled = true, onNonceIncremented, ...rest } = parameters
162
+
163
+ const config = useConfig({ config: parameters.config })
164
+ const configChainId = useChainId({ config })
165
+ const chainId = parameters.chainId ?? configChainId
166
+
167
+ useEffect(() => {
168
+ if (!enabled) return
169
+ if (!onNonceIncremented) return
170
+ return watchNonceIncremented(config, {
171
+ ...rest,
172
+ chainId,
173
+ onNonceIncremented,
174
+ })
175
+ }, [config, enabled, onNonceIncremented, chainId, rest])
176
+ }
177
+
178
+ export declare namespace useWatchNonceIncremented {
179
+ type Parameters<config extends Config = Config> = UnionCompute<
180
+ ExactPartial<watchNonceIncremented.Parameters<config>> &
181
+ ConfigParameter<config> & { enabled?: boolean | undefined }
182
+ >
183
+ }
184
+
185
+ /**
186
+ * Hook for watching active key count changed events.
187
+ *
188
+ * @example
189
+ * ```tsx
190
+ * import { Hooks } from 'tempo.ts/wagmi'
191
+ *
192
+ * function App() {
193
+ * Hooks.nonce.useWatchActiveKeyCountChanged({
194
+ * onActiveKeyCountChanged(args, log) {
195
+ * console.log('Active key count changed:', args)
196
+ * },
197
+ * })
198
+ *
199
+ * return <div>Watching for active key count changes...</div>
200
+ * }
201
+ * ```
202
+ *
203
+ * @param parameters - Parameters.
204
+ */
205
+ export function useWatchActiveKeyCountChanged<
206
+ config extends Config = ResolvedRegister['config'],
207
+ >(parameters: useWatchActiveKeyCountChanged.Parameters<config> = {}) {
208
+ const { enabled = true, onActiveKeyCountChanged, ...rest } = parameters
209
+
210
+ const config = useConfig({ config: parameters.config })
211
+ const configChainId = useChainId({ config })
212
+ const chainId = parameters.chainId ?? configChainId
213
+
214
+ useEffect(() => {
215
+ if (!enabled) return
216
+ if (!onActiveKeyCountChanged) return
217
+ return watchActiveKeyCountChanged(config, {
218
+ ...rest,
219
+ chainId,
220
+ onActiveKeyCountChanged,
221
+ })
222
+ }, [config, enabled, onActiveKeyCountChanged, chainId, rest])
223
+ }
224
+
225
+ export declare namespace useWatchActiveKeyCountChanged {
226
+ type Parameters<config extends Config = Config> = UnionCompute<
227
+ ExactPartial<watchActiveKeyCountChanged.Parameters<config>> &
228
+ ConfigParameter<config> & { enabled?: boolean | undefined }
229
+ >
230
+ }