hiero-sdk-utils-react 0.1.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 (37) hide show
  1. package/dist/esm/HieroProvider.d.ts +32 -0
  2. package/dist/esm/HieroProvider.d.ts.map +1 -0
  3. package/dist/esm/HieroProvider.js +35 -0
  4. package/dist/esm/HieroProvider.js.map +1 -0
  5. package/dist/esm/hooks/useAccount.d.ts +16 -0
  6. package/dist/esm/hooks/useAccount.d.ts.map +1 -0
  7. package/dist/esm/hooks/useAccount.js +50 -0
  8. package/dist/esm/hooks/useAccount.js.map +1 -0
  9. package/dist/esm/hooks/useAccountTransactions.d.ts +17 -0
  10. package/dist/esm/hooks/useAccountTransactions.d.ts.map +1 -0
  11. package/dist/esm/hooks/useAccountTransactions.js +67 -0
  12. package/dist/esm/hooks/useAccountTransactions.js.map +1 -0
  13. package/dist/esm/hooks/useNFTs.d.ts +22 -0
  14. package/dist/esm/hooks/useNFTs.d.ts.map +1 -0
  15. package/dist/esm/hooks/useNFTs.js +63 -0
  16. package/dist/esm/hooks/useNFTs.js.map +1 -0
  17. package/dist/esm/hooks/useToken.d.ts +15 -0
  18. package/dist/esm/hooks/useToken.d.ts.map +1 -0
  19. package/dist/esm/hooks/useToken.js +49 -0
  20. package/dist/esm/hooks/useToken.js.map +1 -0
  21. package/dist/esm/hooks/useTopicMessages.d.ts +16 -0
  22. package/dist/esm/hooks/useTopicMessages.d.ts.map +1 -0
  23. package/dist/esm/hooks/useTopicMessages.js +62 -0
  24. package/dist/esm/hooks/useTopicMessages.js.map +1 -0
  25. package/dist/esm/hooks/useTransaction.d.ts +15 -0
  26. package/dist/esm/hooks/useTransaction.d.ts.map +1 -0
  27. package/dist/esm/hooks/useTransaction.js +49 -0
  28. package/dist/esm/hooks/useTransaction.js.map +1 -0
  29. package/dist/esm/index.d.ts +38 -0
  30. package/dist/esm/index.d.ts.map +1 -0
  31. package/dist/esm/index.js +37 -0
  32. package/dist/esm/index.js.map +1 -0
  33. package/dist/esm/types.d.ts +16 -0
  34. package/dist/esm/types.d.ts.map +1 -0
  35. package/dist/esm/types.js +3 -0
  36. package/dist/esm/types.js.map +1 -0
  37. package/package.json +53 -0
@@ -0,0 +1,32 @@
1
+ import React from 'react';
2
+ import type { HieroClient } from 'hiero-sdk-utils';
3
+ /**
4
+ * Props for the HieroProvider component.
5
+ */
6
+ export interface HieroProviderProps {
7
+ /** The HieroClient instance to provide to all descendant hooks */
8
+ client: HieroClient;
9
+ children: React.ReactNode;
10
+ }
11
+ /**
12
+ * Provides a HieroClient instance to all descendant hooks.
13
+ * Place this once at the root of your application.
14
+ *
15
+ * @example
16
+ * ```tsx
17
+ * const client = new HieroClient({ baseUrl: Networks.mainnet });
18
+ *
19
+ * <HieroProvider client={client}>
20
+ * <App />
21
+ * </HieroProvider>
22
+ * ```
23
+ */
24
+ export declare function HieroProvider({ client, children }: HieroProviderProps): JSX.Element;
25
+ /**
26
+ * Returns the HieroClient from the nearest HieroProvider.
27
+ * Throws a clear error if called outside a HieroProvider.
28
+ *
29
+ * @internal
30
+ */
31
+ export declare function useHieroClient(): HieroClient;
32
+ //# sourceMappingURL=HieroProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HieroProvider.d.ts","sourceRoot":"","sources":["../../src/HieroProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAoC,MAAM,OAAO,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAInD;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,kEAAkE;IAClE,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,kBAAkB,GAAG,GAAG,CAAC,OAAO,CAMnF;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,IAAI,WAAW,CAS5C"}
@@ -0,0 +1,35 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { createContext, useContext } from 'react';
4
+ const HieroContext = createContext(null);
5
+ /**
6
+ * Provides a HieroClient instance to all descendant hooks.
7
+ * Place this once at the root of your application.
8
+ *
9
+ * @example
10
+ * ```tsx
11
+ * const client = new HieroClient({ baseUrl: Networks.mainnet });
12
+ *
13
+ * <HieroProvider client={client}>
14
+ * <App />
15
+ * </HieroProvider>
16
+ * ```
17
+ */
18
+ export function HieroProvider({ client, children }) {
19
+ return (_jsx(HieroContext.Provider, { value: client, children: children }));
20
+ }
21
+ /**
22
+ * Returns the HieroClient from the nearest HieroProvider.
23
+ * Throws a clear error if called outside a HieroProvider.
24
+ *
25
+ * @internal
26
+ */
27
+ export function useHieroClient() {
28
+ const client = useContext(HieroContext);
29
+ if (client === null) {
30
+ throw new Error('useHieroClient must be used within a HieroProvider. ' +
31
+ 'Wrap your component tree with <HieroProvider client={client}>.');
32
+ }
33
+ return client;
34
+ }
35
+ //# sourceMappingURL=HieroProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HieroProvider.js","sourceRoot":"","sources":["../../src/HieroProvider.tsx"],"names":[],"mappings":";AAAA,sCAAsC;AAEtC,OAAc,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAGzD,MAAM,YAAY,GAAG,aAAa,CAAqB,IAAI,CAAC,CAAC;AAW7D;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,aAAa,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAsB;IACpE,OAAO,CACL,KAAC,YAAY,CAAC,QAAQ,IAAC,KAAK,EAAE,MAAM,YACjC,QAAQ,GACa,CACzB,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc;IAC5B,MAAM,MAAM,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;IACxC,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CACb,sDAAsD;YACtD,gEAAgE,CACjE,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,16 @@
1
+ import type { AccountInfo } from 'hiero-sdk-utils';
2
+ import type { HieroQueryResult } from '../types.js';
3
+ /**
4
+ * Fetches account information by ID from the Hedera Mirror Node.
5
+ * Pass `null` to skip the fetch (e.g., when the ID is not yet known).
6
+ *
7
+ * @param accountId - Account in `0.0.X` format, or null to skip
8
+ * @returns Query result with AccountInfo data, loading state, and error
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * const { data, loading, error } = useAccount('0.0.1234');
13
+ * ```
14
+ */
15
+ export declare function useAccount(accountId: string | null): HieroQueryResult<AccountInfo>;
16
+ //# sourceMappingURL=useAccount.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAccount.d.ts","sourceRoot":"","sources":["../../../src/hooks/useAccount.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAGpD;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,gBAAgB,CAAC,WAAW,CAAC,CAoClF"}
@@ -0,0 +1,50 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ import { useState, useEffect, useCallback } from 'react';
3
+ import { useHieroClient } from '../HieroProvider.js';
4
+ /**
5
+ * Fetches account information by ID from the Hedera Mirror Node.
6
+ * Pass `null` to skip the fetch (e.g., when the ID is not yet known).
7
+ *
8
+ * @param accountId - Account in `0.0.X` format, or null to skip
9
+ * @returns Query result with AccountInfo data, loading state, and error
10
+ *
11
+ * @example
12
+ * ```tsx
13
+ * const { data, loading, error } = useAccount('0.0.1234');
14
+ * ```
15
+ */
16
+ export function useAccount(accountId) {
17
+ const client = useHieroClient();
18
+ const [data, setData] = useState(null);
19
+ const [loading, setLoading] = useState(false);
20
+ const [error, setError] = useState(null);
21
+ const [tick, setTick] = useState(0);
22
+ const refetch = useCallback(() => { setTick(t => t + 1); }, []);
23
+ useEffect(() => {
24
+ if (accountId === null) {
25
+ setData(null);
26
+ setLoading(false);
27
+ setError(null);
28
+ return () => { };
29
+ }
30
+ let cancelled = false;
31
+ setLoading(true);
32
+ setError(null);
33
+ client.accounts.getById(accountId)
34
+ .then((result) => {
35
+ if (!cancelled) {
36
+ setData(result);
37
+ setLoading(false);
38
+ }
39
+ })
40
+ .catch((err) => {
41
+ if (!cancelled) {
42
+ setError(err instanceof Error ? err : new Error(String(err)));
43
+ setLoading(false);
44
+ }
45
+ });
46
+ return () => { cancelled = true; };
47
+ }, [accountId, client, tick]);
48
+ return { data, loading, error, refetch };
49
+ }
50
+ //# sourceMappingURL=useAccount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAccount.js","sourceRoot":"","sources":["../../../src/hooks/useAccount.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAGzD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,UAAU,CAAC,SAAwB;IACjD,MAAM,MAAM,GAAG,cAAc,EAAE,CAAC;IAChC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAqB,IAAI,CAAC,CAAC;IAC3D,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAU,KAAK,CAAC,CAAC;IACvD,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAe,IAAI,CAAC,CAAC;IACvD,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAC,CAAC,CA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AE,KAAK,EAAE,OAAO,EAAE,CAAC;AAC3C,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { TransactionInfo, TransactionsQueryParams } from 'hiero-sdk-utils';
2
+ import type { HieroQueryResult } from '../types.js';
3
+ /**
4
+ * Fetches the first page of transactions for an account from the Hedera Mirror Node.
5
+ * The accountId is injected as `account.id` in the query params automatically.
6
+ *
7
+ * @param accountId - Account in `0.0.X` format, or null to skip
8
+ * @param params - Optional query parameters for filtering
9
+ * @returns Query result with TransactionInfo array, loading state, and error
10
+ *
11
+ * @example
12
+ * ```tsx
13
+ * const { data: txs } = useAccountTransactions('0.0.1234', { limit: 10 });
14
+ * ```
15
+ */
16
+ export declare function useAccountTransactions(accountId: string | null, params?: TransactionsQueryParams): HieroQueryResult<TransactionInfo[]>;
17
+ //# sourceMappingURL=useAccountTransactions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAccountTransactions.d.ts","sourceRoot":"","sources":["../../../src/hooks/useAccountTransactions.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAChF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAGpD;;;;;;;;;;;;GAYG;AACH,wBAAgB,sBAAsB,CACpC,SAAS,EAAE,MAAM,GAAG,IAAI,EACxB,MAAM,CAAC,EAAE,uBAAuB,GAC/B,gBAAgB,CAAC,eAAe,EAAE,CAAC,CAoDrC"}
@@ -0,0 +1,67 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ import { useState, useEffect, useCallback } from 'react';
3
+ import { useHieroClient } from '../HieroProvider.js';
4
+ /**
5
+ * Fetches the first page of transactions for an account from the Hedera Mirror Node.
6
+ * The accountId is injected as `account.id` in the query params automatically.
7
+ *
8
+ * @param accountId - Account in `0.0.X` format, or null to skip
9
+ * @param params - Optional query parameters for filtering
10
+ * @returns Query result with TransactionInfo array, loading state, and error
11
+ *
12
+ * @example
13
+ * ```tsx
14
+ * const { data: txs } = useAccountTransactions('0.0.1234', { limit: 10 });
15
+ * ```
16
+ */
17
+ export function useAccountTransactions(accountId, params) {
18
+ const client = useHieroClient();
19
+ const [data, setData] = useState(null);
20
+ const [loading, setLoading] = useState(false);
21
+ const [error, setError] = useState(null);
22
+ const [tick, setTick] = useState(0);
23
+ const refetch = useCallback(() => { setTick(t => t + 1); }, []);
24
+ const limit = params?.limit;
25
+ useEffect(() => {
26
+ if (accountId === null) {
27
+ setData(null);
28
+ setLoading(false);
29
+ setError(null);
30
+ return () => { };
31
+ }
32
+ let cancelled = false;
33
+ setLoading(true);
34
+ setError(null);
35
+ const effectiveLimit = limit ?? 25;
36
+ const paramsWithLimit = {
37
+ ...params,
38
+ 'account.id': accountId,
39
+ limit: effectiveLimit,
40
+ };
41
+ void (async () => {
42
+ const results = [];
43
+ try {
44
+ for await (const tx of client.transactions.list(paramsWithLimit)) {
45
+ results.push(tx);
46
+ if (results.length >= effectiveLimit)
47
+ break;
48
+ }
49
+ if (!cancelled) {
50
+ setData(results);
51
+ setLoading(false);
52
+ }
53
+ }
54
+ catch (err) {
55
+ if (!cancelled) {
56
+ setError(err instanceof Error ? err : new Error(String(err)));
57
+ setLoading(false);
58
+ }
59
+ }
60
+ })();
61
+ return () => { cancelled = true; };
62
+ // Only limit is tracked from params — not the full object — to avoid re-render
63
+ // loops when callers pass inline objects. Other param changes need a new hook call.
64
+ }, [accountId, limit, client, tick]);
65
+ return { data, loading, error, refetch };
66
+ }
67
+ //# sourceMappingURL=useAccountTransactions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAccountTransactions.js","sourceRoot":"","sources":["../../../src/hooks/useAccountTransactions.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAGzD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD;;;;;;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,IAAI,KAAK,EAAE,MAAM,EAAE,IAAI,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC;oBACjE,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;oBACjB,IAAI,OAAO,CAAC,MAAM,IAAI,cAAc;wBAAE,MAAM;gBAC9C,CAAC;gBACD,IAAI,CAAC,SAAS,EAAE,CAAC;oBAAC,OAAO,CAAC,OAAO,CAAC,CAAC;oBAAC,UAAU,CAAC,KAAK,CAAC,CAAC;gBAAC,CAAC;YAC1D,CAAC;YAAC,OAAO,GAAY,EAAE,CAAC;gBACtB,IAAI,CAAC,SAAS,EAAE,CAAC;oBACf,QAAQ,CAAC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;oBAC9D,UAAU,CAAC,KAAK,CAAC,CAAC;gBACpB,CAAC;YACH,CAAC;QACH,CAAC,CAAC,EAAE,CAAC;QAEL,OAAO,GAAS,EAAE,GAAG,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACzC,+EAA+E;QAC/E,oFAAoF;IACtF,CAAC,EAAE,CAAC,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;IAErC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;AAC3C,CAAC"}
@@ -0,0 +1,22 @@
1
+ import type { NftInfo, NftsQueryParams } from 'hiero-sdk-utils';
2
+ import type { HieroQueryResult } from '../types.js';
3
+ /**
4
+ * Hook-specific params: excludes serialnumber (use client.nfts.getByTokenAndSerial for that).
5
+ */
6
+ type NftsHookParams = Omit<NftsQueryParams, 'serialnumber'>;
7
+ /**
8
+ * Fetches the first page of NFTs for a token from the Hedera Mirror Node.
9
+ * Default page size is 25. Pass `limit` in params to change.
10
+ *
11
+ * @param tokenId - Token in `0.0.X` format, or null to skip
12
+ * @param params - Optional query parameters (excludes serialnumber)
13
+ * @returns Query result with NftInfo array, loading state, and error
14
+ *
15
+ * @example
16
+ * ```tsx
17
+ * const { data: nfts } = useNFTs('0.0.5678', { limit: 10 });
18
+ * ```
19
+ */
20
+ export declare function useNFTs(tokenId: string | null, params?: NftsHookParams): HieroQueryResult<NftInfo[]>;
21
+ export {};
22
+ //# sourceMappingURL=useNFTs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useNFTs.d.ts","sourceRoot":"","sources":["../../../src/hooks/useNFTs.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAGpD;;GAEG;AACH,KAAK,cAAc,GAAG,IAAI,CAAC,eAAe,EAAE,cAAc,CAAC,CAAC;AAE5D;;;;;;;;;;;;GAYG;AACH,wBAAgB,OAAO,CACrB,OAAO,EAAE,MAAM,GAAG,IAAI,EACtB,MAAM,CAAC,EAAE,cAAc,GACtB,gBAAgB,CAAC,OAAO,EAAE,CAAC,CAgD7B"}
@@ -0,0 +1,63 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ import { useState, useEffect, useCallback } from 'react';
3
+ import { useHieroClient } from '../HieroProvider.js';
4
+ /**
5
+ * Fetches the first page of NFTs for a token from the Hedera Mirror Node.
6
+ * Default page size is 25. Pass `limit` in params to change.
7
+ *
8
+ * @param tokenId - Token in `0.0.X` format, or null to skip
9
+ * @param params - Optional query parameters (excludes serialnumber)
10
+ * @returns Query result with NftInfo array, loading state, and error
11
+ *
12
+ * @example
13
+ * ```tsx
14
+ * const { data: nfts } = useNFTs('0.0.5678', { limit: 10 });
15
+ * ```
16
+ */
17
+ export function useNFTs(tokenId, params) {
18
+ const client = useHieroClient();
19
+ const [data, setData] = useState(null);
20
+ const [loading, setLoading] = useState(false);
21
+ const [error, setError] = useState(null);
22
+ const [tick, setTick] = useState(0);
23
+ const refetch = useCallback(() => { setTick(t => t + 1); }, []);
24
+ const limit = params?.limit;
25
+ useEffect(() => {
26
+ if (tokenId === null) {
27
+ setData(null);
28
+ setLoading(false);
29
+ setError(null);
30
+ return () => { };
31
+ }
32
+ let cancelled = false;
33
+ setLoading(true);
34
+ setError(null);
35
+ const effectiveLimit = limit ?? 25;
36
+ const paramsWithLimit = { ...params, limit: effectiveLimit };
37
+ void (async () => {
38
+ const results = [];
39
+ try {
40
+ for await (const nft of client.nfts.listByToken(tokenId, paramsWithLimit)) {
41
+ results.push(nft);
42
+ if (results.length >= effectiveLimit)
43
+ break;
44
+ }
45
+ if (!cancelled) {
46
+ setData(results);
47
+ setLoading(false);
48
+ }
49
+ }
50
+ catch (err) {
51
+ if (!cancelled) {
52
+ setError(err instanceof Error ? err : new Error(String(err)));
53
+ setLoading(false);
54
+ }
55
+ }
56
+ })();
57
+ return () => { cancelled = true; };
58
+ // Only limit is tracked from params — not the full object — to avoid re-render
59
+ // loops when callers pass inline objects. Other param changes need a new hook call.
60
+ }, [tokenId, limit, client, tick]);
61
+ return { data, loading, error, refetch };
62
+ }
63
+ //# sourceMappingURL=useNFTs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useNFTs.js","sourceRoot":"","sources":["../../../src/hooks/useNFTs.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAGzD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAOrD;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,OAAO,CACrB,OAAsB,EACtB,MAAuB;IAEvB,MAAM,MAAM,GAAG,cAAc,EAAE,CAAC;IAChC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAmB,IAAI,CAAC,CAAC;IACzD,MAAM,CAAC,OAAO,EAAE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I,CAAC,SAAS,EAAE,CAAC;oBAAC,OAAO,CAAC,OAAO,CAAC,CAAC;oBAAC,UAAU,CAAC,KAAK,CAAC,CAAC;gBAAC,CAAC;YAC1D,CAAC;YAAC,OAAO,GAAY,EAAE,CAAC;gBACtB,IAAI,CAAC,SAAS,EAAE,CAAC;oBACf,QAAQ,CAAC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;oBAC9D,UAAU,CAAC,KAAK,CAAC,CAAC;gBACpB,CAAC;YACH,CAAC;QACH,CAAC,CAAC,EAAE,CAAC;QAEL,OAAO,GAAS,EAAE,GAAG,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACzC,+EAA+E;QAC/E,oFAAoF;IACtF,CAAC,EAAE,CAAC,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;IAEnC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;AAC3C,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { TokenInfo } from 'hiero-sdk-utils';
2
+ import type { HieroQueryResult } from '../types.js';
3
+ /**
4
+ * Fetches token information by ID from the Hedera Mirror Node.
5
+ *
6
+ * @param tokenId - Token in `0.0.X` format, or null to skip
7
+ * @returns Query result with TokenInfo data, loading state, and error
8
+ *
9
+ * @example
10
+ * ```tsx
11
+ * const { data } = useToken('0.0.5678');
12
+ * ```
13
+ */
14
+ export declare function useToken(tokenId: string | null): HieroQueryResult<TokenInfo>;
15
+ //# sourceMappingURL=useToken.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useToken.d.ts","sourceRoot":"","sources":["../../../src/hooks/useToken.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAGpD;;;;;;;;;;GAUG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,gBAAgB,CAAC,SAAS,CAAC,CAoC5E"}
@@ -0,0 +1,49 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ import { useState, useEffect, useCallback } from 'react';
3
+ import { useHieroClient } from '../HieroProvider.js';
4
+ /**
5
+ * Fetches token information by ID from the Hedera Mirror Node.
6
+ *
7
+ * @param tokenId - Token in `0.0.X` format, or null to skip
8
+ * @returns Query result with TokenInfo data, loading state, and error
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * const { data } = useToken('0.0.5678');
13
+ * ```
14
+ */
15
+ export function useToken(tokenId) {
16
+ const client = useHieroClient();
17
+ const [data, setData] = useState(null);
18
+ const [loading, setLoading] = useState(false);
19
+ const [error, setError] = useState(null);
20
+ const [tick, setTick] = useState(0);
21
+ const refetch = useCallback(() => { setTick(t => t + 1); }, []);
22
+ useEffect(() => {
23
+ if (tokenId === null) {
24
+ setData(null);
25
+ setLoading(false);
26
+ setError(null);
27
+ return () => { };
28
+ }
29
+ let cancelled = false;
30
+ setLoading(true);
31
+ setError(null);
32
+ client.tokens.getById(tokenId)
33
+ .then((result) => {
34
+ if (!cancelled) {
35
+ setData(result);
36
+ setLoading(false);
37
+ }
38
+ })
39
+ .catch((err) => {
40
+ if (!cancelled) {
41
+ setError(err instanceof Error ? err : new Error(String(err)));
42
+ setLoading(false);
43
+ }
44
+ });
45
+ return () => { cancelled = true; };
46
+ }, [tokenId, client, tick]);
47
+ return { data, loading, error, refetch };
48
+ }
49
+ //# sourceMappingURL=useToken.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useToken.js","sourceRoot":"","sources":["../../../src/hooks/useToken.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAG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CAAC,GAAY,EAAQ,EAAE;YAC5B,IAAI,CAAC,SAAS,EAAE,CAAC;gBACf,QAAQ,CAAC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;gBAC9D,UAAU,CAAC,KAAK,CAAC,CAAC;YACpB,CAAC;QACH,CAAC,CAAC,CAAC;QAEL,OAAO,GAAS,EAAE,GAAG,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IAC3C,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;IAE5B,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;AAC3C,CAAC"}
@@ -0,0 +1,16 @@
1
+ import type { TopicMessage, TopicMessagesQueryParams } from 'hiero-sdk-utils';
2
+ import type { HieroQueryResult } from '../types.js';
3
+ /**
4
+ * Fetches the first page of HCS messages for a topic from the Hedera Mirror Node.
5
+ *
6
+ * @param topicId - Topic in `0.0.X` format, or null to skip
7
+ * @param params - Optional query parameters for filtering
8
+ * @returns Query result with TopicMessage array, loading state, and error
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * const { data: messages } = useTopicMessages('0.0.7777', { limit: 20 });
13
+ * ```
14
+ */
15
+ export declare function useTopicMessages(topicId: string | null, params?: TopicMessagesQueryParams): HieroQueryResult<TopicMessage[]>;
16
+ //# sourceMappingURL=useTopicMessages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTopicMessages.d.ts","sourceRoot":"","sources":["../../../src/hooks/useTopicMessages.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC9E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAGpD;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,MAAM,GAAG,IAAI,EACtB,MAAM,CAAC,EAAE,wBAAwB,GAChC,gBAAgB,CAAC,YAAY,EAAE,CAAC,CAgDlC"}
@@ -0,0 +1,62 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ import { useState, useEffect, useCallback } from 'react';
3
+ import { useHieroClient } from '../HieroProvider.js';
4
+ /**
5
+ * Fetches the first page of HCS messages for a topic from the Hedera Mirror Node.
6
+ *
7
+ * @param topicId - Topic in `0.0.X` format, or null to skip
8
+ * @param params - Optional query parameters for filtering
9
+ * @returns Query result with TopicMessage array, loading state, and error
10
+ *
11
+ * @example
12
+ * ```tsx
13
+ * const { data: messages } = useTopicMessages('0.0.7777', { limit: 20 });
14
+ * ```
15
+ */
16
+ export function useTopicMessages(topicId, params) {
17
+ const client = useHieroClient();
18
+ const [data, setData] = useState(null);
19
+ const [loading, setLoading] = useState(false);
20
+ const [error, setError] = useState(null);
21
+ const [tick, setTick] = useState(0);
22
+ const refetch = useCallback(() => { setTick(t => t + 1); }, []);
23
+ const limit = params?.limit;
24
+ useEffect(() => {
25
+ if (topicId === null) {
26
+ setData(null);
27
+ setLoading(false);
28
+ setError(null);
29
+ return () => { };
30
+ }
31
+ let cancelled = false;
32
+ setLoading(true);
33
+ setError(null);
34
+ const effectiveLimit = limit ?? 25;
35
+ const paramsWithLimit = { ...params, limit: effectiveLimit };
36
+ void (async () => {
37
+ const results = [];
38
+ try {
39
+ for await (const msg of client.topics.listMessages(topicId, paramsWithLimit)) {
40
+ results.push(msg);
41
+ if (results.length >= effectiveLimit)
42
+ break;
43
+ }
44
+ if (!cancelled) {
45
+ setData(results);
46
+ setLoading(false);
47
+ }
48
+ }
49
+ catch (err) {
50
+ if (!cancelled) {
51
+ setError(err instanceof Error ? err : new Error(String(err)));
52
+ setLoading(false);
53
+ }
54
+ }
55
+ })();
56
+ return () => { cancelled = true; };
57
+ // Only limit is tracked from params — not the full object — to avoid re-render
58
+ // loops when callers pass inline objects. Other param changes need a new hook call.
59
+ }, [topicId, limit, client, tick]);
60
+ return { data, loading, error, refetch };
61
+ }
62
+ //# sourceMappingURL=useTopicMessages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTopicMessages.js","sourceRoot":"","sources":["../../../src/hooks/useTopicMessages.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAGzD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,gBAAgB,CAC9B,OAAsB,EACtB,MAAiC;IAEjC,MAAM,MAAM,GAAG,cAAc,EAAE,CAAC;IAChC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAwB,IAAI,CAAC,CAAC;IAC9D,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAU,KAAK,CAAC,CAAC;IACvD,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAe,IAAI,CAAC,CAAC;IACvD,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;IAEpC,MAAM,OAAO,GAAG,WAAW,CAAC,GAAS,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAEtE,MAAM,KAAK,GAAG,MAAM,EAAE,KAAK,CAAC;IAE5B,SAAS,CAAC,GAAiB,EAAE;QAC3B,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;YACrB,OAAO,CAAC,IAAI,CAAC,CAAC;YACd,UAAU,CAAC,KAAK,CAAC,CAAC;YAClB,QAAQ,CAAC,IAAI,CAAC,CAAC;YACf,OAAO,GAAS,EAAE,GAA2B,CAAC,CAAC;QACjD,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EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;AAC3C,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { TransactionInfo } from 'hiero-sdk-utils';
2
+ import type { HieroQueryResult } from '../types.js';
3
+ /**
4
+ * Fetches a single transaction by ID from the Hedera Mirror Node.
5
+ *
6
+ * @param transactionId - Transaction ID in `0.0.X-secs-nanos` format, or null to skip
7
+ * @returns Query result with TransactionInfo data, loading state, and error
8
+ *
9
+ * @example
10
+ * ```tsx
11
+ * const { data } = useTransaction('0.0.1234-1234567890-000000001');
12
+ * ```
13
+ */
14
+ export declare function useTransaction(transactionId: string | null): HieroQueryResult<TransactionInfo>;
15
+ //# sourceMappingURL=useTransaction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTransaction.d.ts","sourceRoot":"","sources":["../../../src/hooks/useTransaction.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAGpD;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,aAAa,EAAE,MAAM,GAAG,IAAI,GAAG,gBAAgB,CAAC,eAAe,CAAC,CAoC9F"}
@@ -0,0 +1,49 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ import { useState, useEffect, useCallback } from 'react';
3
+ import { useHieroClient } from '../HieroProvider.js';
4
+ /**
5
+ * Fetches a single transaction by ID from the Hedera Mirror Node.
6
+ *
7
+ * @param transactionId - Transaction ID in `0.0.X-secs-nanos` format, or null to skip
8
+ * @returns Query result with TransactionInfo data, loading state, and error
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * const { data } = useTransaction('0.0.1234-1234567890-000000001');
13
+ * ```
14
+ */
15
+ export function useTransaction(transactionId) {
16
+ const client = useHieroClient();
17
+ const [data, setData] = useState(null);
18
+ const [loading, setLoading] = useState(false);
19
+ const [error, setError] = useState(null);
20
+ const [tick, setTick] = useState(0);
21
+ const refetch = useCallback(() => { setTick(t => t + 1); }, []);
22
+ useEffect(() => {
23
+ if (transactionId === null) {
24
+ setData(null);
25
+ setLoading(false);
26
+ setError(null);
27
+ return () => { };
28
+ }
29
+ let cancelled = false;
30
+ setLoading(true);
31
+ setError(null);
32
+ client.transactions.getById(transactionId)
33
+ .then((result) => {
34
+ if (!cancelled) {
35
+ setData(result);
36
+ setLoading(false);
37
+ }
38
+ })
39
+ .catch((err) => {
40
+ if (!cancelled) {
41
+ setError(err instanceof Error ? err : new Error(String(err)));
42
+ setLoading(false);
43
+ }
44
+ });
45
+ return () => { cancelled = true; };
46
+ }, [transactionId, client, tick]);
47
+ return { data, loading, error, refetch };
48
+ }
49
+ //# sourceMappingURL=useTransaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTransaction.js","sourceRoot":"","sources":["../../../src/hooks/useTransaction.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAGzD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,cAAc,CAAC,aAA4B;IACzD,MAAM,MAAM,GAAG,cAAc,EAAE,CAAC;IAChC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAyB,IAAI,CAAC,CAAC;IAC/D,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAU,KAAK,CAAC,CAAC;IACvD,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAe,IAAI,CAAC,CAAC;IACvD,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;IAEpC,MAAM,OAAO,GAAG,WAAW,CAAC,GAAS,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC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edera/Hiero Mirror Node.
3
+ *
4
+ * @example
5
+ * ```tsx
6
+ * import { HieroClient, Networks } from 'hiero-sdk-utils';
7
+ * import { HieroProvider, useAccount } from 'hiero-sdk-utils-react';
8
+ *
9
+ * const client = new HieroClient({ baseUrl: Networks.mainnet });
10
+ *
11
+ * function App() {
12
+ * return (
13
+ * <HieroProvider client={client}>
14
+ * <AccountView />
15
+ * </HieroProvider>
16
+ * );
17
+ * }
18
+ *
19
+ * function AccountView() {
20
+ * const { data, loading, error } = useAccount('0.0.1234');
21
+ * if (loading) return <span>Loading...</span>;
22
+ * if (error) return <span>Error: {error.message}</span>;
23
+ * return <span>{data?.balance.balance} tinybars</span>;
24
+ * }
25
+ * ```
26
+ *
27
+ * @packageDocumentation
28
+ */
29
+ export { HieroProvider } from './HieroProvider.js';
30
+ export type { HieroProviderProps } from './HieroProvider.js';
31
+ export type { HieroQueryResult } from './types.js';
32
+ export { useAccount } from './hooks/useAccount.js';
33
+ export { useTransaction } from './hooks/useTransaction.js';
34
+ export { useToken } from './hooks/useToken.js';
35
+ export { useNFTs } from './hooks/useNFTs.js';
36
+ export { useAccountTransactions } from './hooks/useAccountTransactions.js';
37
+ export { useTopicMessages } from './hooks/useTopicMessages.js';
38
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,YAAY,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAC3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC"}
@@ -0,0 +1,37 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ /**
3
+ * hiero-sdk-utils-react — React hooks for the Hedera/Hiero Mirror Node.
4
+ *
5
+ * @example
6
+ * ```tsx
7
+ * import { HieroClient, Networks } from 'hiero-sdk-utils';
8
+ * import { HieroProvider, useAccount } from 'hiero-sdk-utils-react';
9
+ *
10
+ * const client = new HieroClient({ baseUrl: Networks.mainnet });
11
+ *
12
+ * function App() {
13
+ * return (
14
+ * <HieroProvider client={client}>
15
+ * <AccountView />
16
+ * </HieroProvider>
17
+ * );
18
+ * }
19
+ *
20
+ * function AccountView() {
21
+ * const { data, loading, error } = useAccount('0.0.1234');
22
+ * if (loading) return <span>Loading...</span>;
23
+ * if (error) return <span>Error: {error.message}</span>;
24
+ * return <span>{data?.balance.balance} tinybars</span>;
25
+ * }
26
+ * ```
27
+ *
28
+ * @packageDocumentation
29
+ */
30
+ export { HieroProvider } from './HieroProvider.js';
31
+ export { useAccount } from './hooks/useAccount.js';
32
+ export { useTransaction } from './hooks/useTransaction.js';
33
+ export { useToken } from './hooks/useToken.js';
34
+ export { useNFTs } from './hooks/useNFTs.js';
35
+ export { useAccountTransactions } from './hooks/useAccountTransactions.js';
36
+ export { useTopicMessages } from './hooks/useTopicMessages.js';
37
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAInD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAC3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Return shape for all Hiero query hooks.
3
+ *
4
+ * @typeParam T - The data type returned by the query
5
+ */
6
+ export interface HieroQueryResult<T> {
7
+ /** The fetched data, or null while loading or on error */
8
+ data: T | null;
9
+ /** True while a network request is in flight */
10
+ loading: boolean;
11
+ /** The error thrown by the last failed request, or null */
12
+ error: Error | null;
13
+ /** Re-triggers the query without changing parameters */
14
+ refetch: () => void;
15
+ }
16
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,WAAW,gBAAgB,CAAC,CAAC;IACjC,0DAA0D;IAC1D,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;IACf,gDAAgD;IAChD,OAAO,EAAE,OAAO,CAAC;IACjB,2DAA2D;IAC3D,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,wDAAwD;IACxD,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB"}
@@ -0,0 +1,3 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ export {};
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,sCAAsC"}
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "hiero-sdk-utils-react",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "description": "React hooks for the Hedera/Hiero Mirror Node — built on hiero-sdk-utils",
6
+ "main": "./dist/esm/index.js",
7
+ "types": "./dist/esm/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": {
11
+ "types": "./dist/esm/index.d.ts",
12
+ "default": "./dist/esm/index.js"
13
+ }
14
+ }
15
+ },
16
+ "files": ["dist/"],
17
+ "engines": { "node": ">=18.0.0" },
18
+ "scripts": {
19
+ "build": "tsc -p tsconfig.json",
20
+ "test": "vitest run",
21
+ "lint": "eslint src/ tests/ --max-warnings 0",
22
+ "typecheck": "tsc --noEmit",
23
+ "prepublishOnly": "npm run typecheck && npm run lint && npm run test && npm run build"
24
+ },
25
+ "peerDependencies": {
26
+ "react": ">=18.0.0",
27
+ "hiero-sdk-utils": ">=0.1.0"
28
+ },
29
+ "devDependencies": {
30
+ "@testing-library/react": "^14.0.0",
31
+ "@types/react": "^18.0.0",
32
+ "@types/react-dom": "^18.0.0",
33
+ "@typescript-eslint/eslint-plugin": "^7.0.0",
34
+ "@typescript-eslint/parser": "^7.0.0",
35
+ "eslint": "^8.57.0",
36
+ "jsdom": "^24.0.0",
37
+ "react": "^18.0.0",
38
+ "react-dom": "^18.0.0",
39
+ "typescript": "^5.4.0",
40
+ "vitest": "^1.6.0"
41
+ },
42
+ "publishConfig": { "access": "public" },
43
+ "license": "Apache-2.0",
44
+ "author": "Dmitrij Titarenko <dtytarenko666@gmail.com>",
45
+ "homepage": "https://github.com/dmitrijtitarenko/hiero-sdk-utils#readme",
46
+ "bugs": { "url": "https://github.com/dmitrijtitarenko/hiero-sdk-utils/issues" },
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "https://github.com/dmitrijtitarenko/hiero-sdk-utils.git",
50
+ "directory": "packages/react"
51
+ },
52
+ "keywords": ["hedera", "hiero", "mirror-node", "react", "hooks", "blockchain"]
53
+ }