@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,53 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useMutation } from '@tanstack/react-query'
|
|
4
|
+
import {
|
|
5
|
+
type RevokeNameParameters,
|
|
6
|
+
type RevokeNameReturnType,
|
|
7
|
+
revokeName,
|
|
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 UseRevokeNameParameters<context = unknown> = Compute<
|
|
15
|
+
ConfigParameter & {
|
|
16
|
+
mutation?: {
|
|
17
|
+
onSuccess?: (data: RevokeNameReturnType, variables: RevokeNameParameters, context: context) => void
|
|
18
|
+
onError?: (error: Error, variables: RevokeNameParameters, context: context) => void
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
>
|
|
22
|
+
|
|
23
|
+
export type UseRevokeNameReturnType<context = unknown> = Compute<
|
|
24
|
+
UseMutationReturnType<
|
|
25
|
+
RevokeNameReturnType,
|
|
26
|
+
Error,
|
|
27
|
+
RevokeNameParameters,
|
|
28
|
+
context
|
|
29
|
+
> & {
|
|
30
|
+
revokeName: (variables: RevokeNameParameters) => void
|
|
31
|
+
revokeNameAsync: (variables: RevokeNameParameters) => Promise<RevokeNameReturnType>
|
|
32
|
+
}
|
|
33
|
+
>
|
|
34
|
+
|
|
35
|
+
export function useRevokeName<context = unknown>(
|
|
36
|
+
parameters: UseRevokeNameParameters<context> = {},
|
|
37
|
+
): UseRevokeNameReturnType<context> {
|
|
38
|
+
const config = useConfig(parameters)
|
|
39
|
+
|
|
40
|
+
const mutation = useMutation({
|
|
41
|
+
mutationKey: ['revokeName'],
|
|
42
|
+
mutationFn: (variables: RevokeNameParameters) =>
|
|
43
|
+
revokeName(config, variables),
|
|
44
|
+
...parameters.mutation,
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
type Return = UseRevokeNameReturnType<context>
|
|
48
|
+
return {
|
|
49
|
+
...(mutation as unknown as Return),
|
|
50
|
+
revokeName: mutation.mutate as Return['revokeName'],
|
|
51
|
+
revokeNameAsync: mutation.mutateAsync as Return['revokeNameAsync'],
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { useSendTransaction } from './useSendTransaction.js'
|
|
3
|
+
|
|
4
|
+
describe('useSendTransaction', () => {
|
|
5
|
+
it('should be a function', () => {
|
|
6
|
+
expect(typeof useSendTransaction).toBe('function')
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
it('should be exported', () => {
|
|
10
|
+
expect(useSendTransaction).toBeDefined()
|
|
11
|
+
})
|
|
12
|
+
})
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useMutation } from '@tanstack/react-query'
|
|
4
|
+
import {
|
|
5
|
+
type SendTransactionParameters,
|
|
6
|
+
type SendTransactionReturnType,
|
|
7
|
+
type SendTransactionErrorType,
|
|
8
|
+
sendTransaction,
|
|
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 UseSendTransactionParameters<context = unknown> = Compute<
|
|
16
|
+
ConfigParameter & {
|
|
17
|
+
mutation?: {
|
|
18
|
+
onSuccess?: (data: SendTransactionReturnType, variables: SendTransactionParameters, context: context) => void
|
|
19
|
+
onError?: (error: SendTransactionErrorType, variables: SendTransactionParameters, context: context) => void
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
>
|
|
23
|
+
|
|
24
|
+
export type UseSendTransactionReturnType<context = unknown> = Compute<
|
|
25
|
+
UseMutationReturnType<
|
|
26
|
+
SendTransactionReturnType,
|
|
27
|
+
SendTransactionErrorType,
|
|
28
|
+
SendTransactionParameters,
|
|
29
|
+
context
|
|
30
|
+
> & {
|
|
31
|
+
sendTransaction: (variables: SendTransactionParameters) => void
|
|
32
|
+
sendTransactionAsync: (variables: SendTransactionParameters) => Promise<SendTransactionReturnType>
|
|
33
|
+
}
|
|
34
|
+
>
|
|
35
|
+
|
|
36
|
+
export function useSendTransaction<context = unknown>(
|
|
37
|
+
parameters: UseSendTransactionParameters<context> = {},
|
|
38
|
+
): UseSendTransactionReturnType<context> {
|
|
39
|
+
const config = useConfig(parameters)
|
|
40
|
+
|
|
41
|
+
const mutation = useMutation({
|
|
42
|
+
mutationKey: ['sendTransaction'],
|
|
43
|
+
mutationFn: (variables: SendTransactionParameters) =>
|
|
44
|
+
sendTransaction(config, variables),
|
|
45
|
+
...parameters.mutation,
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
type Return = UseSendTransactionReturnType<context>
|
|
49
|
+
return {
|
|
50
|
+
...(mutation as unknown as Return),
|
|
51
|
+
sendTransaction: mutation.mutate as Return['sendTransaction'],
|
|
52
|
+
sendTransactionAsync: mutation.mutateAsync as Return['sendTransactionAsync'],
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { useSignMessage } from './useSignMessage.js'
|
|
3
|
+
|
|
4
|
+
describe('useSignMessage', () => {
|
|
5
|
+
it('should be a function', () => {
|
|
6
|
+
expect(typeof useSignMessage).toBe('function')
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
it('should be exported', () => {
|
|
10
|
+
expect(useSignMessage).toBeDefined()
|
|
11
|
+
})
|
|
12
|
+
})
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useMutation } from '@tanstack/react-query'
|
|
4
|
+
import {
|
|
5
|
+
type SignMessageParameters,
|
|
6
|
+
type SignMessageReturnType,
|
|
7
|
+
type SignMessageErrorType,
|
|
8
|
+
signMessage,
|
|
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 UseSignMessageParameters<context = unknown> = Compute<
|
|
16
|
+
ConfigParameter & {
|
|
17
|
+
mutation?: {
|
|
18
|
+
onSuccess?: (data: SignMessageReturnType, variables: SignMessageParameters, context: context) => void
|
|
19
|
+
onError?: (error: SignMessageErrorType, variables: SignMessageParameters, context: context) => void
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
>
|
|
23
|
+
|
|
24
|
+
export type UseSignMessageReturnType<context = unknown> = Compute<
|
|
25
|
+
UseMutationReturnType<
|
|
26
|
+
SignMessageReturnType,
|
|
27
|
+
SignMessageErrorType,
|
|
28
|
+
SignMessageParameters,
|
|
29
|
+
context
|
|
30
|
+
> & {
|
|
31
|
+
signMessage: (variables: SignMessageParameters) => void
|
|
32
|
+
signMessageAsync: (variables: SignMessageParameters) => Promise<SignMessageReturnType>
|
|
33
|
+
}
|
|
34
|
+
>
|
|
35
|
+
|
|
36
|
+
export function useSignMessage<context = unknown>(
|
|
37
|
+
parameters: UseSignMessageParameters<context> = {},
|
|
38
|
+
): UseSignMessageReturnType<context> {
|
|
39
|
+
const config = useConfig(parameters)
|
|
40
|
+
|
|
41
|
+
const mutation = useMutation({
|
|
42
|
+
mutationKey: ['signMessage'],
|
|
43
|
+
mutationFn: (variables: SignMessageParameters) =>
|
|
44
|
+
signMessage(config, variables),
|
|
45
|
+
...parameters.mutation,
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
type Return = UseSignMessageReturnType<context>
|
|
49
|
+
return {
|
|
50
|
+
...(mutation as unknown as Return),
|
|
51
|
+
signMessage: mutation.mutate as Return['signMessage'],
|
|
52
|
+
signMessageAsync: mutation.mutateAsync as Return['signMessageAsync'],
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { useSignTransaction } from './useSignTransaction.js'
|
|
3
|
+
|
|
4
|
+
describe('useSignTransaction', () => {
|
|
5
|
+
it('should be a function', () => {
|
|
6
|
+
expect(typeof useSignTransaction).toBe('function')
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
it('should be exported', () => {
|
|
10
|
+
expect(useSignTransaction).toBeDefined()
|
|
11
|
+
})
|
|
12
|
+
})
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useMutation } from '@tanstack/react-query'
|
|
4
|
+
import {
|
|
5
|
+
type SignTransactionParameters,
|
|
6
|
+
type SignTransactionReturnType,
|
|
7
|
+
type SignTransactionErrorType,
|
|
8
|
+
signTransaction,
|
|
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 UseSignTransactionParameters<context = unknown> = Compute<
|
|
16
|
+
ConfigParameter & {
|
|
17
|
+
mutation?: {
|
|
18
|
+
onSuccess?: (data: SignTransactionReturnType, variables: SignTransactionParameters, context: context) => void
|
|
19
|
+
onError?: (error: SignTransactionErrorType, variables: SignTransactionParameters, context: context) => void
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
>
|
|
23
|
+
|
|
24
|
+
export type UseSignTransactionReturnType<context = unknown> = Compute<
|
|
25
|
+
UseMutationReturnType<
|
|
26
|
+
SignTransactionReturnType,
|
|
27
|
+
SignTransactionErrorType,
|
|
28
|
+
SignTransactionParameters,
|
|
29
|
+
context
|
|
30
|
+
> & {
|
|
31
|
+
signTransaction: (variables: SignTransactionParameters) => void
|
|
32
|
+
signTransactionAsync: (variables: SignTransactionParameters) => Promise<SignTransactionReturnType>
|
|
33
|
+
}
|
|
34
|
+
>
|
|
35
|
+
|
|
36
|
+
export function useSignTransaction<context = unknown>(
|
|
37
|
+
parameters: UseSignTransactionParameters<context> = {},
|
|
38
|
+
): UseSignTransactionReturnType<context> {
|
|
39
|
+
const config = useConfig(parameters)
|
|
40
|
+
|
|
41
|
+
const mutation = useMutation({
|
|
42
|
+
mutationKey: ['signTransaction'],
|
|
43
|
+
mutationFn: (variables: SignTransactionParameters) =>
|
|
44
|
+
signTransaction(config, variables),
|
|
45
|
+
...parameters.mutation,
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
type Return = UseSignTransactionReturnType<context>
|
|
49
|
+
return {
|
|
50
|
+
...(mutation as unknown as Return),
|
|
51
|
+
signTransaction: mutation.mutate as Return['signTransaction'],
|
|
52
|
+
signTransactionAsync: mutation.mutateAsync as Return['signTransactionAsync'],
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { useSignTypedData } from './useSignTypedData.js'
|
|
3
|
+
|
|
4
|
+
describe('useSignTypedData', () => {
|
|
5
|
+
it('should be a function', () => {
|
|
6
|
+
expect(typeof useSignTypedData).toBe('function')
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
it('should be exported', () => {
|
|
10
|
+
expect(useSignTypedData).toBeDefined()
|
|
11
|
+
})
|
|
12
|
+
})
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useMutation } from '@tanstack/react-query'
|
|
4
|
+
import {
|
|
5
|
+
type SignTypedDataParameters,
|
|
6
|
+
type SignTypedDataReturnType,
|
|
7
|
+
type SignTypedDataErrorType,
|
|
8
|
+
signTypedData,
|
|
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 UseSignTypedDataParameters<context = unknown> = Compute<
|
|
16
|
+
ConfigParameter & {
|
|
17
|
+
mutation?: {
|
|
18
|
+
onSuccess?: (data: SignTypedDataReturnType, variables: SignTypedDataParameters, context: context) => void
|
|
19
|
+
onError?: (error: SignTypedDataErrorType, variables: SignTypedDataParameters, context: context) => void
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
>
|
|
23
|
+
|
|
24
|
+
export type UseSignTypedDataReturnType<context = unknown> = Compute<
|
|
25
|
+
UseMutationReturnType<
|
|
26
|
+
SignTypedDataReturnType,
|
|
27
|
+
SignTypedDataErrorType,
|
|
28
|
+
SignTypedDataParameters,
|
|
29
|
+
context
|
|
30
|
+
> & {
|
|
31
|
+
signTypedData: (variables: SignTypedDataParameters) => void
|
|
32
|
+
signTypedDataAsync: (variables: SignTypedDataParameters) => Promise<SignTypedDataReturnType>
|
|
33
|
+
}
|
|
34
|
+
>
|
|
35
|
+
|
|
36
|
+
export function useSignTypedData<context = unknown>(
|
|
37
|
+
parameters: UseSignTypedDataParameters<context> = {},
|
|
38
|
+
): UseSignTypedDataReturnType<context> {
|
|
39
|
+
const config = useConfig(parameters)
|
|
40
|
+
|
|
41
|
+
const mutation = useMutation({
|
|
42
|
+
mutationKey: ['signTypedData'],
|
|
43
|
+
mutationFn: (variables: SignTypedDataParameters) =>
|
|
44
|
+
signTypedData(config, variables),
|
|
45
|
+
...parameters.mutation,
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
type Return = UseSignTypedDataReturnType<context>
|
|
49
|
+
return {
|
|
50
|
+
...(mutation as unknown as Return),
|
|
51
|
+
signTypedData: mutation.mutate as Return['signTypedData'],
|
|
52
|
+
signTypedDataAsync: mutation.mutateAsync as Return['signTypedDataAsync'],
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { useSimulateContract } from './useSimulateContract.js'
|
|
3
|
+
|
|
4
|
+
describe('useSimulateContract', () => {
|
|
5
|
+
it('should be a function', () => {
|
|
6
|
+
expect(typeof useSimulateContract).toBe('function')
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
it('should be exported', () => {
|
|
10
|
+
expect(useSimulateContract).toBeDefined()
|
|
11
|
+
})
|
|
12
|
+
})
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type SimulateContractParameters,
|
|
5
|
+
type SimulateContractReturnType,
|
|
6
|
+
simulateContract,
|
|
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 UseSimulateContractParameters = Compute<
|
|
15
|
+
SimulateContractParameters & ConfigParameter & { enabled?: boolean }
|
|
16
|
+
>
|
|
17
|
+
|
|
18
|
+
export type UseSimulateContractReturnType = UseQueryReturnType<
|
|
19
|
+
SimulateContractReturnType,
|
|
20
|
+
Error
|
|
21
|
+
>
|
|
22
|
+
|
|
23
|
+
export function useSimulateContract(
|
|
24
|
+
parameters: UseSimulateContractParameters = {} as UseSimulateContractParameters,
|
|
25
|
+
): UseSimulateContractReturnType {
|
|
26
|
+
const config = useConfig(parameters)
|
|
27
|
+
const networkId = useNetworkId({ config })
|
|
28
|
+
|
|
29
|
+
return useQuery({
|
|
30
|
+
queryKey: ['simulateContract', {
|
|
31
|
+
address: parameters.address,
|
|
32
|
+
method: parameters.method,
|
|
33
|
+
args: parameters.args,
|
|
34
|
+
networkId: parameters.networkId ?? networkId,
|
|
35
|
+
}],
|
|
36
|
+
queryFn: () => simulateContract(config, {
|
|
37
|
+
...parameters,
|
|
38
|
+
networkId: parameters.networkId ?? networkId,
|
|
39
|
+
}),
|
|
40
|
+
enabled: Boolean(parameters.address && parameters.aci && parameters.method) &&
|
|
41
|
+
(parameters.enabled ?? true),
|
|
42
|
+
}) as UseSimulateContractReturnType
|
|
43
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { useSpend } from './useSpend.js'
|
|
3
|
+
|
|
4
|
+
describe('useSpend', () => {
|
|
5
|
+
it('should be a function', () => {
|
|
6
|
+
expect(typeof useSpend).toBe('function')
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
it('should be exported', () => {
|
|
10
|
+
expect(useSpend).toBeDefined()
|
|
11
|
+
})
|
|
12
|
+
})
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useMutation } from '@tanstack/react-query'
|
|
4
|
+
import {
|
|
5
|
+
type SpendParameters,
|
|
6
|
+
type SpendReturnType,
|
|
7
|
+
type SpendErrorType,
|
|
8
|
+
spend,
|
|
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 UseSpendParameters<context = unknown> = Compute<
|
|
16
|
+
ConfigParameter & {
|
|
17
|
+
mutation?: {
|
|
18
|
+
onSuccess?: (data: SpendReturnType, variables: SpendParameters, context: context) => void
|
|
19
|
+
onError?: (error: SpendErrorType, variables: SpendParameters, context: context) => void
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
>
|
|
23
|
+
|
|
24
|
+
export type UseSpendReturnType<context = unknown> = Compute<
|
|
25
|
+
UseMutationReturnType<
|
|
26
|
+
SpendReturnType,
|
|
27
|
+
SpendErrorType,
|
|
28
|
+
SpendParameters,
|
|
29
|
+
context
|
|
30
|
+
> & {
|
|
31
|
+
spend: (variables: SpendParameters) => void
|
|
32
|
+
spendAsync: (variables: SpendParameters) => Promise<SpendReturnType>
|
|
33
|
+
}
|
|
34
|
+
>
|
|
35
|
+
|
|
36
|
+
export function useSpend<context = unknown>(
|
|
37
|
+
parameters: UseSpendParameters<context> = {},
|
|
38
|
+
): UseSpendReturnType<context> {
|
|
39
|
+
const config = useConfig(parameters)
|
|
40
|
+
|
|
41
|
+
const mutation = useMutation({
|
|
42
|
+
mutationKey: ['spend'],
|
|
43
|
+
mutationFn: (variables: SpendParameters) => spend(config, variables),
|
|
44
|
+
...parameters.mutation,
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
type Return = UseSpendReturnType<context>
|
|
48
|
+
return {
|
|
49
|
+
...(mutation as unknown as Return),
|
|
50
|
+
spend: mutation.mutate as Return['spend'],
|
|
51
|
+
spendAsync: mutation.mutateAsync as Return['spendAsync'],
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { useSwitchNetwork } from './useSwitchNetwork.js'
|
|
3
|
+
|
|
4
|
+
describe('useSwitchNetwork', () => {
|
|
5
|
+
it('should be a function', () => {
|
|
6
|
+
expect(typeof useSwitchNetwork).toBe('function')
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
it('should be exported', () => {
|
|
10
|
+
expect(useSwitchNetwork).toBeDefined()
|
|
11
|
+
})
|
|
12
|
+
})
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useMutation } from '@tanstack/react-query'
|
|
4
|
+
import {
|
|
5
|
+
type SwitchNetworkParameters,
|
|
6
|
+
type SwitchNetworkReturnType,
|
|
7
|
+
type SwitchNetworkErrorType,
|
|
8
|
+
switchNetwork,
|
|
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
|
+
import { useNetworks } from './useNetworks.js'
|
|
15
|
+
|
|
16
|
+
export type UseSwitchNetworkParameters<context = unknown> = Compute<
|
|
17
|
+
ConfigParameter & {
|
|
18
|
+
mutation?: {
|
|
19
|
+
onSuccess?: (data: SwitchNetworkReturnType, variables: SwitchNetworkParameters, context: context) => void
|
|
20
|
+
onError?: (error: SwitchNetworkErrorType, variables: SwitchNetworkParameters, context: context) => void
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
>
|
|
24
|
+
|
|
25
|
+
export type UseSwitchNetworkReturnType<context = unknown> = Compute<
|
|
26
|
+
UseMutationReturnType<
|
|
27
|
+
SwitchNetworkReturnType,
|
|
28
|
+
SwitchNetworkErrorType,
|
|
29
|
+
SwitchNetworkParameters,
|
|
30
|
+
context
|
|
31
|
+
> & {
|
|
32
|
+
switchNetwork: (variables: SwitchNetworkParameters) => void
|
|
33
|
+
switchNetworkAsync: (variables: SwitchNetworkParameters) => Promise<SwitchNetworkReturnType>
|
|
34
|
+
networks: ReturnType<typeof useNetworks>
|
|
35
|
+
}
|
|
36
|
+
>
|
|
37
|
+
|
|
38
|
+
export function useSwitchNetwork<context = unknown>(
|
|
39
|
+
parameters: UseSwitchNetworkParameters<context> = {},
|
|
40
|
+
): UseSwitchNetworkReturnType<context> {
|
|
41
|
+
const config = useConfig(parameters)
|
|
42
|
+
|
|
43
|
+
const mutation = useMutation({
|
|
44
|
+
mutationKey: ['switchNetwork'],
|
|
45
|
+
mutationFn: (variables: SwitchNetworkParameters) =>
|
|
46
|
+
switchNetwork(config, variables),
|
|
47
|
+
...parameters.mutation,
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
type Return = UseSwitchNetworkReturnType<context>
|
|
51
|
+
return {
|
|
52
|
+
...(mutation as unknown as Return),
|
|
53
|
+
switchNetwork: mutation.mutate as Return['switchNetwork'],
|
|
54
|
+
switchNetworkAsync: mutation.mutateAsync as Return['switchNetworkAsync'],
|
|
55
|
+
networks: useNetworks({ config }),
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { useTransaction } from './useTransaction.js'
|
|
3
|
+
|
|
4
|
+
describe('useTransaction', () => {
|
|
5
|
+
it('should be a function', () => {
|
|
6
|
+
expect(typeof useTransaction).toBe('function')
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
it('should be exported', () => {
|
|
10
|
+
expect(useTransaction).toBeDefined()
|
|
11
|
+
})
|
|
12
|
+
})
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type GetTransactionParameters,
|
|
5
|
+
type GetTransactionReturnType,
|
|
6
|
+
type GetTransactionErrorType,
|
|
7
|
+
getTransaction,
|
|
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 UseTransactionParameters = Compute<
|
|
16
|
+
GetTransactionParameters & ConfigParameter & { enabled?: boolean }
|
|
17
|
+
>
|
|
18
|
+
|
|
19
|
+
export type UseTransactionReturnType = UseQueryReturnType<
|
|
20
|
+
GetTransactionReturnType,
|
|
21
|
+
GetTransactionErrorType
|
|
22
|
+
>
|
|
23
|
+
|
|
24
|
+
export function useTransaction(
|
|
25
|
+
parameters: UseTransactionParameters = {} as UseTransactionParameters,
|
|
26
|
+
): UseTransactionReturnType {
|
|
27
|
+
const config = useConfig(parameters)
|
|
28
|
+
const networkId = useNetworkId({ config })
|
|
29
|
+
|
|
30
|
+
return useQuery({
|
|
31
|
+
queryKey: ['transaction', {
|
|
32
|
+
hash: parameters.hash,
|
|
33
|
+
networkId: parameters.networkId ?? networkId,
|
|
34
|
+
}],
|
|
35
|
+
queryFn: () => getTransaction(config, {
|
|
36
|
+
...parameters,
|
|
37
|
+
networkId: parameters.networkId ?? networkId,
|
|
38
|
+
}),
|
|
39
|
+
enabled: Boolean(parameters.hash) && (parameters.enabled ?? true),
|
|
40
|
+
}) as UseTransactionReturnType
|
|
41
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { useTransactionCount } from './useTransactionCount.js'
|
|
3
|
+
|
|
4
|
+
describe('useTransactionCount', () => {
|
|
5
|
+
it('should be a function', () => {
|
|
6
|
+
expect(typeof useTransactionCount).toBe('function')
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
it('should be exported', () => {
|
|
10
|
+
expect(useTransactionCount).toBeDefined()
|
|
11
|
+
})
|
|
12
|
+
})
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type GetTransactionCountParameters,
|
|
5
|
+
type GetTransactionCountReturnType,
|
|
6
|
+
type GetTransactionCountErrorType,
|
|
7
|
+
getTransactionCount,
|
|
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 UseTransactionCountParameters = Compute<
|
|
16
|
+
GetTransactionCountParameters & ConfigParameter & { enabled?: boolean }
|
|
17
|
+
>
|
|
18
|
+
|
|
19
|
+
export type UseTransactionCountReturnType = UseQueryReturnType<
|
|
20
|
+
GetTransactionCountReturnType,
|
|
21
|
+
GetTransactionCountErrorType
|
|
22
|
+
>
|
|
23
|
+
|
|
24
|
+
export function useTransactionCount(
|
|
25
|
+
parameters: UseTransactionCountParameters = {} as UseTransactionCountParameters,
|
|
26
|
+
): UseTransactionCountReturnType {
|
|
27
|
+
const config = useConfig(parameters)
|
|
28
|
+
const networkId = useNetworkId({ config })
|
|
29
|
+
|
|
30
|
+
return useQuery({
|
|
31
|
+
queryKey: ['transactionCount', {
|
|
32
|
+
address: parameters.address,
|
|
33
|
+
networkId: parameters.networkId ?? networkId,
|
|
34
|
+
}],
|
|
35
|
+
queryFn: () => getTransactionCount(config, {
|
|
36
|
+
...parameters,
|
|
37
|
+
networkId: parameters.networkId ?? networkId,
|
|
38
|
+
}),
|
|
39
|
+
enabled: Boolean(parameters.address) && (parameters.enabled ?? true),
|
|
40
|
+
}) as UseTransactionCountReturnType
|
|
41
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { useTransferName } from './useTransferName.js'
|
|
3
|
+
|
|
4
|
+
describe('useTransferName', () => {
|
|
5
|
+
it('should be a function', () => {
|
|
6
|
+
expect(typeof useTransferName).toBe('function')
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
it('should be exported', () => {
|
|
10
|
+
expect(useTransferName).toBeDefined()
|
|
11
|
+
})
|
|
12
|
+
})
|