@wagmi/vue 0.0.1 → 0.0.3
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/README.md +14 -0
- package/dist/esm/composables/useBalance.js +24 -0
- package/dist/esm/composables/useBalance.js.map +1 -0
- package/dist/esm/composables/useEnsAddress.js +24 -0
- package/dist/esm/composables/useEnsAddress.js.map +1 -0
- package/dist/esm/composables/useEnsAvatar.js +24 -0
- package/dist/esm/composables/useEnsAvatar.js.map +1 -0
- package/dist/esm/composables/useEnsName.js +24 -0
- package/dist/esm/composables/useEnsName.js.map +1 -0
- package/dist/esm/composables/useEstimateGas.js +29 -0
- package/dist/esm/composables/useEstimateGas.js.map +1 -0
- package/dist/esm/composables/useReadContract.js +28 -0
- package/dist/esm/composables/useReadContract.js.map +1 -0
- package/dist/esm/composables/useSendTransaction.js +19 -0
- package/dist/esm/composables/useSendTransaction.js.map +1 -0
- package/dist/esm/composables/useSignMessage.js +20 -0
- package/dist/esm/composables/useSignMessage.js.map +1 -0
- package/dist/esm/composables/useSignTypedData.js +19 -0
- package/dist/esm/composables/useSignTypedData.js.map +1 -0
- package/dist/esm/composables/useSimulateContract.js +34 -0
- package/dist/esm/composables/useSimulateContract.js.map +1 -0
- package/dist/esm/composables/useTransaction.js +29 -0
- package/dist/esm/composables/useTransaction.js.map +1 -0
- package/dist/esm/composables/useTransactionReceipt.js +31 -0
- package/dist/esm/composables/useTransactionReceipt.js.map +1 -0
- package/dist/esm/composables/useWaitForTransactionReceipt.js +28 -0
- package/dist/esm/composables/useWaitForTransactionReceipt.js.map +1 -0
- package/dist/esm/composables/useWriteContract.js +19 -0
- package/dist/esm/composables/useWriteContract.js.map +1 -0
- package/dist/esm/exports/index.js +14 -0
- package/dist/esm/exports/index.js.map +1 -1
- package/dist/esm/nuxt/module.js +41 -7
- package/dist/esm/nuxt/module.js.map +1 -1
- package/dist/esm/nuxt/runtime/composables.js +2 -0
- package/dist/esm/nuxt/runtime/composables.js.map +1 -0
- package/dist/esm/tsconfig.build.tsbuildinfo +1 -1
- package/dist/esm/utils/query.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/types/composables/useBalance.d.ts +12 -0
- package/dist/types/composables/useBalance.d.ts.map +1 -0
- package/dist/types/composables/useEnsAddress.d.ts +11 -0
- package/dist/types/composables/useEnsAddress.d.ts.map +1 -0
- package/dist/types/composables/useEnsAvatar.d.ts +11 -0
- package/dist/types/composables/useEnsAvatar.d.ts.map +1 -0
- package/dist/types/composables/useEnsName.d.ts +11 -0
- package/dist/types/composables/useEnsName.d.ts.map +1 -0
- package/dist/types/composables/useEstimateGas.d.ts +10 -0
- package/dist/types/composables/useEstimateGas.d.ts.map +1 -0
- package/dist/types/composables/useReadContract.d.ts +12 -0
- package/dist/types/composables/useReadContract.d.ts.map +1 -0
- package/dist/types/composables/useSendTransaction.d.ts +15 -0
- package/dist/types/composables/useSendTransaction.d.ts.map +1 -0
- package/dist/types/composables/useSignMessage.d.ts +15 -0
- package/dist/types/composables/useSignMessage.d.ts.map +1 -0
- package/dist/types/composables/useSignTypedData.d.ts +15 -0
- package/dist/types/composables/useSignTypedData.d.ts.map +1 -0
- package/dist/types/composables/useSimulateContract.d.ts +12 -0
- package/dist/types/composables/useSimulateContract.d.ts.map +1 -0
- package/dist/types/composables/useTransaction.d.ts +11 -0
- package/dist/types/composables/useTransaction.d.ts.map +1 -0
- package/dist/types/composables/useTransactionReceipt.d.ts +12 -0
- package/dist/types/composables/useTransactionReceipt.d.ts.map +1 -0
- package/dist/types/composables/useWaitForTransactionReceipt.d.ts +11 -0
- package/dist/types/composables/useWaitForTransactionReceipt.d.ts.map +1 -0
- package/dist/types/composables/useWriteContract.d.ts +15 -0
- package/dist/types/composables/useWriteContract.d.ts.map +1 -0
- package/dist/types/exports/index.d.ts +14 -0
- package/dist/types/exports/index.d.ts.map +1 -1
- package/dist/types/nuxt/module.d.ts.map +1 -1
- package/dist/types/nuxt/runtime/composables.d.ts +2 -0
- package/dist/types/nuxt/runtime/composables.d.ts.map +1 -0
- package/dist/types/types/ref.d.ts +2 -2
- package/dist/types/types/ref.d.ts.map +1 -1
- package/dist/types/utils/query.d.ts +3 -3
- package/dist/types/utils/query.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +3 -3
- package/src/composables/useBalance.ts +69 -0
- package/src/composables/useEnsAddress.ts +65 -0
- package/src/composables/useEnsAvatar.ts +65 -0
- package/src/composables/useEnsName.ts +65 -0
- package/src/composables/useEstimateGas.ts +83 -0
- package/src/composables/useReadContract.ts +121 -0
- package/src/composables/useSendTransaction.ts +76 -0
- package/src/composables/useSignMessage.ts +63 -0
- package/src/composables/useSignTypedData.ts +64 -0
- package/src/composables/useSimulateContract.ts +148 -0
- package/src/composables/useTransaction.ts +88 -0
- package/src/composables/useTransactionReceipt.ts +85 -0
- package/src/composables/useWaitForTransactionReceipt.ts +81 -0
- package/src/composables/useWriteContract.ts +85 -0
- package/src/exports/index.ts +84 -0
- package/src/nuxt/module.ts +42 -8
- package/src/nuxt/runtime/composables.ts +1 -0
- package/src/types/ref.ts +3 -3
- package/src/utils/query.ts +5 -3
- package/src/version.ts +1 -1
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Config,
|
|
3
|
+
ResolvedRegister,
|
|
4
|
+
SimulateContractErrorType,
|
|
5
|
+
} from '@wagmi/core'
|
|
6
|
+
import {
|
|
7
|
+
type SimulateContractData,
|
|
8
|
+
type SimulateContractOptions,
|
|
9
|
+
type SimulateContractQueryFnData,
|
|
10
|
+
type SimulateContractQueryKey,
|
|
11
|
+
simulateContractQueryOptions,
|
|
12
|
+
} from '@wagmi/core/query'
|
|
13
|
+
import type { Abi, ContractFunctionArgs, ContractFunctionName } from 'viem'
|
|
14
|
+
import { type MaybeRef, computed } from 'vue'
|
|
15
|
+
|
|
16
|
+
import {
|
|
17
|
+
type ConfigParameter,
|
|
18
|
+
type QueryParameter,
|
|
19
|
+
} from '../types/properties.js'
|
|
20
|
+
import type { DeepMaybeRef } from '../types/ref.js'
|
|
21
|
+
import { deepUnref } from '../utils/cloneDeep.js'
|
|
22
|
+
import { type UseQueryReturnType, useQuery } from '../utils/query.js'
|
|
23
|
+
import { useChainId } from './useChainId.js'
|
|
24
|
+
import { useConfig } from './useConfig.js'
|
|
25
|
+
import { useConnectorClient } from './useConnectorClient.js'
|
|
26
|
+
|
|
27
|
+
export type UseSimulateContractParameters<
|
|
28
|
+
abi extends Abi | readonly unknown[] = Abi,
|
|
29
|
+
functionName extends ContractFunctionName<
|
|
30
|
+
abi,
|
|
31
|
+
'nonpayable' | 'payable'
|
|
32
|
+
> = ContractFunctionName<abi, 'nonpayable' | 'payable'>,
|
|
33
|
+
args extends ContractFunctionArgs<
|
|
34
|
+
abi,
|
|
35
|
+
'nonpayable' | 'payable',
|
|
36
|
+
functionName
|
|
37
|
+
> = ContractFunctionArgs<abi, 'nonpayable' | 'payable', functionName>,
|
|
38
|
+
config extends Config = Config,
|
|
39
|
+
chainId extends config['chains'][number]['id'] | undefined = undefined,
|
|
40
|
+
selectData = SimulateContractData<abi, functionName, args, config, chainId>,
|
|
41
|
+
> = MaybeRef<
|
|
42
|
+
DeepMaybeRef<
|
|
43
|
+
SimulateContractOptions<abi, functionName, args, config, chainId>
|
|
44
|
+
> &
|
|
45
|
+
ConfigParameter<config> &
|
|
46
|
+
QueryParameter<
|
|
47
|
+
SimulateContractQueryFnData<abi, functionName, args, config, chainId>,
|
|
48
|
+
SimulateContractErrorType,
|
|
49
|
+
selectData,
|
|
50
|
+
SimulateContractQueryKey<abi, functionName, args, config, chainId>
|
|
51
|
+
>
|
|
52
|
+
>
|
|
53
|
+
|
|
54
|
+
export type UseSimulateContractReturnType<
|
|
55
|
+
abi extends Abi | readonly unknown[] = Abi,
|
|
56
|
+
functionName extends ContractFunctionName<
|
|
57
|
+
abi,
|
|
58
|
+
'nonpayable' | 'payable'
|
|
59
|
+
> = ContractFunctionName<abi, 'nonpayable' | 'payable'>,
|
|
60
|
+
args extends ContractFunctionArgs<
|
|
61
|
+
abi,
|
|
62
|
+
'nonpayable' | 'payable',
|
|
63
|
+
functionName
|
|
64
|
+
> = ContractFunctionArgs<abi, 'nonpayable' | 'payable', functionName>,
|
|
65
|
+
config extends Config = Config,
|
|
66
|
+
chainId extends config['chains'][number]['id'] | undefined = undefined,
|
|
67
|
+
selectData = SimulateContractData<abi, functionName, args, config, chainId>,
|
|
68
|
+
> = UseQueryReturnType<selectData, SimulateContractErrorType>
|
|
69
|
+
|
|
70
|
+
/** https://wagmi.sh/vue/api/composables/useSimulateContract */
|
|
71
|
+
export function useSimulateContract<
|
|
72
|
+
const abi extends Abi | readonly unknown[],
|
|
73
|
+
functionName extends ContractFunctionName<abi, 'nonpayable' | 'payable'>,
|
|
74
|
+
args extends ContractFunctionArgs<
|
|
75
|
+
abi,
|
|
76
|
+
'nonpayable' | 'payable',
|
|
77
|
+
functionName
|
|
78
|
+
>,
|
|
79
|
+
config extends Config = ResolvedRegister['config'],
|
|
80
|
+
chainId extends config['chains'][number]['id'] | undefined = undefined,
|
|
81
|
+
selectData = SimulateContractData<abi, functionName, args, config, chainId>,
|
|
82
|
+
>(
|
|
83
|
+
parameters_: UseSimulateContractParameters<
|
|
84
|
+
abi,
|
|
85
|
+
functionName,
|
|
86
|
+
args,
|
|
87
|
+
config,
|
|
88
|
+
chainId,
|
|
89
|
+
selectData
|
|
90
|
+
> = {} as any,
|
|
91
|
+
): UseSimulateContractReturnType<
|
|
92
|
+
abi,
|
|
93
|
+
functionName,
|
|
94
|
+
args,
|
|
95
|
+
config,
|
|
96
|
+
chainId,
|
|
97
|
+
selectData
|
|
98
|
+
> {
|
|
99
|
+
const parameters = computed(() => deepUnref(parameters_)) as any
|
|
100
|
+
|
|
101
|
+
const config = useConfig(parameters)
|
|
102
|
+
const { data: connectorClient } = useConnectorClient(
|
|
103
|
+
computed(() => ({
|
|
104
|
+
connector: parameters.value.connector,
|
|
105
|
+
query: { enabled: parameters.value.account === undefined },
|
|
106
|
+
})),
|
|
107
|
+
)
|
|
108
|
+
const configChainId = useChainId({ config })
|
|
109
|
+
|
|
110
|
+
const queryOptions = computed(() => {
|
|
111
|
+
const {
|
|
112
|
+
abi,
|
|
113
|
+
account = connectorClient?.value?.account,
|
|
114
|
+
address,
|
|
115
|
+
chainId = configChainId.value,
|
|
116
|
+
functionName,
|
|
117
|
+
query = {},
|
|
118
|
+
} = parameters.value
|
|
119
|
+
const options = simulateContractQueryOptions<
|
|
120
|
+
config,
|
|
121
|
+
abi,
|
|
122
|
+
functionName,
|
|
123
|
+
args,
|
|
124
|
+
chainId
|
|
125
|
+
>(config as any, {
|
|
126
|
+
...parameters.value,
|
|
127
|
+
account,
|
|
128
|
+
chainId,
|
|
129
|
+
})
|
|
130
|
+
const enabled = Boolean(
|
|
131
|
+
abi && address && functionName && (query.enabled ?? true),
|
|
132
|
+
)
|
|
133
|
+
return {
|
|
134
|
+
...query,
|
|
135
|
+
...options,
|
|
136
|
+
enabled,
|
|
137
|
+
}
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
return useQuery(queryOptions as any) as UseSimulateContractReturnType<
|
|
141
|
+
abi,
|
|
142
|
+
functionName,
|
|
143
|
+
args,
|
|
144
|
+
config,
|
|
145
|
+
chainId,
|
|
146
|
+
selectData
|
|
147
|
+
>
|
|
148
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Config,
|
|
3
|
+
GetTransactionErrorType,
|
|
4
|
+
ResolvedRegister,
|
|
5
|
+
} from '@wagmi/core'
|
|
6
|
+
import { type Evaluate } from '@wagmi/core/internal'
|
|
7
|
+
import {
|
|
8
|
+
type GetTransactionData,
|
|
9
|
+
type GetTransactionOptions,
|
|
10
|
+
type GetTransactionQueryFnData,
|
|
11
|
+
type GetTransactionQueryKey,
|
|
12
|
+
getTransactionQueryOptions,
|
|
13
|
+
} from '@wagmi/core/query'
|
|
14
|
+
|
|
15
|
+
import { computed } from 'vue'
|
|
16
|
+
import type { ConfigParameter, QueryParameter } from '../types/properties.js'
|
|
17
|
+
import type { DeepMaybeRef } from '../types/ref.js'
|
|
18
|
+
import { deepUnref } from '../utils/cloneDeep.js'
|
|
19
|
+
import { type UseQueryReturnType, useQuery } from '../utils/query.js'
|
|
20
|
+
import { useChainId } from './useChainId.js'
|
|
21
|
+
import { useConfig } from './useConfig.js'
|
|
22
|
+
|
|
23
|
+
export type UseTransactionParameters<
|
|
24
|
+
config extends Config = Config,
|
|
25
|
+
chainId extends config['chains'][number]['id'] = config['chains'][number]['id'],
|
|
26
|
+
selectData = GetTransactionData<config, chainId>,
|
|
27
|
+
> = Evaluate<
|
|
28
|
+
DeepMaybeRef<
|
|
29
|
+
GetTransactionOptions<config, chainId> &
|
|
30
|
+
ConfigParameter<config> &
|
|
31
|
+
QueryParameter<
|
|
32
|
+
GetTransactionQueryFnData<config, chainId>,
|
|
33
|
+
GetTransactionErrorType,
|
|
34
|
+
selectData,
|
|
35
|
+
GetTransactionQueryKey<config, chainId>
|
|
36
|
+
>
|
|
37
|
+
>
|
|
38
|
+
>
|
|
39
|
+
|
|
40
|
+
export type UseTransactionReturnType<
|
|
41
|
+
config extends Config = Config,
|
|
42
|
+
chainId extends config['chains'][number]['id'] = config['chains'][number]['id'],
|
|
43
|
+
selectData = GetTransactionData<config, chainId>,
|
|
44
|
+
> = UseQueryReturnType<selectData, GetTransactionErrorType>
|
|
45
|
+
|
|
46
|
+
/** https://wagmi.sh/vue/api/composables/useTransaction */
|
|
47
|
+
export function useTransaction<
|
|
48
|
+
config extends Config = ResolvedRegister['config'],
|
|
49
|
+
chainId extends config['chains'][number]['id'] = config['chains'][number]['id'],
|
|
50
|
+
selectData = GetTransactionData<config, chainId>,
|
|
51
|
+
>(
|
|
52
|
+
parameters_: UseTransactionParameters<config, chainId, selectData> = {},
|
|
53
|
+
): UseTransactionReturnType<config, chainId, selectData> {
|
|
54
|
+
const parameters = computed(() => deepUnref(parameters_))
|
|
55
|
+
|
|
56
|
+
const config = useConfig(parameters)
|
|
57
|
+
const configChainId = useChainId({ config })
|
|
58
|
+
|
|
59
|
+
const queryOptions = computed(() => {
|
|
60
|
+
const {
|
|
61
|
+
blockHash,
|
|
62
|
+
blockNumber,
|
|
63
|
+
blockTag,
|
|
64
|
+
chainId = configChainId.value,
|
|
65
|
+
hash,
|
|
66
|
+
query = {},
|
|
67
|
+
} = parameters.value
|
|
68
|
+
const options = getTransactionQueryOptions(config, {
|
|
69
|
+
...parameters.value,
|
|
70
|
+
chainId,
|
|
71
|
+
})
|
|
72
|
+
const enabled = Boolean(
|
|
73
|
+
!(blockHash && blockNumber && blockTag && hash) &&
|
|
74
|
+
(query.enabled ?? true),
|
|
75
|
+
)
|
|
76
|
+
return {
|
|
77
|
+
...query,
|
|
78
|
+
...options,
|
|
79
|
+
enabled,
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
return useQuery(queryOptions as any) as UseTransactionReturnType<
|
|
84
|
+
config,
|
|
85
|
+
chainId,
|
|
86
|
+
selectData
|
|
87
|
+
>
|
|
88
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Config,
|
|
3
|
+
type GetTransactionReceiptErrorType,
|
|
4
|
+
type ResolvedRegister,
|
|
5
|
+
} from '@wagmi/core'
|
|
6
|
+
import { type Evaluate } from '@wagmi/core/internal'
|
|
7
|
+
import {
|
|
8
|
+
type GetTransactionReceiptData,
|
|
9
|
+
type GetTransactionReceiptOptions,
|
|
10
|
+
type GetTransactionReceiptQueryKey,
|
|
11
|
+
getTransactionReceiptQueryOptions,
|
|
12
|
+
} from '@wagmi/core/query'
|
|
13
|
+
import { type GetTransactionReceiptQueryFnData } from '@wagmi/core/query'
|
|
14
|
+
|
|
15
|
+
import { computed } from 'vue'
|
|
16
|
+
import {
|
|
17
|
+
type ConfigParameter,
|
|
18
|
+
type QueryParameter,
|
|
19
|
+
} from '../types/properties.js'
|
|
20
|
+
import type { DeepMaybeRef } from '../types/ref.js'
|
|
21
|
+
import { deepUnref } from '../utils/cloneDeep.js'
|
|
22
|
+
import { type UseQueryReturnType, useQuery } from '../utils/query.js'
|
|
23
|
+
import { useChainId } from './useChainId.js'
|
|
24
|
+
import { useConfig } from './useConfig.js'
|
|
25
|
+
|
|
26
|
+
export type UseTransactionReceiptParameters<
|
|
27
|
+
config extends Config = Config,
|
|
28
|
+
chainId extends config['chains'][number]['id'] = config['chains'][number]['id'],
|
|
29
|
+
selectData = GetTransactionReceiptData<config, chainId>,
|
|
30
|
+
> = Evaluate<
|
|
31
|
+
DeepMaybeRef<
|
|
32
|
+
GetTransactionReceiptOptions<config, chainId> &
|
|
33
|
+
ConfigParameter<config> &
|
|
34
|
+
QueryParameter<
|
|
35
|
+
GetTransactionReceiptQueryFnData<config, chainId>,
|
|
36
|
+
GetTransactionReceiptErrorType,
|
|
37
|
+
selectData,
|
|
38
|
+
GetTransactionReceiptQueryKey<config, chainId>
|
|
39
|
+
>
|
|
40
|
+
>
|
|
41
|
+
>
|
|
42
|
+
|
|
43
|
+
export type UseTransactionReceiptReturnType<
|
|
44
|
+
config extends Config = Config,
|
|
45
|
+
chainId extends config['chains'][number]['id'] = config['chains'][number]['id'],
|
|
46
|
+
selectData = GetTransactionReceiptData<config, chainId>,
|
|
47
|
+
> = UseQueryReturnType<selectData, GetTransactionReceiptErrorType>
|
|
48
|
+
|
|
49
|
+
/** https://wagmi.sh/vue/api/composables/useTransactionReceipt */
|
|
50
|
+
export function useTransactionReceipt<
|
|
51
|
+
config extends Config = ResolvedRegister['config'],
|
|
52
|
+
chainId extends config['chains'][number]['id'] = config['chains'][number]['id'],
|
|
53
|
+
selectData = GetTransactionReceiptData<config, chainId>,
|
|
54
|
+
>(
|
|
55
|
+
parameters_: UseTransactionReceiptParameters<
|
|
56
|
+
config,
|
|
57
|
+
chainId,
|
|
58
|
+
selectData
|
|
59
|
+
> = {},
|
|
60
|
+
): UseTransactionReceiptReturnType<config, chainId, selectData> {
|
|
61
|
+
const parameters = computed(() => deepUnref(parameters_))
|
|
62
|
+
|
|
63
|
+
const config = useConfig(parameters)
|
|
64
|
+
const configChainId = useChainId({ config })
|
|
65
|
+
|
|
66
|
+
const queryOptions = computed(() => {
|
|
67
|
+
const { chainId = configChainId.value, hash, query = {} } = parameters.value
|
|
68
|
+
const options = getTransactionReceiptQueryOptions(config, {
|
|
69
|
+
...parameters.value,
|
|
70
|
+
chainId,
|
|
71
|
+
})
|
|
72
|
+
const enabled = Boolean(hash && (query.enabled ?? true))
|
|
73
|
+
return {
|
|
74
|
+
...(query as any),
|
|
75
|
+
...options,
|
|
76
|
+
enabled,
|
|
77
|
+
}
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
return useQuery(queryOptions) as UseTransactionReceiptReturnType<
|
|
81
|
+
config,
|
|
82
|
+
chainId,
|
|
83
|
+
selectData
|
|
84
|
+
>
|
|
85
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Config,
|
|
3
|
+
ResolvedRegister,
|
|
4
|
+
WaitForTransactionReceiptErrorType,
|
|
5
|
+
} from '@wagmi/core'
|
|
6
|
+
import { type Evaluate } from '@wagmi/core/internal'
|
|
7
|
+
import {
|
|
8
|
+
type WaitForTransactionReceiptData,
|
|
9
|
+
type WaitForTransactionReceiptOptions,
|
|
10
|
+
type WaitForTransactionReceiptQueryFnData,
|
|
11
|
+
type WaitForTransactionReceiptQueryKey,
|
|
12
|
+
waitForTransactionReceiptQueryOptions,
|
|
13
|
+
} from '@wagmi/core/query'
|
|
14
|
+
import { computed } from 'vue'
|
|
15
|
+
|
|
16
|
+
import type { ConfigParameter, QueryParameter } from '../types/properties.js'
|
|
17
|
+
import type { DeepMaybeRef } from '../types/ref.js'
|
|
18
|
+
import { deepUnref } from '../utils/cloneDeep.js'
|
|
19
|
+
import { type UseQueryReturnType, useQuery } from '../utils/query.js'
|
|
20
|
+
import { useChainId } from './useChainId.js'
|
|
21
|
+
import { useConfig } from './useConfig.js'
|
|
22
|
+
|
|
23
|
+
export type UseWaitForTransactionReceiptParameters<
|
|
24
|
+
config extends Config = Config,
|
|
25
|
+
chainId extends config['chains'][number]['id'] = config['chains'][number]['id'],
|
|
26
|
+
selectData = WaitForTransactionReceiptData<config, chainId>,
|
|
27
|
+
> = Evaluate<
|
|
28
|
+
DeepMaybeRef<
|
|
29
|
+
WaitForTransactionReceiptOptions<config, chainId> &
|
|
30
|
+
ConfigParameter<config> &
|
|
31
|
+
QueryParameter<
|
|
32
|
+
WaitForTransactionReceiptQueryFnData<config, chainId>,
|
|
33
|
+
WaitForTransactionReceiptErrorType,
|
|
34
|
+
selectData,
|
|
35
|
+
WaitForTransactionReceiptQueryKey<config, chainId>
|
|
36
|
+
>
|
|
37
|
+
>
|
|
38
|
+
>
|
|
39
|
+
|
|
40
|
+
export type UseWaitForTransactionReceiptReturnType<
|
|
41
|
+
config extends Config = Config,
|
|
42
|
+
chainId extends config['chains'][number]['id'] = config['chains'][number]['id'],
|
|
43
|
+
selectData = WaitForTransactionReceiptData<config, chainId>,
|
|
44
|
+
> = UseQueryReturnType<selectData, WaitForTransactionReceiptErrorType>
|
|
45
|
+
|
|
46
|
+
/** https://wagmi.sh/vue/api/composables/useWaitForTransactionReceipt */
|
|
47
|
+
export function useWaitForTransactionReceipt<
|
|
48
|
+
config extends Config = ResolvedRegister['config'],
|
|
49
|
+
chainId extends config['chains'][number]['id'] = config['chains'][number]['id'],
|
|
50
|
+
selectData = WaitForTransactionReceiptData<config, chainId>,
|
|
51
|
+
>(
|
|
52
|
+
parameters_: UseWaitForTransactionReceiptParameters<
|
|
53
|
+
config,
|
|
54
|
+
chainId,
|
|
55
|
+
selectData
|
|
56
|
+
> = {},
|
|
57
|
+
): UseWaitForTransactionReceiptReturnType<config, chainId, selectData> {
|
|
58
|
+
const parameters = computed(() => deepUnref(parameters_))
|
|
59
|
+
const config = useConfig(parameters_)
|
|
60
|
+
const configChainId = useChainId()
|
|
61
|
+
|
|
62
|
+
const queryOptions = computed(() => {
|
|
63
|
+
const { chainId = configChainId.value, hash, query = {} } = parameters.value
|
|
64
|
+
|
|
65
|
+
const options = waitForTransactionReceiptQueryOptions(config, {
|
|
66
|
+
...parameters.value,
|
|
67
|
+
chainId,
|
|
68
|
+
})
|
|
69
|
+
const enabled = Boolean(hash && (query.enabled ?? true))
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
...query,
|
|
73
|
+
...options,
|
|
74
|
+
enabled,
|
|
75
|
+
}
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
return useQuery(
|
|
79
|
+
queryOptions as any,
|
|
80
|
+
) as UseWaitForTransactionReceiptReturnType<config, chainId, selectData>
|
|
81
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { useMutation } from '@tanstack/vue-query'
|
|
2
|
+
import type {
|
|
3
|
+
Config,
|
|
4
|
+
ResolvedRegister,
|
|
5
|
+
WriteContractErrorType,
|
|
6
|
+
} from '@wagmi/core'
|
|
7
|
+
import {
|
|
8
|
+
type WriteContractData,
|
|
9
|
+
type WriteContractMutate,
|
|
10
|
+
type WriteContractMutateAsync,
|
|
11
|
+
type WriteContractVariables,
|
|
12
|
+
writeContractMutationOptions,
|
|
13
|
+
} from '@wagmi/core/query'
|
|
14
|
+
import type { Abi } from 'viem'
|
|
15
|
+
|
|
16
|
+
import type { ConfigParameter } from '../types/properties.js'
|
|
17
|
+
import type {
|
|
18
|
+
UseMutationParameters,
|
|
19
|
+
UseMutationReturnType,
|
|
20
|
+
} from '../utils/query.js'
|
|
21
|
+
import { useConfig } from './useConfig.js'
|
|
22
|
+
|
|
23
|
+
export type UseWriteContractParameters<
|
|
24
|
+
config extends Config = Config,
|
|
25
|
+
context = unknown,
|
|
26
|
+
> = ConfigParameter<config> & {
|
|
27
|
+
mutation?:
|
|
28
|
+
| UseMutationParameters<
|
|
29
|
+
WriteContractData,
|
|
30
|
+
WriteContractErrorType,
|
|
31
|
+
WriteContractVariables<
|
|
32
|
+
Abi,
|
|
33
|
+
string,
|
|
34
|
+
readonly unknown[],
|
|
35
|
+
config,
|
|
36
|
+
config['chains'][number]['id']
|
|
37
|
+
>,
|
|
38
|
+
context
|
|
39
|
+
>
|
|
40
|
+
| undefined
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type UseWriteContractReturnType<
|
|
44
|
+
config extends Config = Config,
|
|
45
|
+
context = unknown,
|
|
46
|
+
> = UseMutationReturnType<
|
|
47
|
+
WriteContractData,
|
|
48
|
+
WriteContractErrorType,
|
|
49
|
+
WriteContractVariables<
|
|
50
|
+
Abi,
|
|
51
|
+
string,
|
|
52
|
+
readonly unknown[],
|
|
53
|
+
config,
|
|
54
|
+
config['chains'][number]['id']
|
|
55
|
+
>,
|
|
56
|
+
context
|
|
57
|
+
> & {
|
|
58
|
+
writeContract: WriteContractMutate<config, context>
|
|
59
|
+
writeContractAsync: WriteContractMutateAsync<config, context>
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** https://wagmi.sh/vue/api/composables/useWriteContract */
|
|
63
|
+
export function useWriteContract<
|
|
64
|
+
config extends Config = ResolvedRegister['config'],
|
|
65
|
+
context = unknown,
|
|
66
|
+
>(
|
|
67
|
+
parameters: UseWriteContractParameters<config, context> = {},
|
|
68
|
+
): UseWriteContractReturnType<config, context> {
|
|
69
|
+
const { mutation } = parameters
|
|
70
|
+
|
|
71
|
+
const config = useConfig(parameters)
|
|
72
|
+
|
|
73
|
+
const mutationOptions = writeContractMutationOptions(config)
|
|
74
|
+
const { mutate, mutateAsync, ...result } = useMutation({
|
|
75
|
+
...mutation,
|
|
76
|
+
...mutationOptions,
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
type Return = UseWriteContractReturnType<config, context>
|
|
80
|
+
return {
|
|
81
|
+
...result,
|
|
82
|
+
writeContract: mutate as Return['writeContract'],
|
|
83
|
+
writeContractAsync: mutateAsync as Return['writeContractAsync'],
|
|
84
|
+
}
|
|
85
|
+
}
|
package/src/exports/index.ts
CHANGED
|
@@ -32,6 +32,12 @@ export {
|
|
|
32
32
|
useAccountEffect,
|
|
33
33
|
} from '../composables/useAccountEffect.js'
|
|
34
34
|
|
|
35
|
+
export {
|
|
36
|
+
type UseBalanceParameters,
|
|
37
|
+
type UseBalanceReturnType,
|
|
38
|
+
useBalance,
|
|
39
|
+
} from '../composables/useBalance.js'
|
|
40
|
+
|
|
35
41
|
export {
|
|
36
42
|
type UseBlockNumberParameters,
|
|
37
43
|
type UseBlockNumberReturnType,
|
|
@@ -92,12 +98,66 @@ export {
|
|
|
92
98
|
useDisconnect,
|
|
93
99
|
} from '../composables/useDisconnect.js'
|
|
94
100
|
|
|
101
|
+
export {
|
|
102
|
+
type UseEnsAddressParameters,
|
|
103
|
+
type UseEnsAddressReturnType,
|
|
104
|
+
useEnsAddress,
|
|
105
|
+
} from '../composables/useEnsAddress.js'
|
|
106
|
+
|
|
107
|
+
export {
|
|
108
|
+
type UseEnsAvatarParameters,
|
|
109
|
+
type UseEnsAvatarReturnType,
|
|
110
|
+
useEnsAvatar,
|
|
111
|
+
} from '../composables/useEnsAvatar.js'
|
|
112
|
+
|
|
113
|
+
export {
|
|
114
|
+
type UseEnsNameParameters,
|
|
115
|
+
type UseEnsNameReturnType,
|
|
116
|
+
useEnsName,
|
|
117
|
+
} from '../composables/useEnsName.js'
|
|
118
|
+
|
|
119
|
+
export {
|
|
120
|
+
type UseEstimateGasParameters,
|
|
121
|
+
type UseEstimateGasReturnType,
|
|
122
|
+
useEstimateGas,
|
|
123
|
+
} from '../composables/useEstimateGas.js'
|
|
124
|
+
|
|
125
|
+
export {
|
|
126
|
+
type UseReadContractParameters,
|
|
127
|
+
type UseReadContractReturnType,
|
|
128
|
+
useReadContract,
|
|
129
|
+
} from '../composables/useReadContract.js'
|
|
130
|
+
|
|
95
131
|
export {
|
|
96
132
|
type UseReconnectParameters,
|
|
97
133
|
type UseReconnectReturnType,
|
|
98
134
|
useReconnect,
|
|
99
135
|
} from '../composables/useReconnect.js'
|
|
100
136
|
|
|
137
|
+
export {
|
|
138
|
+
type UseSendTransactionParameters,
|
|
139
|
+
type UseSendTransactionReturnType,
|
|
140
|
+
useSendTransaction,
|
|
141
|
+
} from '../composables/useSendTransaction.js'
|
|
142
|
+
|
|
143
|
+
export {
|
|
144
|
+
type UseSignMessageParameters,
|
|
145
|
+
type UseSignMessageReturnType,
|
|
146
|
+
useSignMessage,
|
|
147
|
+
} from '../composables/useSignMessage.js'
|
|
148
|
+
|
|
149
|
+
export {
|
|
150
|
+
type UseSignTypedDataParameters,
|
|
151
|
+
type UseSignTypedDataReturnType,
|
|
152
|
+
useSignTypedData,
|
|
153
|
+
} from '../composables/useSignTypedData.js'
|
|
154
|
+
|
|
155
|
+
export {
|
|
156
|
+
type UseSimulateContractParameters,
|
|
157
|
+
type UseSimulateContractReturnType,
|
|
158
|
+
useSimulateContract,
|
|
159
|
+
} from '../composables/useSimulateContract.js'
|
|
160
|
+
|
|
101
161
|
export {
|
|
102
162
|
type UseSwitchAccountParameters,
|
|
103
163
|
type UseSwitchAccountReturnType,
|
|
@@ -110,12 +170,36 @@ export {
|
|
|
110
170
|
useSwitchChain,
|
|
111
171
|
} from '../composables/useSwitchChain.js'
|
|
112
172
|
|
|
173
|
+
export {
|
|
174
|
+
type UseTransactionParameters,
|
|
175
|
+
type UseTransactionReturnType,
|
|
176
|
+
useTransaction,
|
|
177
|
+
} from '../composables/useTransaction.js'
|
|
178
|
+
|
|
179
|
+
export {
|
|
180
|
+
type UseTransactionReceiptParameters,
|
|
181
|
+
type UseTransactionReceiptReturnType,
|
|
182
|
+
useTransactionReceipt,
|
|
183
|
+
} from '../composables/useTransactionReceipt.js'
|
|
184
|
+
|
|
113
185
|
export {
|
|
114
186
|
type UseWatchBlockNumberParameters,
|
|
115
187
|
type UseWatchBlockNumberReturnType,
|
|
116
188
|
useWatchBlockNumber,
|
|
117
189
|
} from '../composables/useWatchBlockNumber.js'
|
|
118
190
|
|
|
191
|
+
export {
|
|
192
|
+
type UseWaitForTransactionReceiptParameters,
|
|
193
|
+
type UseWaitForTransactionReceiptReturnType,
|
|
194
|
+
useWaitForTransactionReceipt,
|
|
195
|
+
} from '../composables/useWaitForTransactionReceipt.js'
|
|
196
|
+
|
|
197
|
+
export {
|
|
198
|
+
type UseWriteContractParameters,
|
|
199
|
+
type UseWriteContractReturnType,
|
|
200
|
+
useWriteContract,
|
|
201
|
+
} from '../composables/useWriteContract.js'
|
|
202
|
+
|
|
119
203
|
////////////////////////////////////////////////////////////////////////////////
|
|
120
204
|
// @wagmi/core
|
|
121
205
|
////////////////////////////////////////////////////////////////////////////////
|
package/src/nuxt/module.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { fileURLToPath } from 'node:url'
|
|
2
1
|
import type { NuxtModule } from '@nuxt/schema'
|
|
3
|
-
import { defineNuxtModule } from 'nuxt/kit'
|
|
2
|
+
import { addImports, createResolver, defineNuxtModule } from 'nuxt/kit'
|
|
4
3
|
|
|
5
|
-
// TODO: createConfig parameters to options?
|
|
6
4
|
export type WagmiModuleOptions = {}
|
|
7
5
|
|
|
8
6
|
export const wagmiModule: NuxtModule<WagmiModuleOptions> =
|
|
@@ -15,11 +13,47 @@ export const wagmiModule: NuxtModule<WagmiModuleOptions> =
|
|
|
15
13
|
},
|
|
16
14
|
},
|
|
17
15
|
setup(_options, nuxt) {
|
|
18
|
-
|
|
19
|
-
const runtimeDir = fileURLToPath(new URL('./runtime', import.meta.url))
|
|
20
|
-
nuxt.options.build.transpile.push(runtimeDir)
|
|
16
|
+
const { resolve } = createResolver(import.meta.url)
|
|
21
17
|
|
|
22
|
-
//
|
|
23
|
-
|
|
18
|
+
// Add types
|
|
19
|
+
nuxt.hook('prepare:types', ({ references }) => {
|
|
20
|
+
references.push({ types: '@wagmi/vue/nuxt' })
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
// Add auto imports
|
|
24
|
+
const composables = resolve('./runtime/composables')
|
|
25
|
+
const names = [
|
|
26
|
+
'useAccount',
|
|
27
|
+
'useAccountEffect',
|
|
28
|
+
'useBalance',
|
|
29
|
+
'useBlockNumber',
|
|
30
|
+
'useChainId',
|
|
31
|
+
'useChains',
|
|
32
|
+
'useClient',
|
|
33
|
+
'useConfig',
|
|
34
|
+
'useConnect',
|
|
35
|
+
'useConnections',
|
|
36
|
+
'useConnectorClient',
|
|
37
|
+
'useConnectors',
|
|
38
|
+
'useDisconnect',
|
|
39
|
+
'useEnsAddress',
|
|
40
|
+
'useEnsAvatar',
|
|
41
|
+
'useEnsName',
|
|
42
|
+
'useEstimateGas',
|
|
43
|
+
'useReadContract',
|
|
44
|
+
'useReconnect',
|
|
45
|
+
'useSendTransaction',
|
|
46
|
+
'useSignMessage',
|
|
47
|
+
'useSignTypedData',
|
|
48
|
+
'useSimulateContract',
|
|
49
|
+
'useSwitchAccount',
|
|
50
|
+
'useSwitchChain',
|
|
51
|
+
'useTransaction',
|
|
52
|
+
'useTransactionReceipt',
|
|
53
|
+
'useWaitForTransactionReceipt',
|
|
54
|
+
'useWatchBlockNumber',
|
|
55
|
+
'useWriteContract',
|
|
56
|
+
]
|
|
57
|
+
addImports(names.map((name) => ({ from: composables, name })))
|
|
24
58
|
},
|
|
25
59
|
})
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../exports/index.js'
|
package/src/types/ref.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Credit: https://github.com/TanStack/query/blob/01ce023826b81e6c41e354f27691f65c9725af67/packages/vue-query/src/types.ts
|
|
2
2
|
|
|
3
|
-
import type { Config } from '@wagmi/core'
|
|
3
|
+
import type { Config, Connector } from '@wagmi/core'
|
|
4
4
|
import type { MaybeRef, Ref, UnwrapRef } from 'vue'
|
|
5
5
|
|
|
6
6
|
type Primitive = string | number | boolean | bigint | symbol | undefined | null
|
|
@@ -16,9 +16,9 @@ type UnwrapLeaf =
|
|
|
16
16
|
| WeakSet<any>
|
|
17
17
|
|
|
18
18
|
export type DeepMaybeRef<value> = MaybeRef<
|
|
19
|
-
value extends Function | Config
|
|
19
|
+
value extends Function | Config | Connector
|
|
20
20
|
? value
|
|
21
|
-
: value extends object
|
|
21
|
+
: value extends object | any[]
|
|
22
22
|
? {
|
|
23
23
|
[key in keyof value]: DeepMaybeRef<value[key]>
|
|
24
24
|
}
|