@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.
- package/LICENSE +21 -0
- package/package.json +47 -0
- package/src/context.test.ts +52 -0
- package/src/context.ts +25 -0
- package/src/errors/base.ts +8 -0
- package/src/errors/context.ts +12 -0
- package/src/errors/index.ts +5 -0
- package/src/exports/index.ts +230 -0
- package/src/exports/query.ts +12 -0
- package/src/hooks/index.ts +69 -0
- package/src/hooks/useAccount.test.ts +12 -0
- package/src/hooks/useAccount.ts +43 -0
- package/src/hooks/useBalance.test.ts +72 -0
- package/src/hooks/useBalance.ts +42 -0
- package/src/hooks/useBlock.test.ts +12 -0
- package/src/hooks/useBlock.ts +42 -0
- package/src/hooks/useCallContract.test.ts +12 -0
- package/src/hooks/useCallContract.ts +54 -0
- package/src/hooks/useChannelDeposit.test.ts +12 -0
- package/src/hooks/useChannelDeposit.ts +53 -0
- package/src/hooks/useClaimName.test.ts +12 -0
- package/src/hooks/useClaimName.ts +53 -0
- package/src/hooks/useCloseChannel.test.ts +12 -0
- package/src/hooks/useCloseChannel.ts +53 -0
- package/src/hooks/useConfig.test.ts +53 -0
- package/src/hooks/useConfig.ts +20 -0
- package/src/hooks/useConnect.test.ts +67 -0
- package/src/hooks/useConnect.ts +69 -0
- package/src/hooks/useConnection.test.ts +12 -0
- package/src/hooks/useConnection.ts +26 -0
- package/src/hooks/useConnections.test.ts +12 -0
- package/src/hooks/useConnections.ts +26 -0
- package/src/hooks/useConnectorClient.test.ts +12 -0
- package/src/hooks/useConnectorClient.ts +44 -0
- package/src/hooks/useConnectors.test.ts +12 -0
- package/src/hooks/useConnectors.ts +26 -0
- package/src/hooks/useContractBytecode.test.ts +12 -0
- package/src/hooks/useContractBytecode.ts +41 -0
- package/src/hooks/useContractEvents.test.ts +12 -0
- package/src/hooks/useContractEvents.ts +42 -0
- package/src/hooks/useDeployContract.test.ts +12 -0
- package/src/hooks/useDeployContract.ts +54 -0
- package/src/hooks/useDisconnect.test.ts +12 -0
- package/src/hooks/useDisconnect.ts +54 -0
- package/src/hooks/useEstimateGas.test.ts +12 -0
- package/src/hooks/useEstimateGas.ts +42 -0
- package/src/hooks/useHeight.test.ts +12 -0
- package/src/hooks/useHeight.ts +39 -0
- package/src/hooks/useNetworkId.test.ts +54 -0
- package/src/hooks/useNetworkId.ts +26 -0
- package/src/hooks/useNetworks.test.ts +12 -0
- package/src/hooks/useNetworks.ts +19 -0
- package/src/hooks/useNodeClient.test.ts +12 -0
- package/src/hooks/useNodeClient.ts +30 -0
- package/src/hooks/useOpenChannel.test.ts +12 -0
- package/src/hooks/useOpenChannel.ts +53 -0
- package/src/hooks/useOracleQueries.test.ts +12 -0
- package/src/hooks/useOracleQueries.ts +40 -0
- package/src/hooks/useOracleState.test.ts +12 -0
- package/src/hooks/useOracleState.ts +40 -0
- package/src/hooks/usePayForTransaction.test.ts +12 -0
- package/src/hooks/usePayForTransaction.ts +54 -0
- package/src/hooks/usePreclaimName.test.ts +12 -0
- package/src/hooks/usePreclaimName.ts +53 -0
- package/src/hooks/useQueryOracle.test.ts +12 -0
- package/src/hooks/useQueryOracle.ts +53 -0
- package/src/hooks/useReadContract.test.ts +12 -0
- package/src/hooks/useReadContract.ts +43 -0
- package/src/hooks/useReadContracts.test.ts +12 -0
- package/src/hooks/useReadContracts.ts +38 -0
- package/src/hooks/useReconnect.test.ts +12 -0
- package/src/hooks/useReconnect.ts +54 -0
- package/src/hooks/useRegisterOracle.test.ts +12 -0
- package/src/hooks/useRegisterOracle.ts +53 -0
- package/src/hooks/useResolveName.test.ts +12 -0
- package/src/hooks/useResolveName.ts +41 -0
- package/src/hooks/useRespondToQuery.test.ts +12 -0
- package/src/hooks/useRespondToQuery.ts +53 -0
- package/src/hooks/useRevokeName.test.ts +12 -0
- package/src/hooks/useRevokeName.ts +53 -0
- package/src/hooks/useSendTransaction.test.ts +12 -0
- package/src/hooks/useSendTransaction.ts +54 -0
- package/src/hooks/useSignMessage.test.ts +12 -0
- package/src/hooks/useSignMessage.ts +54 -0
- package/src/hooks/useSignTransaction.test.ts +12 -0
- package/src/hooks/useSignTransaction.ts +54 -0
- package/src/hooks/useSignTypedData.test.ts +12 -0
- package/src/hooks/useSignTypedData.ts +54 -0
- package/src/hooks/useSimulateContract.test.ts +12 -0
- package/src/hooks/useSimulateContract.ts +43 -0
- package/src/hooks/useSpend.test.ts +12 -0
- package/src/hooks/useSpend.ts +53 -0
- package/src/hooks/useSwitchNetwork.test.ts +12 -0
- package/src/hooks/useSwitchNetwork.ts +57 -0
- package/src/hooks/useTransaction.test.ts +12 -0
- package/src/hooks/useTransaction.ts +41 -0
- package/src/hooks/useTransactionCount.test.ts +12 -0
- package/src/hooks/useTransactionCount.ts +41 -0
- package/src/hooks/useTransferName.test.ts +12 -0
- package/src/hooks/useTransferName.ts +53 -0
- package/src/hooks/useUpdateName.test.ts +12 -0
- package/src/hooks/useUpdateName.ts +53 -0
- package/src/hooks/useVerifyMessage.test.ts +12 -0
- package/src/hooks/useVerifyMessage.ts +39 -0
- package/src/hooks/useVerifyTypedData.test.ts +12 -0
- package/src/hooks/useVerifyTypedData.ts +39 -0
- package/src/hooks/useWaitForTransaction.test.ts +12 -0
- package/src/hooks/useWaitForTransaction.ts +41 -0
- package/src/hooks/useWatchConnection.test.ts +12 -0
- package/src/hooks/useWatchConnection.ts +34 -0
- package/src/hooks/useWatchConnectors.test.ts +12 -0
- package/src/hooks/useWatchConnectors.ts +34 -0
- package/src/hooks/useWatchHeight.test.ts +12 -0
- package/src/hooks/useWatchHeight.ts +45 -0
- package/src/hydrate.ts +34 -0
- package/src/types/properties.ts +9 -0
- package/src/utils/query.ts +80 -0
- package/tsconfig.build.json +13 -0
- package/tsconfig.json +7 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { useConnectors } from './useConnectors.js'
|
|
3
|
+
|
|
4
|
+
describe('useConnectors', () => {
|
|
5
|
+
it('should be a function', () => {
|
|
6
|
+
expect(typeof useConnectors).toBe('function')
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
it('should be exported', () => {
|
|
10
|
+
expect(useConnectors).toBeDefined()
|
|
11
|
+
})
|
|
12
|
+
})
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type GetConnectorsReturnType,
|
|
5
|
+
getConnectors,
|
|
6
|
+
watchConnectors,
|
|
7
|
+
} from '@growae/reactive'
|
|
8
|
+
import { useSyncExternalStore } from 'react'
|
|
9
|
+
import type { ConfigParameter } from '../types/properties.js'
|
|
10
|
+
import { useConfig } from './useConfig.js'
|
|
11
|
+
|
|
12
|
+
export type UseConnectorsParameters = ConfigParameter
|
|
13
|
+
|
|
14
|
+
export type UseConnectorsReturnType = GetConnectorsReturnType
|
|
15
|
+
|
|
16
|
+
export function useConnectors(
|
|
17
|
+
parameters: UseConnectorsParameters = {},
|
|
18
|
+
): UseConnectorsReturnType {
|
|
19
|
+
const config = useConfig(parameters)
|
|
20
|
+
|
|
21
|
+
return useSyncExternalStore(
|
|
22
|
+
(onChange) => watchConnectors(config, { onChange }),
|
|
23
|
+
() => getConnectors(config),
|
|
24
|
+
() => getConnectors(config),
|
|
25
|
+
)
|
|
26
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { useContractBytecode } from './useContractBytecode.js'
|
|
3
|
+
|
|
4
|
+
describe('useContractBytecode', () => {
|
|
5
|
+
it('should be a function', () => {
|
|
6
|
+
expect(typeof useContractBytecode).toBe('function')
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
it('should be exported', () => {
|
|
10
|
+
expect(useContractBytecode).toBeDefined()
|
|
11
|
+
})
|
|
12
|
+
})
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type GetContractBytecodeParameters,
|
|
5
|
+
type GetContractBytecodeReturnType,
|
|
6
|
+
type GetContractBytecodeErrorType,
|
|
7
|
+
getContractBytecode,
|
|
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 UseContractBytecodeParameters = Compute<
|
|
16
|
+
GetContractBytecodeParameters & ConfigParameter & { enabled?: boolean }
|
|
17
|
+
>
|
|
18
|
+
|
|
19
|
+
export type UseContractBytecodeReturnType = UseQueryReturnType<
|
|
20
|
+
GetContractBytecodeReturnType,
|
|
21
|
+
GetContractBytecodeErrorType
|
|
22
|
+
>
|
|
23
|
+
|
|
24
|
+
export function useContractBytecode(
|
|
25
|
+
parameters: UseContractBytecodeParameters = {} as UseContractBytecodeParameters,
|
|
26
|
+
): UseContractBytecodeReturnType {
|
|
27
|
+
const config = useConfig(parameters)
|
|
28
|
+
const networkId = useNetworkId({ config })
|
|
29
|
+
|
|
30
|
+
return useQuery({
|
|
31
|
+
queryKey: ['contractBytecode', {
|
|
32
|
+
contractId: parameters.contractId,
|
|
33
|
+
networkId: parameters.networkId ?? networkId,
|
|
34
|
+
}],
|
|
35
|
+
queryFn: () => getContractBytecode(config, {
|
|
36
|
+
...parameters,
|
|
37
|
+
networkId: parameters.networkId ?? networkId,
|
|
38
|
+
}),
|
|
39
|
+
enabled: Boolean(parameters.contractId) && (parameters.enabled ?? true),
|
|
40
|
+
}) as UseContractBytecodeReturnType
|
|
41
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { useContractEvents } from './useContractEvents.js'
|
|
3
|
+
|
|
4
|
+
describe('useContractEvents', () => {
|
|
5
|
+
it('should be a function', () => {
|
|
6
|
+
expect(typeof useContractEvents).toBe('function')
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
it('should be exported', () => {
|
|
10
|
+
expect(useContractEvents).toBeDefined()
|
|
11
|
+
})
|
|
12
|
+
})
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type GetContractEventsParameters,
|
|
5
|
+
type GetContractEventsReturnType,
|
|
6
|
+
getContractEvents,
|
|
7
|
+
} from '@growae/reactive'
|
|
8
|
+
import type { Compute } from '@growae/reactive'
|
|
9
|
+
import { type UseQueryReturnType, useQuery } from '../utils/query.js'
|
|
10
|
+
import type { ConfigParameter } from '../types/properties.js'
|
|
11
|
+
import { useConfig } from './useConfig.js'
|
|
12
|
+
import { useNetworkId } from './useNetworkId.js'
|
|
13
|
+
|
|
14
|
+
export type UseContractEventsParameters = Compute<
|
|
15
|
+
GetContractEventsParameters & ConfigParameter & { enabled?: boolean }
|
|
16
|
+
>
|
|
17
|
+
|
|
18
|
+
export type UseContractEventsReturnType = UseQueryReturnType<
|
|
19
|
+
GetContractEventsReturnType,
|
|
20
|
+
Error
|
|
21
|
+
>
|
|
22
|
+
|
|
23
|
+
export function useContractEvents(
|
|
24
|
+
parameters: UseContractEventsParameters = {} as UseContractEventsParameters,
|
|
25
|
+
): UseContractEventsReturnType {
|
|
26
|
+
const config = useConfig(parameters)
|
|
27
|
+
const networkId = useNetworkId({ config })
|
|
28
|
+
|
|
29
|
+
return useQuery({
|
|
30
|
+
queryKey: ['contractEvents', {
|
|
31
|
+
address: parameters.address,
|
|
32
|
+
fromHeight: parameters.fromHeight,
|
|
33
|
+
toHeight: parameters.toHeight,
|
|
34
|
+
networkId: parameters.networkId ?? networkId,
|
|
35
|
+
}],
|
|
36
|
+
queryFn: () => getContractEvents(config, {
|
|
37
|
+
...parameters,
|
|
38
|
+
networkId: parameters.networkId ?? networkId,
|
|
39
|
+
}),
|
|
40
|
+
enabled: Boolean(parameters.address) && (parameters.enabled ?? true),
|
|
41
|
+
}) as UseContractEventsReturnType
|
|
42
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { useDeployContract } from './useDeployContract.js'
|
|
3
|
+
|
|
4
|
+
describe('useDeployContract', () => {
|
|
5
|
+
it('should be a function', () => {
|
|
6
|
+
expect(typeof useDeployContract).toBe('function')
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
it('should be exported', () => {
|
|
10
|
+
expect(useDeployContract).toBeDefined()
|
|
11
|
+
})
|
|
12
|
+
})
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useMutation } from '@tanstack/react-query'
|
|
4
|
+
import {
|
|
5
|
+
type DeployContractParameters,
|
|
6
|
+
type DeployContractReturnType,
|
|
7
|
+
type DeployContractErrorType,
|
|
8
|
+
deployContract,
|
|
9
|
+
} from '@growae/reactive'
|
|
10
|
+
import type { Compute } from '@growae/reactive'
|
|
11
|
+
import type { ConfigParameter } from '../types/properties.js'
|
|
12
|
+
import type { UseMutationReturnType } from '../utils/query.js'
|
|
13
|
+
import { useConfig } from './useConfig.js'
|
|
14
|
+
|
|
15
|
+
export type UseDeployContractParameters<context = unknown> = Compute<
|
|
16
|
+
ConfigParameter & {
|
|
17
|
+
mutation?: {
|
|
18
|
+
onSuccess?: (data: DeployContractReturnType, variables: DeployContractParameters, context: context) => void
|
|
19
|
+
onError?: (error: DeployContractErrorType, variables: DeployContractParameters, context: context) => void
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
>
|
|
23
|
+
|
|
24
|
+
export type UseDeployContractReturnType<context = unknown> = Compute<
|
|
25
|
+
UseMutationReturnType<
|
|
26
|
+
DeployContractReturnType,
|
|
27
|
+
DeployContractErrorType,
|
|
28
|
+
DeployContractParameters,
|
|
29
|
+
context
|
|
30
|
+
> & {
|
|
31
|
+
deployContract: (variables: DeployContractParameters) => void
|
|
32
|
+
deployContractAsync: (variables: DeployContractParameters) => Promise<DeployContractReturnType>
|
|
33
|
+
}
|
|
34
|
+
>
|
|
35
|
+
|
|
36
|
+
export function useDeployContract<context = unknown>(
|
|
37
|
+
parameters: UseDeployContractParameters<context> = {},
|
|
38
|
+
): UseDeployContractReturnType<context> {
|
|
39
|
+
const config = useConfig(parameters)
|
|
40
|
+
|
|
41
|
+
const mutation = useMutation({
|
|
42
|
+
mutationKey: ['deployContract'],
|
|
43
|
+
mutationFn: (variables: DeployContractParameters) =>
|
|
44
|
+
deployContract(config, variables),
|
|
45
|
+
...parameters.mutation,
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
type Return = UseDeployContractReturnType<context>
|
|
49
|
+
return {
|
|
50
|
+
...(mutation as unknown as Return),
|
|
51
|
+
deployContract: mutation.mutate as Return['deployContract'],
|
|
52
|
+
deployContractAsync: mutation.mutateAsync as Return['deployContractAsync'],
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { useDisconnect } from './useDisconnect.js'
|
|
3
|
+
|
|
4
|
+
describe('useDisconnect', () => {
|
|
5
|
+
it('should be a function', () => {
|
|
6
|
+
expect(typeof useDisconnect).toBe('function')
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
it('should be exported', () => {
|
|
10
|
+
expect(useDisconnect).toBeDefined()
|
|
11
|
+
})
|
|
12
|
+
})
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useMutation } from '@tanstack/react-query'
|
|
4
|
+
import {
|
|
5
|
+
type DisconnectParameters,
|
|
6
|
+
type DisconnectReturnType,
|
|
7
|
+
type DisconnectErrorType,
|
|
8
|
+
disconnect,
|
|
9
|
+
} from '@growae/reactive'
|
|
10
|
+
import type { Compute } from '@growae/reactive'
|
|
11
|
+
import type { ConfigParameter } from '../types/properties.js'
|
|
12
|
+
import type { UseMutationReturnType } from '../utils/query.js'
|
|
13
|
+
import { useConfig } from './useConfig.js'
|
|
14
|
+
|
|
15
|
+
export type UseDisconnectParameters<context = unknown> = Compute<
|
|
16
|
+
ConfigParameter & {
|
|
17
|
+
mutation?: {
|
|
18
|
+
onSuccess?: (data: DisconnectReturnType, variables: DisconnectParameters, context: context) => void
|
|
19
|
+
onError?: (error: DisconnectErrorType, variables: DisconnectParameters, context: context) => void
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
>
|
|
23
|
+
|
|
24
|
+
export type UseDisconnectReturnType<context = unknown> = Compute<
|
|
25
|
+
UseMutationReturnType<
|
|
26
|
+
DisconnectReturnType,
|
|
27
|
+
DisconnectErrorType,
|
|
28
|
+
DisconnectParameters,
|
|
29
|
+
context
|
|
30
|
+
> & {
|
|
31
|
+
disconnect: (variables?: DisconnectParameters) => void
|
|
32
|
+
disconnectAsync: (variables?: DisconnectParameters) => Promise<DisconnectReturnType>
|
|
33
|
+
}
|
|
34
|
+
>
|
|
35
|
+
|
|
36
|
+
export function useDisconnect<context = unknown>(
|
|
37
|
+
parameters: UseDisconnectParameters<context> = {},
|
|
38
|
+
): UseDisconnectReturnType<context> {
|
|
39
|
+
const config = useConfig(parameters)
|
|
40
|
+
|
|
41
|
+
const mutation = useMutation({
|
|
42
|
+
mutationKey: ['disconnect'],
|
|
43
|
+
mutationFn: (variables: DisconnectParameters = {}) =>
|
|
44
|
+
disconnect(config, variables),
|
|
45
|
+
...parameters.mutation,
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
type Return = UseDisconnectReturnType<context>
|
|
49
|
+
return {
|
|
50
|
+
...(mutation as unknown as Return),
|
|
51
|
+
disconnect: mutation.mutate as Return['disconnect'],
|
|
52
|
+
disconnectAsync: mutation.mutateAsync as Return['disconnectAsync'],
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { useEstimateGas } from './useEstimateGas.js'
|
|
3
|
+
|
|
4
|
+
describe('useEstimateGas', () => {
|
|
5
|
+
it('should be a function', () => {
|
|
6
|
+
expect(typeof useEstimateGas).toBe('function')
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
it('should be exported', () => {
|
|
10
|
+
expect(useEstimateGas).toBeDefined()
|
|
11
|
+
})
|
|
12
|
+
})
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type EstimateGasParameters,
|
|
5
|
+
type EstimateGasReturnType,
|
|
6
|
+
type EstimateGasErrorType,
|
|
7
|
+
estimateGas,
|
|
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 UseEstimateGasParameters = Compute<
|
|
16
|
+
EstimateGasParameters & ConfigParameter & { enabled?: boolean }
|
|
17
|
+
>
|
|
18
|
+
|
|
19
|
+
export type UseEstimateGasReturnType = UseQueryReturnType<
|
|
20
|
+
EstimateGasReturnType,
|
|
21
|
+
EstimateGasErrorType
|
|
22
|
+
>
|
|
23
|
+
|
|
24
|
+
export function useEstimateGas(
|
|
25
|
+
parameters: UseEstimateGasParameters = {} as UseEstimateGasParameters,
|
|
26
|
+
): UseEstimateGasReturnType {
|
|
27
|
+
const config = useConfig(parameters)
|
|
28
|
+
const networkId = useNetworkId({ config })
|
|
29
|
+
|
|
30
|
+
return useQuery({
|
|
31
|
+
queryKey: ['estimateGas', {
|
|
32
|
+
tx: parameters.tx,
|
|
33
|
+
accountAddress: parameters.accountAddress,
|
|
34
|
+
networkId: parameters.networkId ?? networkId,
|
|
35
|
+
}],
|
|
36
|
+
queryFn: () => estimateGas(config, {
|
|
37
|
+
...parameters,
|
|
38
|
+
networkId: parameters.networkId ?? networkId,
|
|
39
|
+
}),
|
|
40
|
+
enabled: Boolean(parameters.tx && parameters.accountAddress) && (parameters.enabled ?? true),
|
|
41
|
+
}) as UseEstimateGasReturnType
|
|
42
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { useHeight } from './useHeight.js'
|
|
3
|
+
|
|
4
|
+
describe('useHeight', () => {
|
|
5
|
+
it('should be a function', () => {
|
|
6
|
+
expect(typeof useHeight).toBe('function')
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
it('should be exported', () => {
|
|
10
|
+
expect(useHeight).toBeDefined()
|
|
11
|
+
})
|
|
12
|
+
})
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type GetHeightParameters,
|
|
5
|
+
type GetHeightReturnType,
|
|
6
|
+
type GetHeightErrorType,
|
|
7
|
+
getHeight,
|
|
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 UseHeightParameters = Compute<
|
|
16
|
+
GetHeightParameters & ConfigParameter & { enabled?: boolean }
|
|
17
|
+
>
|
|
18
|
+
|
|
19
|
+
export type UseHeightReturnType = UseQueryReturnType<
|
|
20
|
+
GetHeightReturnType,
|
|
21
|
+
GetHeightErrorType
|
|
22
|
+
>
|
|
23
|
+
|
|
24
|
+
export function useHeight(
|
|
25
|
+
parameters: UseHeightParameters = {},
|
|
26
|
+
): UseHeightReturnType {
|
|
27
|
+
const config = useConfig(parameters)
|
|
28
|
+
const networkId = useNetworkId({ config })
|
|
29
|
+
|
|
30
|
+
return useQuery({
|
|
31
|
+
queryKey: ['height', {
|
|
32
|
+
networkId: parameters.networkId ?? networkId,
|
|
33
|
+
}],
|
|
34
|
+
queryFn: () => getHeight(config, {
|
|
35
|
+
networkId: parameters.networkId ?? networkId,
|
|
36
|
+
}),
|
|
37
|
+
enabled: parameters.enabled ?? true,
|
|
38
|
+
}) as UseHeightReturnType
|
|
39
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
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 { useNetworkId } from './useNetworkId.js'
|
|
11
|
+
import { ReactiveProvider } from '../context.js'
|
|
12
|
+
import { createConfig } from '@growae/reactive'
|
|
13
|
+
import { testnet, mainnet } from '@growae/reactive'
|
|
14
|
+
import { mock } from '@growae/reactive'
|
|
15
|
+
|
|
16
|
+
const TEST_ACCOUNTS = [
|
|
17
|
+
'ak_2swhLkgBPeeADxVTABy7tt6d2HgBQFnGJELkBUMY4FUa8RVLM',
|
|
18
|
+
] as const
|
|
19
|
+
|
|
20
|
+
function createTestConfig() {
|
|
21
|
+
return createConfig({
|
|
22
|
+
networks: [testnet, mainnet],
|
|
23
|
+
connectors: [mock({ accounts: [...TEST_ACCOUNTS] })],
|
|
24
|
+
storage: null,
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
describe('useNetworkId', () => {
|
|
29
|
+
it('should return current network id', () => {
|
|
30
|
+
const config = createTestConfig()
|
|
31
|
+
const { result } = renderHook(() => useNetworkId(), {
|
|
32
|
+
wrapper: ({ children }) =>
|
|
33
|
+
createElement(
|
|
34
|
+
ReactiveProvider,
|
|
35
|
+
{ config, reconnectOnMount: false },
|
|
36
|
+
children,
|
|
37
|
+
),
|
|
38
|
+
})
|
|
39
|
+
expect(result.current).toBe('ae_uat')
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('should accept config parameter directly', () => {
|
|
43
|
+
const config = createTestConfig()
|
|
44
|
+
const { result } = renderHook(() => useNetworkId({ config }), {
|
|
45
|
+
wrapper: ({ children }) =>
|
|
46
|
+
createElement(
|
|
47
|
+
ReactiveProvider,
|
|
48
|
+
{ config, reconnectOnMount: false },
|
|
49
|
+
children,
|
|
50
|
+
),
|
|
51
|
+
})
|
|
52
|
+
expect(result.current).toBe('ae_uat')
|
|
53
|
+
})
|
|
54
|
+
})
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type GetNetworkIdReturnType,
|
|
5
|
+
getNetworkId,
|
|
6
|
+
watchNetworkId,
|
|
7
|
+
} from '@growae/reactive'
|
|
8
|
+
import { useSyncExternalStore } from 'react'
|
|
9
|
+
import type { ConfigParameter } from '../types/properties.js'
|
|
10
|
+
import { useConfig } from './useConfig.js'
|
|
11
|
+
|
|
12
|
+
export type UseNetworkIdParameters = ConfigParameter
|
|
13
|
+
|
|
14
|
+
export type UseNetworkIdReturnType = GetNetworkIdReturnType
|
|
15
|
+
|
|
16
|
+
export function useNetworkId(
|
|
17
|
+
parameters: UseNetworkIdParameters = {},
|
|
18
|
+
): UseNetworkIdReturnType {
|
|
19
|
+
const config = useConfig(parameters)
|
|
20
|
+
|
|
21
|
+
return useSyncExternalStore(
|
|
22
|
+
(onChange) => watchNetworkId(config, { onChange }),
|
|
23
|
+
() => getNetworkId(config),
|
|
24
|
+
() => getNetworkId(config),
|
|
25
|
+
)
|
|
26
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { useNetworks } from './useNetworks.js'
|
|
3
|
+
|
|
4
|
+
describe('useNetworks', () => {
|
|
5
|
+
it('should be a function', () => {
|
|
6
|
+
expect(typeof useNetworks).toBe('function')
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
it('should be exported', () => {
|
|
10
|
+
expect(useNetworks).toBeDefined()
|
|
11
|
+
})
|
|
12
|
+
})
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type GetNetworksReturnType,
|
|
5
|
+
getNetworks,
|
|
6
|
+
} from '@growae/reactive'
|
|
7
|
+
import type { ConfigParameter } from '../types/properties.js'
|
|
8
|
+
import { useConfig } from './useConfig.js'
|
|
9
|
+
|
|
10
|
+
export type UseNetworksParameters = ConfigParameter
|
|
11
|
+
|
|
12
|
+
export type UseNetworksReturnType = GetNetworksReturnType
|
|
13
|
+
|
|
14
|
+
export function useNetworks(
|
|
15
|
+
parameters: UseNetworksParameters = {},
|
|
16
|
+
): UseNetworksReturnType {
|
|
17
|
+
const config = useConfig(parameters)
|
|
18
|
+
return getNetworks(config)
|
|
19
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { useNodeClient } from './useNodeClient.js'
|
|
3
|
+
|
|
4
|
+
describe('useNodeClient', () => {
|
|
5
|
+
it('should be a function', () => {
|
|
6
|
+
expect(typeof useNodeClient).toBe('function')
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
it('should be exported', () => {
|
|
10
|
+
expect(useNodeClient).toBeDefined()
|
|
11
|
+
})
|
|
12
|
+
})
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type GetNodeClientParameters,
|
|
5
|
+
type GetNodeClientReturnType,
|
|
6
|
+
getNodeClient,
|
|
7
|
+
watchNodeClient,
|
|
8
|
+
} from '@growae/reactive'
|
|
9
|
+
import type { Compute } from '@growae/reactive'
|
|
10
|
+
import { useSyncExternalStore } from 'react'
|
|
11
|
+
import type { ConfigParameter } from '../types/properties.js'
|
|
12
|
+
import { useConfig } from './useConfig.js'
|
|
13
|
+
|
|
14
|
+
export type UseNodeClientParameters = Compute<
|
|
15
|
+
GetNodeClientParameters & ConfigParameter
|
|
16
|
+
>
|
|
17
|
+
|
|
18
|
+
export type UseNodeClientReturnType = GetNodeClientReturnType
|
|
19
|
+
|
|
20
|
+
export function useNodeClient(
|
|
21
|
+
parameters: UseNodeClientParameters = {},
|
|
22
|
+
): UseNodeClientReturnType {
|
|
23
|
+
const config = useConfig(parameters)
|
|
24
|
+
|
|
25
|
+
return useSyncExternalStore(
|
|
26
|
+
(onChange) => watchNodeClient(config, { onChange }),
|
|
27
|
+
() => getNodeClient(config, parameters),
|
|
28
|
+
() => getNodeClient(config, parameters),
|
|
29
|
+
)
|
|
30
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { useOpenChannel } from './useOpenChannel.js'
|
|
3
|
+
|
|
4
|
+
describe('useOpenChannel', () => {
|
|
5
|
+
it('should be a function', () => {
|
|
6
|
+
expect(typeof useOpenChannel).toBe('function')
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
it('should be exported', () => {
|
|
10
|
+
expect(useOpenChannel).toBeDefined()
|
|
11
|
+
})
|
|
12
|
+
})
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useMutation } from '@tanstack/react-query'
|
|
4
|
+
import {
|
|
5
|
+
type OpenChannelParameters,
|
|
6
|
+
type OpenChannelReturnType,
|
|
7
|
+
openChannel,
|
|
8
|
+
} from '@growae/reactive'
|
|
9
|
+
import type { Compute } from '@growae/reactive'
|
|
10
|
+
import type { ConfigParameter } from '../types/properties.js'
|
|
11
|
+
import type { UseMutationReturnType } from '../utils/query.js'
|
|
12
|
+
import { useConfig } from './useConfig.js'
|
|
13
|
+
|
|
14
|
+
export type UseOpenChannelParameters<context = unknown> = Compute<
|
|
15
|
+
ConfigParameter & {
|
|
16
|
+
mutation?: {
|
|
17
|
+
onSuccess?: (data: OpenChannelReturnType, variables: OpenChannelParameters, context: context) => void
|
|
18
|
+
onError?: (error: Error, variables: OpenChannelParameters, context: context) => void
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
>
|
|
22
|
+
|
|
23
|
+
export type UseOpenChannelReturnType<context = unknown> = Compute<
|
|
24
|
+
UseMutationReturnType<
|
|
25
|
+
OpenChannelReturnType,
|
|
26
|
+
Error,
|
|
27
|
+
OpenChannelParameters,
|
|
28
|
+
context
|
|
29
|
+
> & {
|
|
30
|
+
openChannel: (variables: OpenChannelParameters) => void
|
|
31
|
+
openChannelAsync: (variables: OpenChannelParameters) => Promise<OpenChannelReturnType>
|
|
32
|
+
}
|
|
33
|
+
>
|
|
34
|
+
|
|
35
|
+
export function useOpenChannel<context = unknown>(
|
|
36
|
+
parameters: UseOpenChannelParameters<context> = {},
|
|
37
|
+
): UseOpenChannelReturnType<context> {
|
|
38
|
+
const config = useConfig(parameters)
|
|
39
|
+
|
|
40
|
+
const mutation = useMutation({
|
|
41
|
+
mutationKey: ['openChannel'],
|
|
42
|
+
mutationFn: (variables: OpenChannelParameters) =>
|
|
43
|
+
openChannel(config, variables),
|
|
44
|
+
...parameters.mutation,
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
type Return = UseOpenChannelReturnType<context>
|
|
48
|
+
return {
|
|
49
|
+
...(mutation as unknown as Return),
|
|
50
|
+
openChannel: mutation.mutate as Return['openChannel'],
|
|
51
|
+
openChannelAsync: mutation.mutateAsync as Return['openChannelAsync'],
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { useOracleQueries } from './useOracleQueries.js'
|
|
3
|
+
|
|
4
|
+
describe('useOracleQueries', () => {
|
|
5
|
+
it('should be a function', () => {
|
|
6
|
+
expect(typeof useOracleQueries).toBe('function')
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
it('should be exported', () => {
|
|
10
|
+
expect(useOracleQueries).toBeDefined()
|
|
11
|
+
})
|
|
12
|
+
})
|