@growae/reactive-react 0.0.1

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 (119) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +47 -0
  3. package/src/context.test.ts +52 -0
  4. package/src/context.ts +25 -0
  5. package/src/errors/base.ts +8 -0
  6. package/src/errors/context.ts +12 -0
  7. package/src/errors/index.ts +5 -0
  8. package/src/exports/index.ts +230 -0
  9. package/src/exports/query.ts +12 -0
  10. package/src/hooks/index.ts +69 -0
  11. package/src/hooks/useAccount.test.ts +12 -0
  12. package/src/hooks/useAccount.ts +43 -0
  13. package/src/hooks/useBalance.test.ts +72 -0
  14. package/src/hooks/useBalance.ts +42 -0
  15. package/src/hooks/useBlock.test.ts +12 -0
  16. package/src/hooks/useBlock.ts +42 -0
  17. package/src/hooks/useCallContract.test.ts +12 -0
  18. package/src/hooks/useCallContract.ts +54 -0
  19. package/src/hooks/useChannelDeposit.test.ts +12 -0
  20. package/src/hooks/useChannelDeposit.ts +53 -0
  21. package/src/hooks/useClaimName.test.ts +12 -0
  22. package/src/hooks/useClaimName.ts +53 -0
  23. package/src/hooks/useCloseChannel.test.ts +12 -0
  24. package/src/hooks/useCloseChannel.ts +53 -0
  25. package/src/hooks/useConfig.test.ts +53 -0
  26. package/src/hooks/useConfig.ts +20 -0
  27. package/src/hooks/useConnect.test.ts +67 -0
  28. package/src/hooks/useConnect.ts +69 -0
  29. package/src/hooks/useConnection.test.ts +12 -0
  30. package/src/hooks/useConnection.ts +26 -0
  31. package/src/hooks/useConnections.test.ts +12 -0
  32. package/src/hooks/useConnections.ts +26 -0
  33. package/src/hooks/useConnectorClient.test.ts +12 -0
  34. package/src/hooks/useConnectorClient.ts +44 -0
  35. package/src/hooks/useConnectors.test.ts +12 -0
  36. package/src/hooks/useConnectors.ts +26 -0
  37. package/src/hooks/useContractBytecode.test.ts +12 -0
  38. package/src/hooks/useContractBytecode.ts +41 -0
  39. package/src/hooks/useContractEvents.test.ts +12 -0
  40. package/src/hooks/useContractEvents.ts +42 -0
  41. package/src/hooks/useDeployContract.test.ts +12 -0
  42. package/src/hooks/useDeployContract.ts +54 -0
  43. package/src/hooks/useDisconnect.test.ts +12 -0
  44. package/src/hooks/useDisconnect.ts +54 -0
  45. package/src/hooks/useEstimateGas.test.ts +12 -0
  46. package/src/hooks/useEstimateGas.ts +42 -0
  47. package/src/hooks/useHeight.test.ts +12 -0
  48. package/src/hooks/useHeight.ts +39 -0
  49. package/src/hooks/useNetworkId.test.ts +54 -0
  50. package/src/hooks/useNetworkId.ts +26 -0
  51. package/src/hooks/useNetworks.test.ts +12 -0
  52. package/src/hooks/useNetworks.ts +19 -0
  53. package/src/hooks/useNodeClient.test.ts +12 -0
  54. package/src/hooks/useNodeClient.ts +30 -0
  55. package/src/hooks/useOpenChannel.test.ts +12 -0
  56. package/src/hooks/useOpenChannel.ts +53 -0
  57. package/src/hooks/useOracleQueries.test.ts +12 -0
  58. package/src/hooks/useOracleQueries.ts +40 -0
  59. package/src/hooks/useOracleState.test.ts +12 -0
  60. package/src/hooks/useOracleState.ts +40 -0
  61. package/src/hooks/usePayForTransaction.test.ts +12 -0
  62. package/src/hooks/usePayForTransaction.ts +54 -0
  63. package/src/hooks/usePreclaimName.test.ts +12 -0
  64. package/src/hooks/usePreclaimName.ts +53 -0
  65. package/src/hooks/useQueryOracle.test.ts +12 -0
  66. package/src/hooks/useQueryOracle.ts +53 -0
  67. package/src/hooks/useReadContract.test.ts +12 -0
  68. package/src/hooks/useReadContract.ts +43 -0
  69. package/src/hooks/useReadContracts.test.ts +12 -0
  70. package/src/hooks/useReadContracts.ts +38 -0
  71. package/src/hooks/useReconnect.test.ts +12 -0
  72. package/src/hooks/useReconnect.ts +54 -0
  73. package/src/hooks/useRegisterOracle.test.ts +12 -0
  74. package/src/hooks/useRegisterOracle.ts +53 -0
  75. package/src/hooks/useResolveName.test.ts +12 -0
  76. package/src/hooks/useResolveName.ts +41 -0
  77. package/src/hooks/useRespondToQuery.test.ts +12 -0
  78. package/src/hooks/useRespondToQuery.ts +53 -0
  79. package/src/hooks/useRevokeName.test.ts +12 -0
  80. package/src/hooks/useRevokeName.ts +53 -0
  81. package/src/hooks/useSendTransaction.test.ts +12 -0
  82. package/src/hooks/useSendTransaction.ts +54 -0
  83. package/src/hooks/useSignMessage.test.ts +12 -0
  84. package/src/hooks/useSignMessage.ts +54 -0
  85. package/src/hooks/useSignTransaction.test.ts +12 -0
  86. package/src/hooks/useSignTransaction.ts +54 -0
  87. package/src/hooks/useSignTypedData.test.ts +12 -0
  88. package/src/hooks/useSignTypedData.ts +54 -0
  89. package/src/hooks/useSimulateContract.test.ts +12 -0
  90. package/src/hooks/useSimulateContract.ts +43 -0
  91. package/src/hooks/useSpend.test.ts +12 -0
  92. package/src/hooks/useSpend.ts +53 -0
  93. package/src/hooks/useSwitchNetwork.test.ts +12 -0
  94. package/src/hooks/useSwitchNetwork.ts +57 -0
  95. package/src/hooks/useTransaction.test.ts +12 -0
  96. package/src/hooks/useTransaction.ts +41 -0
  97. package/src/hooks/useTransactionCount.test.ts +12 -0
  98. package/src/hooks/useTransactionCount.ts +41 -0
  99. package/src/hooks/useTransferName.test.ts +12 -0
  100. package/src/hooks/useTransferName.ts +53 -0
  101. package/src/hooks/useUpdateName.test.ts +12 -0
  102. package/src/hooks/useUpdateName.ts +53 -0
  103. package/src/hooks/useVerifyMessage.test.ts +12 -0
  104. package/src/hooks/useVerifyMessage.ts +39 -0
  105. package/src/hooks/useVerifyTypedData.test.ts +12 -0
  106. package/src/hooks/useVerifyTypedData.ts +39 -0
  107. package/src/hooks/useWaitForTransaction.test.ts +12 -0
  108. package/src/hooks/useWaitForTransaction.ts +41 -0
  109. package/src/hooks/useWatchConnection.test.ts +12 -0
  110. package/src/hooks/useWatchConnection.ts +34 -0
  111. package/src/hooks/useWatchConnectors.test.ts +12 -0
  112. package/src/hooks/useWatchConnectors.ts +34 -0
  113. package/src/hooks/useWatchHeight.test.ts +12 -0
  114. package/src/hooks/useWatchHeight.ts +45 -0
  115. package/src/hydrate.ts +34 -0
  116. package/src/types/properties.ts +9 -0
  117. package/src/utils/query.ts +80 -0
  118. package/tsconfig.build.json +13 -0
  119. package/tsconfig.json +7 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-present Growae
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@growae/reactive-react",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "main": "dist/esm/exports/index.js",
6
+ "types": "dist/types/exports/index.d.ts",
7
+ "sideEffects": false,
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/types/exports/index.d.ts",
11
+ "default": "./dist/esm/exports/index.js"
12
+ },
13
+ "./query": {
14
+ "types": "./dist/types/exports/query.d.ts",
15
+ "default": "./dist/esm/exports/query.js"
16
+ },
17
+ "./package.json": "./package.json"
18
+ },
19
+ "dependencies": {
20
+ "use-sync-external-store": "^1.4.0",
21
+ "@growae/reactive": "0.0.1"
22
+ },
23
+ "peerDependencies": {
24
+ "@tanstack/react-query": ">=5.0.0",
25
+ "react": ">=18.0.0",
26
+ "typescript": ">=5.7.0"
27
+ },
28
+ "peerDependenciesMeta": {
29
+ "typescript": {
30
+ "optional": true
31
+ }
32
+ },
33
+ "devDependencies": {
34
+ "@tanstack/react-query": "^5.95.2",
35
+ "@testing-library/react": "^16.3.2",
36
+ "@types/react": "^19.2.14",
37
+ "jsdom": "^29.0.1",
38
+ "react": "^19.2.4",
39
+ "react-dom": "^19.2.4"
40
+ },
41
+ "scripts": {
42
+ "build": "tsc --project tsconfig.build.json --outDir ./dist/esm --declaration --declarationMap --declarationDir ./dist/types",
43
+ "clean": "rm -rf dist",
44
+ "check:types": "tsc --noEmit",
45
+ "dev": "tsc --project tsconfig.build.json --outDir ./dist/esm --declaration --declarationMap --declarationDir ./dist/types --watch"
46
+ }
47
+ }
@@ -0,0 +1,52 @@
1
+ // @vitest-environment jsdom
2
+ import { describe, it, expect, vi } from 'vitest'
3
+
4
+ vi.mock('@aeternity/aepp-sdk', () => ({
5
+ Node: vi.fn().mockImplementation(() => ({})),
6
+ }))
7
+
8
+ import { createElement, useContext } from 'react'
9
+ import { render, renderHook } from '@testing-library/react'
10
+ import { ReactiveProvider, ReactiveContext } from './context.js'
11
+ import { createConfig } from '@growae/reactive'
12
+ import { testnet } from '@growae/reactive'
13
+ import { mock } from '@growae/reactive'
14
+
15
+ const TEST_ACCOUNTS = [
16
+ 'ak_2swhLkgBPeeADxVTABy7tt6d2HgBQFnGJELkBUMY4FUa8RVLM',
17
+ ] as const
18
+
19
+ function createTestConfig() {
20
+ return createConfig({
21
+ networks: [testnet],
22
+ connectors: [mock({ accounts: [...TEST_ACCOUNTS] })],
23
+ storage: null,
24
+ })
25
+ }
26
+
27
+ describe('ReactiveProvider', () => {
28
+ it('should render children', () => {
29
+ const config = createTestConfig()
30
+ const { container } = render(
31
+ createElement(
32
+ ReactiveProvider,
33
+ { config, reconnectOnMount: false },
34
+ createElement('div', null, 'Hello'),
35
+ ),
36
+ )
37
+ expect(container.textContent).toBe('Hello')
38
+ })
39
+
40
+ it('should provide config via context', () => {
41
+ const config = createTestConfig()
42
+ const { result } = renderHook(() => useContext(ReactiveContext), {
43
+ wrapper: ({ children }) =>
44
+ createElement(
45
+ ReactiveProvider,
46
+ { config, reconnectOnMount: false },
47
+ children,
48
+ ),
49
+ })
50
+ expect(result.current).toBe(config)
51
+ })
52
+ })
package/src/context.ts ADDED
@@ -0,0 +1,25 @@
1
+ 'use client'
2
+
3
+ import type { Config, State } from '@growae/reactive'
4
+ import { createContext, createElement, type ReactNode } from 'react'
5
+ import { Hydrate } from './hydrate.js'
6
+
7
+ export const ReactiveContext = createContext<Config | undefined>(undefined)
8
+
9
+ export type ReactiveProviderProps = {
10
+ config: Config
11
+ initialState?: State | undefined
12
+ reconnectOnMount?: boolean | undefined
13
+ }
14
+
15
+ export function ReactiveProvider(
16
+ parameters: React.PropsWithChildren<ReactiveProviderProps>,
17
+ ) {
18
+ const { children, config } = parameters
19
+ const props = { value: config }
20
+ return createElement(
21
+ Hydrate,
22
+ parameters,
23
+ createElement(ReactiveContext.Provider, props, children),
24
+ )
25
+ }
@@ -0,0 +1,8 @@
1
+ 'use client'
2
+
3
+ import { BaseError as CoreError } from '@growae/reactive'
4
+
5
+ export type BaseErrorType = BaseError & { name: 'ReactiveError' }
6
+ export class BaseError extends CoreError {
7
+ override name = 'ReactiveError'
8
+ }
@@ -0,0 +1,12 @@
1
+ import { BaseError } from './base.js'
2
+
3
+ export type ReactiveProviderNotFoundErrorType =
4
+ ReactiveProviderNotFoundError & {
5
+ name: 'ReactiveProviderNotFoundError'
6
+ }
7
+ export class ReactiveProviderNotFoundError extends BaseError {
8
+ override name = 'ReactiveProviderNotFoundError'
9
+ constructor() {
10
+ super('`useConfig` must be used within `ReactiveProvider`.')
11
+ }
12
+ }
@@ -0,0 +1,5 @@
1
+ export { BaseError, type BaseErrorType } from './base.js'
2
+ export {
3
+ ReactiveProviderNotFoundError,
4
+ type ReactiveProviderNotFoundErrorType,
5
+ } from './context.js'
@@ -0,0 +1,230 @@
1
+ ////////////////////////////////////////////////////////////////////////////////
2
+ // Context
3
+ ////////////////////////////////////////////////////////////////////////////////
4
+
5
+ export {
6
+ ReactiveContext,
7
+ ReactiveProvider,
8
+ type ReactiveProviderProps,
9
+ } from '../context.js'
10
+
11
+ ////////////////////////////////////////////////////////////////////////////////
12
+ // Errors
13
+ ////////////////////////////////////////////////////////////////////////////////
14
+
15
+ export { BaseError, type BaseErrorType } from '../errors/base.js'
16
+ export {
17
+ ReactiveProviderNotFoundError,
18
+ type ReactiveProviderNotFoundErrorType,
19
+ } from '../errors/context.js'
20
+
21
+ ////////////////////////////////////////////////////////////////////////////////
22
+ // Hydrate
23
+ ////////////////////////////////////////////////////////////////////////////////
24
+
25
+ export {
26
+ Hydrate,
27
+ type HydrateProps,
28
+ } from '../hydrate.js'
29
+
30
+ ////////////////////////////////////////////////////////////////////////////////
31
+ // Hooks
32
+ ////////////////////////////////////////////////////////////////////////////////
33
+
34
+ export {
35
+ // Connection
36
+ useConfig,
37
+ type UseConfigParameters,
38
+ type UseConfigReturnType,
39
+ useConnect,
40
+ type UseConnectParameters,
41
+ type UseConnectReturnType,
42
+ useDisconnect,
43
+ type UseDisconnectParameters,
44
+ type UseDisconnectReturnType,
45
+ useReconnect,
46
+ type UseReconnectParameters,
47
+ type UseReconnectReturnType,
48
+ useConnection,
49
+ type UseConnectionParameters,
50
+ type UseConnectionReturnType,
51
+ useConnections,
52
+ type UseConnectionsParameters,
53
+ type UseConnectionsReturnType,
54
+ useConnectors,
55
+ type UseConnectorsParameters,
56
+ type UseConnectorsReturnType,
57
+ useNetworkId,
58
+ type UseNetworkIdParameters,
59
+ type UseNetworkIdReturnType,
60
+ useNetworks,
61
+ type UseNetworksParameters,
62
+ type UseNetworksReturnType,
63
+ useSwitchNetwork,
64
+ type UseSwitchNetworkParameters,
65
+ type UseSwitchNetworkReturnType,
66
+ useNodeClient,
67
+ type UseNodeClientParameters,
68
+ type UseNodeClientReturnType,
69
+ useConnectorClient,
70
+ type UseConnectorClientParameters,
71
+ type UseConnectorClientReturnType,
72
+
73
+ // Chain reads
74
+ useBalance,
75
+ type UseBalanceParameters,
76
+ type UseBalanceReturnType,
77
+ useHeight,
78
+ type UseHeightParameters,
79
+ type UseHeightReturnType,
80
+ useAccount,
81
+ type UseAccountParameters,
82
+ type UseAccountReturnType,
83
+ useBlock,
84
+ type UseBlockParameters,
85
+ type UseBlockReturnType,
86
+ useTransaction,
87
+ type UseTransactionParameters,
88
+ type UseTransactionReturnType,
89
+ useTransactionCount,
90
+ type UseTransactionCountParameters,
91
+ type UseTransactionCountReturnType,
92
+ useWaitForTransaction,
93
+ type UseWaitForTransactionParameters,
94
+ type UseWaitForTransactionReturnType,
95
+ useContractBytecode,
96
+ type UseContractBytecodeParameters,
97
+ type UseContractBytecodeReturnType,
98
+ useEstimateGas,
99
+ type UseEstimateGasParameters,
100
+ type UseEstimateGasReturnType,
101
+
102
+ // Transactions
103
+ useSendTransaction,
104
+ type UseSendTransactionParameters,
105
+ type UseSendTransactionReturnType,
106
+ useSpend,
107
+ type UseSpendParameters,
108
+ type UseSpendReturnType,
109
+ usePayForTransaction,
110
+ type UsePayForTransactionParameters,
111
+ type UsePayForTransactionReturnType,
112
+
113
+ // Signing
114
+ useSignMessage,
115
+ type UseSignMessageParameters,
116
+ type UseSignMessageReturnType,
117
+ useSignTypedData,
118
+ type UseSignTypedDataParameters,
119
+ type UseSignTypedDataReturnType,
120
+ useSignTransaction,
121
+ type UseSignTransactionParameters,
122
+ type UseSignTransactionReturnType,
123
+ useVerifyMessage,
124
+ type UseVerifyMessageParameters,
125
+ type UseVerifyMessageReturnType,
126
+ useVerifyTypedData,
127
+ type UseVerifyTypedDataParameters,
128
+ type UseVerifyTypedDataReturnType,
129
+
130
+ // Contracts
131
+ useDeployContract,
132
+ type UseDeployContractParameters,
133
+ type UseDeployContractReturnType,
134
+ useCallContract,
135
+ type UseCallContractParameters,
136
+ type UseCallContractReturnType,
137
+ useReadContract,
138
+ type UseReadContractParameters,
139
+ type UseReadContractReturnType,
140
+ useReadContracts,
141
+ type UseReadContractsParameters,
142
+ type UseReadContractsReturnType,
143
+ useSimulateContract,
144
+ type UseSimulateContractParameters,
145
+ type UseSimulateContractReturnType,
146
+ useContractEvents,
147
+ type UseContractEventsParameters,
148
+ type UseContractEventsReturnType,
149
+
150
+ // AENS
151
+ usePreclaimName,
152
+ type UsePreclaimNameParameters,
153
+ type UsePreclaimNameReturnType,
154
+ useClaimName,
155
+ type UseClaimNameParameters,
156
+ type UseClaimNameReturnType,
157
+ useUpdateName,
158
+ type UseUpdateNameParameters,
159
+ type UseUpdateNameReturnType,
160
+ useTransferName,
161
+ type UseTransferNameParameters,
162
+ type UseTransferNameReturnType,
163
+ useRevokeName,
164
+ type UseRevokeNameParameters,
165
+ type UseRevokeNameReturnType,
166
+ useResolveName,
167
+ type UseResolveNameParameters,
168
+ type UseResolveNameReturnType,
169
+
170
+ // Oracles
171
+ useRegisterOracle,
172
+ type UseRegisterOracleParameters,
173
+ type UseRegisterOracleReturnType,
174
+ useQueryOracle,
175
+ type UseQueryOracleParameters,
176
+ type UseQueryOracleReturnType,
177
+ useRespondToQuery,
178
+ type UseRespondToQueryParameters,
179
+ type UseRespondToQueryReturnType,
180
+ useOracleState,
181
+ type UseOracleStateParameters,
182
+ type UseOracleStateReturnType,
183
+ useOracleQueries,
184
+ type UseOracleQueriesParameters,
185
+ type UseOracleQueriesReturnType,
186
+
187
+ // Channels
188
+ useOpenChannel,
189
+ type UseOpenChannelParameters,
190
+ type UseOpenChannelReturnType,
191
+ useCloseChannel,
192
+ type UseCloseChannelParameters,
193
+ type UseCloseChannelReturnType,
194
+ useChannelDeposit,
195
+ type UseChannelDepositParameters,
196
+ type UseChannelDepositReturnType,
197
+
198
+ // Watchers
199
+ useWatchHeight,
200
+ type UseWatchHeightParameters,
201
+ type UseWatchHeightReturnType,
202
+ useWatchConnection,
203
+ type UseWatchConnectionParameters,
204
+ type UseWatchConnectionReturnType,
205
+ useWatchConnectors,
206
+ type UseWatchConnectorsParameters,
207
+ type UseWatchConnectorsReturnType,
208
+ } from '../hooks/index.js'
209
+
210
+ ////////////////////////////////////////////////////////////////////////////////
211
+ // @growae/reactive re-exports
212
+ ////////////////////////////////////////////////////////////////////////////////
213
+
214
+ export {
215
+ createConfig,
216
+ createStorage,
217
+ mainnet,
218
+ testnet,
219
+ toAe,
220
+ toAettos,
221
+ formatAmount,
222
+ } from '@growae/reactive'
223
+
224
+ export type {
225
+ Config,
226
+ Network,
227
+ State,
228
+ Connection,
229
+ Connector,
230
+ } from '@growae/reactive'
@@ -0,0 +1,12 @@
1
+ // Re-export core query utilities
2
+ export { hashFn } from '@growae/reactive/query'
3
+
4
+ // Re-export React query wrappers
5
+ export {
6
+ useQuery,
7
+ useMutation,
8
+ type UseQueryParameters,
9
+ type UseQueryReturnType,
10
+ type UseMutationParameters,
11
+ type UseMutationReturnType,
12
+ } from '../utils/query.js'
@@ -0,0 +1,69 @@
1
+ // Connection hooks
2
+ export { useConfig, type UseConfigParameters, type UseConfigReturnType } from './useConfig.js'
3
+ export { useConnect, type UseConnectParameters, type UseConnectReturnType } from './useConnect.js'
4
+ export { useDisconnect, type UseDisconnectParameters, type UseDisconnectReturnType } from './useDisconnect.js'
5
+ export { useReconnect, type UseReconnectParameters, type UseReconnectReturnType } from './useReconnect.js'
6
+ export { useConnection, type UseConnectionParameters, type UseConnectionReturnType } from './useConnection.js'
7
+ export { useConnections, type UseConnectionsParameters, type UseConnectionsReturnType } from './useConnections.js'
8
+ export { useConnectors, type UseConnectorsParameters, type UseConnectorsReturnType } from './useConnectors.js'
9
+ export { useNetworkId, type UseNetworkIdParameters, type UseNetworkIdReturnType } from './useNetworkId.js'
10
+ export { useNetworks, type UseNetworksParameters, type UseNetworksReturnType } from './useNetworks.js'
11
+ export { useSwitchNetwork, type UseSwitchNetworkParameters, type UseSwitchNetworkReturnType } from './useSwitchNetwork.js'
12
+ export { useNodeClient, type UseNodeClientParameters, type UseNodeClientReturnType } from './useNodeClient.js'
13
+ export { useConnectorClient, type UseConnectorClientParameters, type UseConnectorClientReturnType } from './useConnectorClient.js'
14
+
15
+ // Chain read hooks
16
+ export { useBalance, type UseBalanceParameters, type UseBalanceReturnType } from './useBalance.js'
17
+ export { useHeight, type UseHeightParameters, type UseHeightReturnType } from './useHeight.js'
18
+ export { useAccount, type UseAccountParameters, type UseAccountReturnType } from './useAccount.js'
19
+ export { useBlock, type UseBlockParameters, type UseBlockReturnType } from './useBlock.js'
20
+ export { useTransaction, type UseTransactionParameters, type UseTransactionReturnType } from './useTransaction.js'
21
+ export { useTransactionCount, type UseTransactionCountParameters, type UseTransactionCountReturnType } from './useTransactionCount.js'
22
+ export { useWaitForTransaction, type UseWaitForTransactionParameters, type UseWaitForTransactionReturnType } from './useWaitForTransaction.js'
23
+ export { useContractBytecode, type UseContractBytecodeParameters, type UseContractBytecodeReturnType } from './useContractBytecode.js'
24
+ export { useEstimateGas, type UseEstimateGasParameters, type UseEstimateGasReturnType } from './useEstimateGas.js'
25
+
26
+ // Transaction hooks
27
+ export { useSendTransaction, type UseSendTransactionParameters, type UseSendTransactionReturnType } from './useSendTransaction.js'
28
+ export { useSpend, type UseSpendParameters, type UseSpendReturnType } from './useSpend.js'
29
+ export { usePayForTransaction, type UsePayForTransactionParameters, type UsePayForTransactionReturnType } from './usePayForTransaction.js'
30
+
31
+ // Signing hooks
32
+ export { useSignMessage, type UseSignMessageParameters, type UseSignMessageReturnType } from './useSignMessage.js'
33
+ export { useSignTypedData, type UseSignTypedDataParameters, type UseSignTypedDataReturnType } from './useSignTypedData.js'
34
+ export { useSignTransaction, type UseSignTransactionParameters, type UseSignTransactionReturnType } from './useSignTransaction.js'
35
+ export { useVerifyMessage, type UseVerifyMessageParameters, type UseVerifyMessageReturnType } from './useVerifyMessage.js'
36
+ export { useVerifyTypedData, type UseVerifyTypedDataParameters, type UseVerifyTypedDataReturnType } from './useVerifyTypedData.js'
37
+
38
+ // Contract hooks
39
+ export { useDeployContract, type UseDeployContractParameters, type UseDeployContractReturnType } from './useDeployContract.js'
40
+ export { useCallContract, type UseCallContractParameters, type UseCallContractReturnType } from './useCallContract.js'
41
+ export { useReadContract, type UseReadContractParameters, type UseReadContractReturnType } from './useReadContract.js'
42
+ export { useReadContracts, type UseReadContractsParameters, type UseReadContractsReturnType } from './useReadContracts.js'
43
+ export { useSimulateContract, type UseSimulateContractParameters, type UseSimulateContractReturnType } from './useSimulateContract.js'
44
+ export { useContractEvents, type UseContractEventsParameters, type UseContractEventsReturnType } from './useContractEvents.js'
45
+
46
+ // AENS hooks
47
+ export { usePreclaimName, type UsePreclaimNameParameters, type UsePreclaimNameReturnType } from './usePreclaimName.js'
48
+ export { useClaimName, type UseClaimNameParameters, type UseClaimNameReturnType } from './useClaimName.js'
49
+ export { useUpdateName, type UseUpdateNameParameters, type UseUpdateNameReturnType } from './useUpdateName.js'
50
+ export { useTransferName, type UseTransferNameParameters, type UseTransferNameReturnType } from './useTransferName.js'
51
+ export { useRevokeName, type UseRevokeNameParameters, type UseRevokeNameReturnType } from './useRevokeName.js'
52
+ export { useResolveName, type UseResolveNameParameters, type UseResolveNameReturnType } from './useResolveName.js'
53
+
54
+ // Oracle hooks
55
+ export { useRegisterOracle, type UseRegisterOracleParameters, type UseRegisterOracleReturnType } from './useRegisterOracle.js'
56
+ export { useQueryOracle, type UseQueryOracleParameters, type UseQueryOracleReturnType } from './useQueryOracle.js'
57
+ export { useRespondToQuery, type UseRespondToQueryParameters, type UseRespondToQueryReturnType } from './useRespondToQuery.js'
58
+ export { useOracleState, type UseOracleStateParameters, type UseOracleStateReturnType } from './useOracleState.js'
59
+ export { useOracleQueries, type UseOracleQueriesParameters, type UseOracleQueriesReturnType } from './useOracleQueries.js'
60
+
61
+ // Channel hooks
62
+ export { useOpenChannel, type UseOpenChannelParameters, type UseOpenChannelReturnType } from './useOpenChannel.js'
63
+ export { useCloseChannel, type UseCloseChannelParameters, type UseCloseChannelReturnType } from './useCloseChannel.js'
64
+ export { useChannelDeposit, type UseChannelDepositParameters, type UseChannelDepositReturnType } from './useChannelDeposit.js'
65
+
66
+ // Watcher hooks
67
+ export { useWatchHeight, type UseWatchHeightParameters, type UseWatchHeightReturnType } from './useWatchHeight.js'
68
+ export { useWatchConnection, type UseWatchConnectionParameters, type UseWatchConnectionReturnType } from './useWatchConnection.js'
69
+ export { useWatchConnectors, type UseWatchConnectorsParameters, type UseWatchConnectorsReturnType } from './useWatchConnectors.js'
@@ -0,0 +1,12 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { useAccount } from './useAccount.js'
3
+
4
+ describe('useAccount', () => {
5
+ it('should be a function', () => {
6
+ expect(typeof useAccount).toBe('function')
7
+ })
8
+
9
+ it('should be exported', () => {
10
+ expect(useAccount).toBeDefined()
11
+ })
12
+ })
@@ -0,0 +1,43 @@
1
+ 'use client'
2
+
3
+ import {
4
+ type GetAccountParameters,
5
+ type GetAccountReturnType,
6
+ type GetAccountErrorType,
7
+ getAccount,
8
+ } from '@growae/reactive'
9
+ import type { Compute } from '@growae/reactive'
10
+ import { type UseQueryReturnType, useQuery } from '../utils/query.js'
11
+ import type { ConfigParameter } from '../types/properties.js'
12
+ import { useConfig } from './useConfig.js'
13
+ import { useNetworkId } from './useNetworkId.js'
14
+
15
+ export type UseAccountParameters = Compute<
16
+ GetAccountParameters & ConfigParameter & { enabled?: boolean }
17
+ >
18
+
19
+ export type UseAccountReturnType = UseQueryReturnType<
20
+ GetAccountReturnType,
21
+ GetAccountErrorType
22
+ >
23
+
24
+ export function useAccount(
25
+ parameters: UseAccountParameters = {} as UseAccountParameters,
26
+ ): UseAccountReturnType {
27
+ const config = useConfig(parameters)
28
+ const networkId = useNetworkId({ config })
29
+
30
+ return useQuery({
31
+ queryKey: ['account', {
32
+ address: parameters.address,
33
+ networkId: parameters.networkId ?? networkId,
34
+ height: parameters.height,
35
+ hash: parameters.hash,
36
+ }],
37
+ queryFn: () => getAccount(config, {
38
+ ...parameters,
39
+ networkId: parameters.networkId ?? networkId,
40
+ }),
41
+ enabled: Boolean(parameters.address) && (parameters.enabled ?? true),
42
+ }) as UseAccountReturnType
43
+ }
@@ -0,0 +1,72 @@
1
+ // @vitest-environment jsdom
2
+ import { describe, it, expect, vi } from 'vitest'
3
+
4
+ vi.mock('@aeternity/aepp-sdk', () => ({
5
+ Node: vi.fn().mockImplementation(() => ({})),
6
+ }))
7
+
8
+ import { createElement } from 'react'
9
+ import { renderHook } from '@testing-library/react'
10
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
11
+ import { useBalance } from './useBalance.js'
12
+ import { ReactiveProvider } from '../context.js'
13
+ import { createConfig } from '@growae/reactive'
14
+ import { testnet } from '@growae/reactive'
15
+ import { mock } from '@growae/reactive'
16
+
17
+ const TEST_ACCOUNTS = [
18
+ 'ak_2swhLkgBPeeADxVTABy7tt6d2HgBQFnGJELkBUMY4FUa8RVLM',
19
+ ] as const
20
+
21
+ function createWrapper() {
22
+ const config = createConfig({
23
+ networks: [testnet],
24
+ connectors: [mock({ accounts: [...TEST_ACCOUNTS] })],
25
+ storage: null,
26
+ })
27
+ const queryClient = new QueryClient({
28
+ defaultOptions: { queries: { retry: false } },
29
+ })
30
+ return {
31
+ config,
32
+ wrapper: ({ children }: { children: React.ReactNode }) =>
33
+ createElement(
34
+ QueryClientProvider,
35
+ { client: queryClient },
36
+ createElement(
37
+ ReactiveProvider,
38
+ { config, reconnectOnMount: false },
39
+ children,
40
+ ),
41
+ ),
42
+ }
43
+ }
44
+
45
+ describe('useBalance', () => {
46
+ it('should return query result shape', () => {
47
+ const { wrapper } = createWrapper()
48
+ const { result } = renderHook(
49
+ () =>
50
+ useBalance({
51
+ address:
52
+ 'ak_2swhLkgBPeeADxVTABy7tt6d2HgBQFnGJELkBUMY4FUa8RVLM',
53
+ }),
54
+ { wrapper },
55
+ )
56
+
57
+ expect(result.current).toHaveProperty('data')
58
+ expect(result.current).toHaveProperty('isLoading')
59
+ expect(result.current).toHaveProperty('isError')
60
+ expect(result.current).toHaveProperty('error')
61
+ expect(result.current).toHaveProperty('queryKey')
62
+ })
63
+
64
+ it('should be idle without address', () => {
65
+ const { wrapper } = createWrapper()
66
+ const { result } = renderHook(
67
+ () => useBalance({} as any),
68
+ { wrapper },
69
+ )
70
+ expect(result.current.fetchStatus).toBe('idle')
71
+ })
72
+ })
@@ -0,0 +1,42 @@
1
+ 'use client'
2
+
3
+ import {
4
+ type GetBalanceParameters,
5
+ type GetBalanceReturnType,
6
+ type GetBalanceErrorType,
7
+ getBalance,
8
+ } from '@growae/reactive'
9
+ import type { Compute } from '@growae/reactive'
10
+ import { type UseQueryReturnType, useQuery } from '../utils/query.js'
11
+ import type { ConfigParameter } from '../types/properties.js'
12
+ import { useConfig } from './useConfig.js'
13
+ import { useNetworkId } from './useNetworkId.js'
14
+
15
+ export type UseBalanceParameters = Compute<
16
+ GetBalanceParameters & ConfigParameter & { enabled?: boolean }
17
+ >
18
+
19
+ export type UseBalanceReturnType = UseQueryReturnType<
20
+ GetBalanceReturnType,
21
+ GetBalanceErrorType
22
+ >
23
+
24
+ export function useBalance(
25
+ parameters: UseBalanceParameters = {} as UseBalanceParameters,
26
+ ): UseBalanceReturnType {
27
+ const config = useConfig(parameters)
28
+ const networkId = useNetworkId({ config })
29
+
30
+ return useQuery({
31
+ queryKey: ['balance', {
32
+ address: parameters.address,
33
+ networkId: parameters.networkId ?? networkId,
34
+ format: parameters.format,
35
+ }],
36
+ queryFn: () => getBalance(config, {
37
+ ...parameters,
38
+ networkId: parameters.networkId ?? networkId,
39
+ }),
40
+ enabled: Boolean(parameters.address) && (parameters.enabled ?? true),
41
+ }) as UseBalanceReturnType
42
+ }