tempo.ts 0.8.0 → 0.8.2

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.
@@ -1,6 +1,7 @@
1
1
  import type { DefaultError } from '@tanstack/query-core'
2
2
  import type { UseMutationResult } from '@tanstack/react-query'
3
3
  import type { Config, ResolvedRegister } from '@wagmi/core'
4
+ import { useEffect } from 'react'
4
5
  import { useChainId, useConfig } from 'wagmi'
5
6
  import type { ConfigParameter, QueryParameter } from 'wagmi/internal'
6
7
  import {
@@ -9,7 +10,7 @@ import {
9
10
  useMutation,
10
11
  useQuery,
11
12
  } from 'wagmi/query'
12
- import type { ExactPartial } from '../../internal/types.js'
13
+ import type { ExactPartial, UnionCompute } from '../../internal/types.js'
13
14
  import * as Actions from '../Actions/reward.js'
14
15
 
15
16
  /**
@@ -205,6 +206,74 @@ export declare namespace useGetTotalPerSecond {
205
206
  UseQueryReturnType<selectData, Error>
206
207
  }
207
208
 
209
+ /**
210
+ * Hook for getting the reward information for a specific account.
211
+ *
212
+ * @example
213
+ * ```tsx
214
+ * import { Hooks } from 'tempo.ts/wagmi'
215
+ *
216
+ * function App() {
217
+ * const { data, isLoading } = Hooks.reward.useUserRewardInfo({
218
+ * token: '0x20c0000000000000000000000000000000000001',
219
+ * account: '0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC',
220
+ * })
221
+ *
222
+ * if (isLoading) return <div>Loading...</div>
223
+ * return (
224
+ * <div>
225
+ * <div>Recipient: {data?.rewardRecipient}</div>
226
+ * <div>Reward per token: {data?.rewardPerToken.toString()}</div>
227
+ * <div>Reward balance: {data?.rewardBalance.toString()}</div>
228
+ * </div>
229
+ * )
230
+ * }
231
+ * ```
232
+ *
233
+ * @param parameters - Parameters.
234
+ * @returns Query result with reward information (recipient, rewardPerToken, rewardBalance).
235
+ */
236
+ export function useUserRewardInfo<
237
+ config extends Config = ResolvedRegister['config'],
238
+ selectData = Actions.getUserRewardInfo.ReturnValue,
239
+ >(parameters: useUserRewardInfo.Parameters<config, selectData> = {}) {
240
+ const { account, query = {}, token } = parameters
241
+
242
+ const config = useConfig(parameters)
243
+ const chainId = useChainId({ config })
244
+
245
+ const options = Actions.getUserRewardInfo.queryOptions(config, {
246
+ ...parameters,
247
+ chainId: parameters.chainId ?? chainId,
248
+ query: undefined,
249
+ } as never)
250
+ const enabled = Boolean(token && account && (query.enabled ?? true))
251
+
252
+ return useQuery({ ...query, ...options, enabled })
253
+ }
254
+
255
+ export declare namespace useUserRewardInfo {
256
+ export type Parameters<
257
+ config extends Config = ResolvedRegister['config'],
258
+ selectData = Actions.getUserRewardInfo.ReturnValue,
259
+ > = ConfigParameter<config> &
260
+ QueryParameter<
261
+ Actions.getUserRewardInfo.ReturnValue,
262
+ DefaultError,
263
+ selectData,
264
+ Actions.getUserRewardInfo.QueryKey<config>
265
+ > &
266
+ ExactPartial<
267
+ Omit<
268
+ Actions.getUserRewardInfo.queryOptions.Parameters<config, selectData>,
269
+ 'query'
270
+ >
271
+ >
272
+
273
+ export type ReturnValue<selectData = Actions.getUserRewardInfo.ReturnValue> =
274
+ UseQueryReturnType<selectData, Error>
275
+ }
276
+
208
277
  /**
209
278
  * Hook for setting the reward recipient for a token holder.
210
279
  *
@@ -474,3 +543,103 @@ export declare namespace useStartSync {
474
543
  context
475
544
  >
476
545
  }
546
+
547
+ /**
548
+ * Hook for watching reward scheduled events.
549
+ *
550
+ * @example
551
+ * ```tsx
552
+ * import { Hooks } from 'tempo.ts/wagmi'
553
+ *
554
+ * function App() {
555
+ * Hooks.reward.useWatchRewardScheduled({
556
+ * token: '0x20c0000000000000000000000000000000000001',
557
+ * onRewardScheduled(args) {
558
+ * console.log('Reward scheduled:', args)
559
+ * },
560
+ * })
561
+ *
562
+ * return <div>Watching for reward scheduled events...</div>
563
+ * }
564
+ * ```
565
+ *
566
+ * @param parameters - Parameters.
567
+ */
568
+ export function useWatchRewardScheduled<
569
+ config extends Config = ResolvedRegister['config'],
570
+ >(parameters: useWatchRewardScheduled.Parameters<config> = {}) {
571
+ const { enabled = true, onRewardScheduled, token, ...rest } = parameters
572
+
573
+ const config = useConfig({ config: parameters.config })
574
+ const configChainId = useChainId({ config })
575
+ const chainId = parameters.chainId ?? configChainId
576
+
577
+ useEffect(() => {
578
+ if (!enabled) return
579
+ if (!onRewardScheduled) return
580
+ if (!token) return
581
+ return Actions.watchRewardScheduled(config, {
582
+ ...rest,
583
+ chainId,
584
+ onRewardScheduled,
585
+ token,
586
+ })
587
+ }, [config, enabled, onRewardScheduled, rest, chainId, token])
588
+ }
589
+
590
+ export declare namespace useWatchRewardScheduled {
591
+ type Parameters<config extends Config = Config> = UnionCompute<
592
+ ExactPartial<Actions.watchRewardScheduled.Parameters<config>> &
593
+ ConfigParameter<config> & { enabled?: boolean | undefined }
594
+ >
595
+ }
596
+
597
+ /**
598
+ * Hook for watching reward recipient set events.
599
+ *
600
+ * @example
601
+ * ```tsx
602
+ * import { Hooks } from 'tempo.ts/wagmi'
603
+ *
604
+ * function App() {
605
+ * Hooks.reward.useWatchRewardRecipientSet({
606
+ * token: '0x20c0000000000000000000000000000000000001',
607
+ * onRewardRecipientSet(args) {
608
+ * console.log('Reward recipient set:', args)
609
+ * },
610
+ * })
611
+ *
612
+ * return <div>Watching for reward recipient set events...</div>
613
+ * }
614
+ * ```
615
+ *
616
+ * @param parameters - Parameters.
617
+ */
618
+ export function useWatchRewardRecipientSet<
619
+ config extends Config = ResolvedRegister['config'],
620
+ >(parameters: useWatchRewardRecipientSet.Parameters<config> = {}) {
621
+ const { enabled = true, onRewardRecipientSet, token, ...rest } = parameters
622
+
623
+ const config = useConfig({ config: parameters.config })
624
+ const configChainId = useChainId({ config })
625
+ const chainId = parameters.chainId ?? configChainId
626
+
627
+ useEffect(() => {
628
+ if (!enabled) return
629
+ if (!onRewardRecipientSet) return
630
+ if (!token) return
631
+ return Actions.watchRewardRecipientSet(config, {
632
+ ...rest,
633
+ chainId,
634
+ onRewardRecipientSet,
635
+ token,
636
+ })
637
+ }, [config, enabled, onRewardRecipientSet, rest, chainId, token])
638
+ }
639
+
640
+ export declare namespace useWatchRewardRecipientSet {
641
+ type Parameters<config extends Config = Config> = UnionCompute<
642
+ ExactPartial<Actions.watchRewardRecipientSet.Parameters<config>> &
643
+ ConfigParameter<config> & { enabled?: boolean | undefined }
644
+ >
645
+ }