wagmi 1.4.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/context.js +16 -0
- package/dist/esm/context.js.map +1 -0
- package/dist/esm/errors/base.js +20 -0
- package/dist/esm/errors/base.js.map +1 -0
- package/dist/esm/errors/context.js +13 -0
- package/dist/esm/errors/context.js.map +1 -0
- package/dist/esm/exports/actions.js +4 -0
- package/dist/esm/exports/actions.js.map +1 -0
- package/dist/esm/exports/chains.js +4 -0
- package/dist/esm/exports/chains.js.map +1 -0
- package/dist/esm/exports/connectors.js +4 -0
- package/dist/esm/exports/connectors.js.map +1 -0
- package/dist/esm/exports/index.js +63 -0
- package/dist/esm/exports/index.js.map +1 -0
- package/dist/esm/exports/query.js +4 -0
- package/dist/esm/exports/query.js.map +1 -0
- package/dist/esm/hooks/useAccount.js +10 -0
- package/dist/esm/hooks/useAccount.js.map +1 -0
- package/dist/esm/hooks/useAccountEffect.js +29 -0
- package/dist/esm/hooks/useAccountEffect.js.map +1 -0
- package/dist/esm/hooks/useBalance.js +19 -0
- package/dist/esm/hooks/useBalance.js.map +1 -0
- package/dist/esm/hooks/useBlockNumber.js +37 -0
- package/dist/esm/hooks/useBlockNumber.js.map +1 -0
- package/dist/esm/hooks/useChainId.js +10 -0
- package/dist/esm/hooks/useChainId.js.map +1 -0
- package/dist/esm/hooks/useClient.js +10 -0
- package/dist/esm/hooks/useClient.js.map +1 -0
- package/dist/esm/hooks/useConfig.js +13 -0
- package/dist/esm/hooks/useConfig.js.map +1 -0
- package/dist/esm/hooks/useConnect.js +22 -0
- package/dist/esm/hooks/useConnect.js.map +1 -0
- package/dist/esm/hooks/useConnections.js +10 -0
- package/dist/esm/hooks/useConnections.js.map +1 -0
- package/dist/esm/hooks/useConnectorClient.js +40 -0
- package/dist/esm/hooks/useConnectorClient.js.map +1 -0
- package/dist/esm/hooks/useContractRead.js +26 -0
- package/dist/esm/hooks/useContractRead.js.map +1 -0
- package/dist/esm/hooks/useContractReads.js +38 -0
- package/dist/esm/hooks/useContractReads.js.map +1 -0
- package/dist/esm/hooks/useContractSimulate.js +24 -0
- package/dist/esm/hooks/useContractSimulate.js.map +1 -0
- package/dist/esm/hooks/useContractWrite.js +20 -0
- package/dist/esm/hooks/useContractWrite.js.map +1 -0
- package/dist/esm/hooks/useDisconnect.js +23 -0
- package/dist/esm/hooks/useDisconnect.js.map +1 -0
- package/dist/esm/hooks/useEnsAddress.js +19 -0
- package/dist/esm/hooks/useEnsAddress.js.map +1 -0
- package/dist/esm/hooks/useEnsAvatar.js +19 -0
- package/dist/esm/hooks/useEnsAvatar.js.map +1 -0
- package/dist/esm/hooks/useEnsName.js +19 -0
- package/dist/esm/hooks/useEnsName.js.map +1 -0
- package/dist/esm/hooks/useEnsResolver.js +19 -0
- package/dist/esm/hooks/useEnsResolver.js.map +1 -0
- package/dist/esm/hooks/useEstimateFeesPerGas.js +19 -0
- package/dist/esm/hooks/useEstimateFeesPerGas.js.map +1 -0
- package/dist/esm/hooks/useEstimateGas.js +25 -0
- package/dist/esm/hooks/useEstimateGas.js.map +1 -0
- package/dist/esm/hooks/usePublicClient.js +10 -0
- package/dist/esm/hooks/usePublicClient.js.map +1 -0
- package/dist/esm/hooks/useReconnect.js +22 -0
- package/dist/esm/hooks/useReconnect.js.map +1 -0
- package/dist/esm/hooks/useSendTransaction.js +20 -0
- package/dist/esm/hooks/useSendTransaction.js.map +1 -0
- package/dist/esm/hooks/useSignMessage.js +21 -0
- package/dist/esm/hooks/useSignMessage.js.map +1 -0
- package/dist/esm/hooks/useSignTypedData.js +20 -0
- package/dist/esm/hooks/useSignTypedData.js.map +1 -0
- package/dist/esm/hooks/useSwitchAccount.js +22 -0
- package/dist/esm/hooks/useSwitchAccount.js.map +1 -0
- package/dist/esm/hooks/useSwitchChain.js +21 -0
- package/dist/esm/hooks/useSwitchChain.js.map +1 -0
- package/dist/esm/hooks/useSyncExternalStoreWithTracked.js +40 -0
- package/dist/esm/hooks/useSyncExternalStoreWithTracked.js.map +1 -0
- package/dist/esm/hooks/useToken.js +19 -0
- package/dist/esm/hooks/useToken.js.map +1 -0
- package/dist/esm/hooks/useTransaction.js +19 -0
- package/dist/esm/hooks/useTransaction.js.map +1 -0
- package/dist/esm/hooks/useWaitForTransactionReceipt.js +19 -0
- package/dist/esm/hooks/useWaitForTransactionReceipt.js.map +1 -0
- package/dist/esm/hooks/useWalletClient.js +42 -0
- package/dist/esm/hooks/useWalletClient.js.map +1 -0
- package/dist/esm/hooks/useWatchBlockNumber.js +25 -0
- package/dist/esm/hooks/useWatchBlockNumber.js.map +1 -0
- package/dist/esm/hooks/useWatchContractEvent.js +25 -0
- package/dist/esm/hooks/useWatchContractEvent.js.map +1 -0
- package/dist/esm/hooks/useWatchPendingTransactions.js +25 -0
- package/dist/esm/hooks/useWatchPendingTransactions.js.map +1 -0
- package/dist/esm/tsconfig.build.tsbuildinfo +1 -0
- package/dist/esm/types/properties.js +2 -0
- package/dist/esm/types/properties.js.map +1 -0
- package/dist/esm/utils/getVersion.js +3 -0
- package/dist/esm/utils/getVersion.js.map +1 -0
- package/dist/esm/utils/query.js +21 -0
- package/dist/esm/utils/query.js.map +1 -0
- package/dist/esm/version.js +2 -0
- package/dist/esm/version.js.map +1 -0
- package/dist/types/context.d.ts +11 -0
- package/dist/types/context.d.ts.map +1 -0
- package/dist/types/errors/base.d.ts +7 -0
- package/dist/types/errors/base.d.ts.map +1 -0
- package/dist/types/errors/context.d.ts +6 -0
- package/dist/types/errors/context.d.ts.map +1 -0
- package/dist/types/exports/actions.d.ts +2 -0
- package/dist/types/exports/actions.d.ts.map +1 -0
- package/dist/types/exports/chains.d.ts +2 -0
- package/dist/types/exports/chains.d.ts.map +1 -0
- package/dist/types/exports/connectors.d.ts +2 -0
- package/dist/types/exports/connectors.d.ts.map +1 -0
- package/dist/types/exports/index.d.ts +46 -0
- package/dist/types/exports/index.d.ts.map +1 -0
- package/dist/types/exports/query.d.ts +2 -0
- package/dist/types/exports/query.d.ts.map +1 -0
- package/dist/types/hooks/useAccount.d.ts +7 -0
- package/dist/types/hooks/useAccount.d.ts.map +1 -0
- package/dist/types/hooks/useAccountEffect.d.ts +14 -0
- package/dist/types/hooks/useAccountEffect.d.ts.map +1 -0
- package/dist/types/hooks/useBalance.d.ts +13 -0
- package/dist/types/hooks/useBalance.d.ts.map +1 -0
- package/dist/types/hooks/useBlockNumber.d.ts +14 -0
- package/dist/types/hooks/useBlockNumber.d.ts.map +1 -0
- package/dist/types/hooks/useChainId.d.ts +7 -0
- package/dist/types/hooks/useChainId.d.ts.map +1 -0
- package/dist/types/hooks/useClient.d.ts +8 -0
- package/dist/types/hooks/useClient.d.ts.map +1 -0
- package/dist/types/hooks/useConfig.d.ts +7 -0
- package/dist/types/hooks/useConfig.d.ts.map +1 -0
- package/dist/types/hooks/useConnect.d.ts +16 -0
- package/dist/types/hooks/useConnect.d.ts.map +1 -0
- package/dist/types/hooks/useConnections.d.ts +7 -0
- package/dist/types/hooks/useConnections.d.ts.map +1 -0
- package/dist/types/hooks/useConnectorClient.d.ts +12 -0
- package/dist/types/hooks/useConnectorClient.d.ts.map +1 -0
- package/dist/types/hooks/useContractRead.d.ts +13 -0
- package/dist/types/hooks/useContractRead.d.ts.map +1 -0
- package/dist/types/hooks/useContractReads.d.ts +13 -0
- package/dist/types/hooks/useContractReads.d.ts.map +1 -0
- package/dist/types/hooks/useContractSimulate.d.ts +12 -0
- package/dist/types/hooks/useContractSimulate.d.ts.map +1 -0
- package/dist/types/hooks/useContractWrite.d.ts +15 -0
- package/dist/types/hooks/useContractWrite.d.ts.map +1 -0
- package/dist/types/hooks/useDisconnect.d.ts +16 -0
- package/dist/types/hooks/useDisconnect.d.ts.map +1 -0
- package/dist/types/hooks/useEnsAddress.d.ts +12 -0
- package/dist/types/hooks/useEnsAddress.d.ts.map +1 -0
- package/dist/types/hooks/useEnsAvatar.d.ts +12 -0
- package/dist/types/hooks/useEnsAvatar.d.ts.map +1 -0
- package/dist/types/hooks/useEnsName.d.ts +12 -0
- package/dist/types/hooks/useEnsName.d.ts.map +1 -0
- package/dist/types/hooks/useEnsResolver.d.ts +12 -0
- package/dist/types/hooks/useEnsResolver.d.ts.map +1 -0
- package/dist/types/hooks/useEstimateFeesPerGas.d.ts +13 -0
- package/dist/types/hooks/useEstimateFeesPerGas.d.ts.map +1 -0
- package/dist/types/hooks/useEstimateGas.d.ts +11 -0
- package/dist/types/hooks/useEstimateGas.d.ts.map +1 -0
- package/dist/types/hooks/usePublicClient.d.ts +8 -0
- package/dist/types/hooks/usePublicClient.d.ts.map +1 -0
- package/dist/types/hooks/useReconnect.d.ts +16 -0
- package/dist/types/hooks/useReconnect.d.ts.map +1 -0
- package/dist/types/hooks/useSendTransaction.d.ts +15 -0
- package/dist/types/hooks/useSendTransaction.d.ts.map +1 -0
- package/dist/types/hooks/useSignMessage.d.ts +15 -0
- package/dist/types/hooks/useSignMessage.d.ts.map +1 -0
- package/dist/types/hooks/useSignTypedData.d.ts +15 -0
- package/dist/types/hooks/useSignTypedData.d.ts.map +1 -0
- package/dist/types/hooks/useSwitchAccount.d.ts +16 -0
- package/dist/types/hooks/useSwitchAccount.d.ts.map +1 -0
- package/dist/types/hooks/useSwitchChain.d.ts +16 -0
- package/dist/types/hooks/useSwitchChain.d.ts.map +1 -0
- package/dist/types/hooks/useSyncExternalStoreWithTracked.d.ts +2 -0
- package/dist/types/hooks/useSyncExternalStoreWithTracked.d.ts.map +1 -0
- package/dist/types/hooks/useToken.d.ts +12 -0
- package/dist/types/hooks/useToken.d.ts.map +1 -0
- package/dist/types/hooks/useTransaction.d.ts +12 -0
- package/dist/types/hooks/useTransaction.d.ts.map +1 -0
- package/dist/types/hooks/useWaitForTransactionReceipt.d.ts +12 -0
- package/dist/types/hooks/useWaitForTransactionReceipt.d.ts.map +1 -0
- package/dist/types/hooks/useWalletClient.d.ts +12 -0
- package/dist/types/hooks/useWalletClient.d.ts.map +1 -0
- package/dist/types/hooks/useWatchBlockNumber.d.ts +8 -0
- package/dist/types/hooks/useWatchBlockNumber.d.ts.map +1 -0
- package/dist/types/hooks/useWatchContractEvent.d.ts +9 -0
- package/dist/types/hooks/useWatchContractEvent.d.ts.map +1 -0
- package/dist/types/hooks/useWatchPendingTransactions.d.ts +8 -0
- package/dist/types/hooks/useWatchPendingTransactions.d.ts.map +1 -0
- package/dist/types/types/properties.d.ts +8 -0
- package/dist/types/types/properties.d.ts.map +1 -0
- package/dist/types/utils/getVersion.d.ts +2 -0
- package/dist/types/utils/getVersion.d.ts.map +1 -0
- package/dist/types/utils/query.d.ts +15 -0
- package/dist/types/utils/query.d.ts.map +1 -0
- package/dist/types/version.d.ts +2 -0
- package/dist/types/version.d.ts.map +1 -0
- package/package.json +65 -103
- package/src/context.ts +27 -0
- package/src/errors/base.ts +13 -0
- package/src/errors/context.ts +8 -0
- package/src/exports/actions.ts +4 -0
- package/src/exports/chains.ts +4 -0
- package/src/exports/connectors.ts +4 -0
- package/src/exports/index.ts +284 -0
- package/src/exports/query.ts +4 -0
- package/src/hooks/useAccount.ts +27 -0
- package/src/hooks/useAccountEffect.ts +55 -0
- package/src/hooks/useBalance.ts +65 -0
- package/src/hooks/useBlockNumber.ts +97 -0
- package/src/hooks/useChainId.ts +31 -0
- package/src/hooks/useClient.ts +43 -0
- package/src/hooks/useConfig.ts +22 -0
- package/src/hooks/useConnect.ts +80 -0
- package/src/hooks/useConnections.ts +27 -0
- package/src/hooks/useConnectorClient.ts +95 -0
- package/src/hooks/useContractRead.ts +107 -0
- package/src/hooks/useContractReads.ts +98 -0
- package/src/hooks/useContractSimulate.ts +117 -0
- package/src/hooks/useContractWrite.ts +83 -0
- package/src/hooks/useDisconnect.ts +68 -0
- package/src/hooks/useEnsAddress.ts +61 -0
- package/src/hooks/useEnsAvatar.ts +59 -0
- package/src/hooks/useEnsName.ts +61 -0
- package/src/hooks/useEnsResolver.ts +61 -0
- package/src/hooks/useEstimateFeesPerGas.ts +69 -0
- package/src/hooks/useEstimateGas.ts +72 -0
- package/src/hooks/usePublicClient.ts +45 -0
- package/src/hooks/useReconnect.ts +67 -0
- package/src/hooks/useSendTransaction.ts +79 -0
- package/src/hooks/useSignMessage.ts +65 -0
- package/src/hooks/useSignTypedData.ts +66 -0
- package/src/hooks/useSwitchAccount.ts +82 -0
- package/src/hooks/useSwitchChain.ts +77 -0
- package/src/hooks/useSyncExternalStoreWithTracked.ts +67 -0
- package/src/hooks/useToken.ts +63 -0
- package/src/hooks/useTransaction.ts +68 -0
- package/src/hooks/useWaitForTransactionReceipt.ts +74 -0
- package/src/hooks/useWalletClient.ts +96 -0
- package/src/hooks/useWatchBlockNumber.ts +49 -0
- package/src/hooks/useWatchContractEvent.ts +64 -0
- package/src/hooks/useWatchPendingTransactions.ts +52 -0
- package/src/types/properties.ts +9 -0
- package/src/utils/getVersion.ts +3 -0
- package/src/utils/query.ts +102 -0
- package/src/version.ts +1 -0
- package/README.md +0 -30
- package/actions/package.json +0 -4
- package/chains/package.json +0 -4
- package/connectors/coinbaseWallet/package.json +0 -4
- package/connectors/injected/package.json +0 -4
- package/connectors/ledger/package.json +0 -4
- package/connectors/metaMask/package.json +0 -4
- package/connectors/mock/package.json +0 -4
- package/connectors/package.json +0 -4
- package/connectors/safe/package.json +0 -4
- package/connectors/walletConnect/package.json +0 -4
- package/connectors/walletConnectLegacy/package.json +0 -4
- package/dist/actions.d.ts +0 -1
- package/dist/actions.js +0 -85
- package/dist/chains.d.ts +0 -2
- package/dist/chains.js +0 -4
- package/dist/connectors/coinbaseWallet.d.ts +0 -1
- package/dist/connectors/coinbaseWallet.js +0 -7
- package/dist/connectors/index.d.ts +0 -1
- package/dist/connectors/index.js +0 -7
- package/dist/connectors/injected.d.ts +0 -1
- package/dist/connectors/injected.js +0 -7
- package/dist/connectors/ledger.d.ts +0 -1
- package/dist/connectors/ledger.js +0 -7
- package/dist/connectors/metaMask.d.ts +0 -1
- package/dist/connectors/metaMask.js +0 -7
- package/dist/connectors/mock.d.ts +0 -1
- package/dist/connectors/mock.js +0 -7
- package/dist/connectors/safe.d.ts +0 -1
- package/dist/connectors/safe.js +0 -7
- package/dist/connectors/walletConnect.d.ts +0 -1
- package/dist/connectors/walletConnect.js +0 -7
- package/dist/connectors/walletConnectLegacy.d.ts +0 -1
- package/dist/connectors/walletConnectLegacy.js +0 -7
- package/dist/index.d.ts +0 -958
- package/dist/index.js +0 -2564
- package/dist/providers/alchemy.d.ts +0 -1
- package/dist/providers/alchemy.js +0 -7
- package/dist/providers/infura.d.ts +0 -1
- package/dist/providers/infura.js +0 -7
- package/dist/providers/jsonRpc.d.ts +0 -1
- package/dist/providers/jsonRpc.js +0 -7
- package/dist/providers/public.d.ts +0 -1
- package/dist/providers/public.js +0 -7
- package/dist/window.d.ts +0 -76
- package/dist/window.js +0 -1
- package/providers/alchemy/package.json +0 -4
- package/providers/infura/package.json +0 -4
- package/providers/jsonRpc/package.json +0 -4
- package/providers/public/package.json +0 -4
- package/window/package.json +0 -4
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
Config,
|
|
5
|
+
ResolvedRegister,
|
|
6
|
+
SimulateContractError,
|
|
7
|
+
} from '@wagmi/core'
|
|
8
|
+
import {
|
|
9
|
+
type SimulateContractData,
|
|
10
|
+
type SimulateContractOptions,
|
|
11
|
+
type SimulateContractQueryFnData,
|
|
12
|
+
type SimulateContractQueryKey,
|
|
13
|
+
simulateContractQueryOptions,
|
|
14
|
+
} from '@wagmi/core/query'
|
|
15
|
+
import type { Abi, ContractFunctionArgs, ContractFunctionName } from 'viem'
|
|
16
|
+
|
|
17
|
+
import type { ConfigParameter } from '../types/properties.js'
|
|
18
|
+
import {
|
|
19
|
+
type UseQueryParameters,
|
|
20
|
+
type UseQueryReturnType,
|
|
21
|
+
useQuery,
|
|
22
|
+
} 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 UseContractSimulateParameters<
|
|
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
|
+
> = SimulateContractOptions<abi, functionName, args, config, chainId> &
|
|
42
|
+
ConfigParameter<config> & {
|
|
43
|
+
query?:
|
|
44
|
+
| UseQueryParameters<
|
|
45
|
+
SimulateContractQueryFnData<abi, functionName, args, config, chainId>,
|
|
46
|
+
SimulateContractError,
|
|
47
|
+
selectData,
|
|
48
|
+
SimulateContractQueryKey<abi, functionName, args, config, chainId>
|
|
49
|
+
>
|
|
50
|
+
| undefined
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type UseContractSimulateReturnType<
|
|
54
|
+
abi extends Abi | readonly unknown[] = Abi,
|
|
55
|
+
functionName extends ContractFunctionName<
|
|
56
|
+
abi,
|
|
57
|
+
'nonpayable' | 'payable'
|
|
58
|
+
> = ContractFunctionName<abi, 'nonpayable' | 'payable'>,
|
|
59
|
+
args extends ContractFunctionArgs<
|
|
60
|
+
abi,
|
|
61
|
+
'nonpayable' | 'payable',
|
|
62
|
+
functionName
|
|
63
|
+
> = ContractFunctionArgs<abi, 'nonpayable' | 'payable', functionName>,
|
|
64
|
+
config extends Config = Config,
|
|
65
|
+
chainId extends config['chains'][number]['id'] | undefined = undefined,
|
|
66
|
+
selectData = SimulateContractData<abi, functionName, args, config, chainId>,
|
|
67
|
+
> = UseQueryReturnType<selectData, SimulateContractError>
|
|
68
|
+
|
|
69
|
+
/** https://alpha.wagmi.sh/react/api/hooks/useContractSimulate */
|
|
70
|
+
export function useContractSimulate<
|
|
71
|
+
const abi extends Abi | readonly unknown[],
|
|
72
|
+
functionName extends ContractFunctionName<abi, 'nonpayable' | 'payable'>,
|
|
73
|
+
args extends ContractFunctionArgs<
|
|
74
|
+
abi,
|
|
75
|
+
'nonpayable' | 'payable',
|
|
76
|
+
functionName
|
|
77
|
+
>,
|
|
78
|
+
config extends Config = ResolvedRegister['config'],
|
|
79
|
+
chainId extends config['chains'][number]['id'] | undefined = undefined,
|
|
80
|
+
selectData = SimulateContractData<abi, functionName, args, config, chainId>,
|
|
81
|
+
>(
|
|
82
|
+
parameters: UseContractSimulateParameters<
|
|
83
|
+
abi,
|
|
84
|
+
functionName,
|
|
85
|
+
args,
|
|
86
|
+
config,
|
|
87
|
+
chainId,
|
|
88
|
+
selectData
|
|
89
|
+
> = {} as any,
|
|
90
|
+
): UseContractSimulateReturnType<
|
|
91
|
+
abi,
|
|
92
|
+
functionName,
|
|
93
|
+
args,
|
|
94
|
+
config,
|
|
95
|
+
chainId,
|
|
96
|
+
selectData
|
|
97
|
+
> {
|
|
98
|
+
const { abi, address, connector, functionName, query = {} } = parameters
|
|
99
|
+
|
|
100
|
+
const config = useConfig(parameters)
|
|
101
|
+
const { data: connectorClient } = useConnectorClient({
|
|
102
|
+
connector,
|
|
103
|
+
query: { enabled: parameters.account === undefined },
|
|
104
|
+
})
|
|
105
|
+
const chainId = useChainId()
|
|
106
|
+
|
|
107
|
+
const queryOptions = simulateContractQueryOptions(config, {
|
|
108
|
+
...(parameters as any),
|
|
109
|
+
account: parameters.account ?? connectorClient?.account,
|
|
110
|
+
chainId: parameters.chainId ?? chainId,
|
|
111
|
+
})
|
|
112
|
+
const enabled = Boolean(
|
|
113
|
+
abi && address && functionName && (query.enabled ?? true),
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
return useQuery({ ...queryOptions, ...query, enabled })
|
|
117
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useMutation } from '@tanstack/react-query'
|
|
4
|
+
import type { Config, ResolvedRegister, WriteContractError } from '@wagmi/core'
|
|
5
|
+
import {
|
|
6
|
+
type WriteContractData,
|
|
7
|
+
type WriteContractMutate,
|
|
8
|
+
type WriteContractMutateAsync,
|
|
9
|
+
type WriteContractVariables,
|
|
10
|
+
writeContractMutationOptions,
|
|
11
|
+
} from '@wagmi/core/query'
|
|
12
|
+
import type { Abi } from 'viem'
|
|
13
|
+
|
|
14
|
+
import type { ConfigParameter } from '../types/properties.js'
|
|
15
|
+
import type {
|
|
16
|
+
UseMutationParameters,
|
|
17
|
+
UseMutationReturnType,
|
|
18
|
+
} from '../utils/query.js'
|
|
19
|
+
import { useConfig } from './useConfig.js'
|
|
20
|
+
|
|
21
|
+
export type UseContractWriteParameters<
|
|
22
|
+
config extends Config = Config,
|
|
23
|
+
context = unknown,
|
|
24
|
+
> = ConfigParameter<config> & {
|
|
25
|
+
mutation?:
|
|
26
|
+
| UseMutationParameters<
|
|
27
|
+
WriteContractData,
|
|
28
|
+
WriteContractError,
|
|
29
|
+
WriteContractVariables<
|
|
30
|
+
Abi,
|
|
31
|
+
string,
|
|
32
|
+
readonly unknown[],
|
|
33
|
+
config,
|
|
34
|
+
config['chains'][number]['id']
|
|
35
|
+
>,
|
|
36
|
+
context
|
|
37
|
+
>
|
|
38
|
+
| undefined
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type UseContractWriteReturnType<
|
|
42
|
+
config extends Config = Config,
|
|
43
|
+
context = unknown,
|
|
44
|
+
> = UseMutationReturnType<
|
|
45
|
+
WriteContractData,
|
|
46
|
+
WriteContractError,
|
|
47
|
+
WriteContractVariables<
|
|
48
|
+
Abi,
|
|
49
|
+
string,
|
|
50
|
+
readonly unknown[],
|
|
51
|
+
config,
|
|
52
|
+
config['chains'][number]['id']
|
|
53
|
+
>,
|
|
54
|
+
context
|
|
55
|
+
> & {
|
|
56
|
+
write: WriteContractMutate<config, context>
|
|
57
|
+
writeAsync: WriteContractMutateAsync<config, context>
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** https://alpha.wagmi.sh/react/api/hooks/useContractWrite */
|
|
61
|
+
export function useContractWrite<
|
|
62
|
+
config extends Config = ResolvedRegister['config'],
|
|
63
|
+
context = unknown,
|
|
64
|
+
>(
|
|
65
|
+
parameters: UseContractWriteParameters<config, context> = {},
|
|
66
|
+
): UseContractWriteReturnType<config, context> {
|
|
67
|
+
const { mutation } = parameters
|
|
68
|
+
|
|
69
|
+
const config = useConfig(parameters)
|
|
70
|
+
|
|
71
|
+
const mutationOptions = writeContractMutationOptions(config)
|
|
72
|
+
const { mutate, mutateAsync, ...result } = useMutation({
|
|
73
|
+
...mutation,
|
|
74
|
+
...mutationOptions,
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
type Return = UseContractWriteReturnType<config, context>
|
|
78
|
+
return {
|
|
79
|
+
...result,
|
|
80
|
+
write: mutate as Return['write'],
|
|
81
|
+
writeAsync: mutateAsync as Return['writeAsync'],
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useMutation } from '@tanstack/react-query'
|
|
4
|
+
import { type Connector, type DisconnectError } from '@wagmi/core'
|
|
5
|
+
import type { Evaluate } from '@wagmi/core/internal'
|
|
6
|
+
import {
|
|
7
|
+
type DisconnectData,
|
|
8
|
+
type DisconnectMutate,
|
|
9
|
+
type DisconnectMutateAsync,
|
|
10
|
+
type DisconnectVariables,
|
|
11
|
+
disconnectMutationOptions,
|
|
12
|
+
} from '@wagmi/core/query'
|
|
13
|
+
|
|
14
|
+
import type { ConfigParameter } from '../types/properties.js'
|
|
15
|
+
import type {
|
|
16
|
+
UseMutationParameters,
|
|
17
|
+
UseMutationReturnType,
|
|
18
|
+
} from '../utils/query.js'
|
|
19
|
+
import { useConfig } from './useConfig.js'
|
|
20
|
+
import { useConnections } from './useConnections.js'
|
|
21
|
+
|
|
22
|
+
export type UseDisconnectParameters<context = unknown> = Evaluate<
|
|
23
|
+
ConfigParameter & {
|
|
24
|
+
mutation?:
|
|
25
|
+
| UseMutationParameters<
|
|
26
|
+
DisconnectData,
|
|
27
|
+
DisconnectError,
|
|
28
|
+
DisconnectVariables,
|
|
29
|
+
context
|
|
30
|
+
>
|
|
31
|
+
| undefined
|
|
32
|
+
}
|
|
33
|
+
>
|
|
34
|
+
|
|
35
|
+
export type UseDisconnectReturnType<context = unknown> = Evaluate<
|
|
36
|
+
UseMutationReturnType<
|
|
37
|
+
DisconnectData,
|
|
38
|
+
DisconnectError,
|
|
39
|
+
DisconnectVariables,
|
|
40
|
+
context
|
|
41
|
+
> & {
|
|
42
|
+
connectors: readonly Connector[]
|
|
43
|
+
disconnect: DisconnectMutate<context>
|
|
44
|
+
disconnectAsync: DisconnectMutateAsync<context>
|
|
45
|
+
}
|
|
46
|
+
>
|
|
47
|
+
|
|
48
|
+
/** https://alpha.wagmi.sh/react/api/hooks/useDisconnect */
|
|
49
|
+
export function useDisconnect<context = unknown>(
|
|
50
|
+
parameters: UseDisconnectParameters<context> = {},
|
|
51
|
+
): UseDisconnectReturnType<context> {
|
|
52
|
+
const { mutation } = parameters
|
|
53
|
+
|
|
54
|
+
const config = useConfig(parameters)
|
|
55
|
+
|
|
56
|
+
const mutationOptions = disconnectMutationOptions(config)
|
|
57
|
+
const { mutate, mutateAsync, ...result } = useMutation({
|
|
58
|
+
...mutation,
|
|
59
|
+
...mutationOptions,
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
...result,
|
|
64
|
+
connectors: useConnections().map((connection) => connection.connector),
|
|
65
|
+
disconnect: mutate,
|
|
66
|
+
disconnectAsync: mutateAsync,
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import type { Config, GetEnsAddressError, ResolvedRegister } from '@wagmi/core'
|
|
4
|
+
import { type Evaluate } from '@wagmi/core/internal'
|
|
5
|
+
import {
|
|
6
|
+
type GetEnsAddressData,
|
|
7
|
+
type GetEnsAddressOptions,
|
|
8
|
+
type GetEnsAddressQueryFnData,
|
|
9
|
+
type GetEnsAddressQueryKey,
|
|
10
|
+
getEnsAddressQueryOptions,
|
|
11
|
+
} from '@wagmi/core/query'
|
|
12
|
+
|
|
13
|
+
import type { ConfigParameter } from '../types/properties.js'
|
|
14
|
+
import {
|
|
15
|
+
type UseQueryParameters,
|
|
16
|
+
type UseQueryReturnType,
|
|
17
|
+
useQuery,
|
|
18
|
+
} from '../utils/query.js'
|
|
19
|
+
import { useChainId } from './useChainId.js'
|
|
20
|
+
import { useConfig } from './useConfig.js'
|
|
21
|
+
|
|
22
|
+
export type UseEnsAddressParameters<
|
|
23
|
+
config extends Config = Config,
|
|
24
|
+
selectData = GetEnsAddressData,
|
|
25
|
+
> = Evaluate<
|
|
26
|
+
GetEnsAddressOptions<config> &
|
|
27
|
+
ConfigParameter<config> & {
|
|
28
|
+
query?:
|
|
29
|
+
| UseQueryParameters<
|
|
30
|
+
GetEnsAddressQueryFnData,
|
|
31
|
+
GetEnsAddressError,
|
|
32
|
+
selectData,
|
|
33
|
+
GetEnsAddressQueryKey<config>
|
|
34
|
+
>
|
|
35
|
+
| undefined
|
|
36
|
+
}
|
|
37
|
+
>
|
|
38
|
+
|
|
39
|
+
export type UseEnsAddressReturnType<selectData = GetEnsAddressData> =
|
|
40
|
+
UseQueryReturnType<selectData, GetEnsAddressError>
|
|
41
|
+
|
|
42
|
+
/** https://alpha.wagmi.sh/react/api/hooks/useEnsAddress */
|
|
43
|
+
export function useEnsAddress<
|
|
44
|
+
config extends Config = ResolvedRegister['config'],
|
|
45
|
+
selectData = GetEnsAddressData,
|
|
46
|
+
>(
|
|
47
|
+
parameters: UseEnsAddressParameters<config, selectData> = {},
|
|
48
|
+
): UseEnsAddressReturnType<selectData> {
|
|
49
|
+
const { name, query = {} } = parameters
|
|
50
|
+
|
|
51
|
+
const config = useConfig(parameters)
|
|
52
|
+
const chainId = useChainId()
|
|
53
|
+
|
|
54
|
+
const queryOptions = getEnsAddressQueryOptions(config, {
|
|
55
|
+
...parameters,
|
|
56
|
+
chainId: parameters.chainId ?? chainId,
|
|
57
|
+
})
|
|
58
|
+
const enabled = Boolean(name && (query.enabled ?? true))
|
|
59
|
+
|
|
60
|
+
return useQuery({ ...queryOptions, ...query, enabled })
|
|
61
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import type { Config, GetEnsAvatarError, ResolvedRegister } from '@wagmi/core'
|
|
4
|
+
import { type Evaluate } from '@wagmi/core/internal'
|
|
5
|
+
import {
|
|
6
|
+
type GetEnsAvatarData,
|
|
7
|
+
type GetEnsAvatarOptions,
|
|
8
|
+
type GetEnsAvatarQueryFnData,
|
|
9
|
+
type GetEnsAvatarQueryKey,
|
|
10
|
+
getEnsAvatarQueryOptions,
|
|
11
|
+
} from '@wagmi/core/query'
|
|
12
|
+
|
|
13
|
+
import type { ConfigParameter } from '../types/properties.js'
|
|
14
|
+
import {
|
|
15
|
+
type UseQueryParameters,
|
|
16
|
+
type UseQueryReturnType,
|
|
17
|
+
useQuery,
|
|
18
|
+
} from '../utils/query.js'
|
|
19
|
+
import { useChainId } from './useChainId.js'
|
|
20
|
+
import { useConfig } from './useConfig.js'
|
|
21
|
+
|
|
22
|
+
export type UseEnsAvatarParameters<
|
|
23
|
+
config extends Config = Config,
|
|
24
|
+
selectData = GetEnsAvatarData,
|
|
25
|
+
> = Evaluate<
|
|
26
|
+
GetEnsAvatarOptions<config> &
|
|
27
|
+
ConfigParameter<config> & {
|
|
28
|
+
query?: UseQueryParameters<
|
|
29
|
+
GetEnsAvatarQueryFnData,
|
|
30
|
+
GetEnsAvatarError,
|
|
31
|
+
selectData,
|
|
32
|
+
GetEnsAvatarQueryKey<config>
|
|
33
|
+
>
|
|
34
|
+
}
|
|
35
|
+
>
|
|
36
|
+
|
|
37
|
+
export type UseEnsAvatarReturnType<selectData = GetEnsAvatarData> =
|
|
38
|
+
UseQueryReturnType<selectData, GetEnsAvatarError>
|
|
39
|
+
|
|
40
|
+
/** https://alpha.wagmi.sh/react/api/hooks/useEnsAvatar */
|
|
41
|
+
export function useEnsAvatar<
|
|
42
|
+
config extends Config = ResolvedRegister['config'],
|
|
43
|
+
selectData = GetEnsAvatarData,
|
|
44
|
+
>(
|
|
45
|
+
parameters: UseEnsAvatarParameters<config, selectData> = {},
|
|
46
|
+
): UseEnsAvatarReturnType<selectData> {
|
|
47
|
+
const { name, query = {} } = parameters
|
|
48
|
+
|
|
49
|
+
const config = useConfig(parameters)
|
|
50
|
+
const chainId = useChainId()
|
|
51
|
+
|
|
52
|
+
const queryOptions = getEnsAvatarQueryOptions(config, {
|
|
53
|
+
...parameters,
|
|
54
|
+
chainId: parameters.chainId ?? chainId,
|
|
55
|
+
})
|
|
56
|
+
const enabled = Boolean(name && (query.enabled ?? true))
|
|
57
|
+
|
|
58
|
+
return useQuery({ ...queryOptions, ...query, enabled })
|
|
59
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import type { Config, GetEnsNameError, ResolvedRegister } from '@wagmi/core'
|
|
4
|
+
import { type Evaluate } from '@wagmi/core/internal'
|
|
5
|
+
import {
|
|
6
|
+
type GetEnsNameData,
|
|
7
|
+
type GetEnsNameOptions,
|
|
8
|
+
type GetEnsNameQueryFnData,
|
|
9
|
+
type GetEnsNameQueryKey,
|
|
10
|
+
getEnsNameQueryOptions,
|
|
11
|
+
} from '@wagmi/core/query'
|
|
12
|
+
|
|
13
|
+
import type { ConfigParameter } from '../types/properties.js'
|
|
14
|
+
import {
|
|
15
|
+
type UseQueryParameters,
|
|
16
|
+
type UseQueryReturnType,
|
|
17
|
+
useQuery,
|
|
18
|
+
} from '../utils/query.js'
|
|
19
|
+
import { useChainId } from './useChainId.js'
|
|
20
|
+
import { useConfig } from './useConfig.js'
|
|
21
|
+
|
|
22
|
+
export type UseEnsNameParameters<
|
|
23
|
+
config extends Config = Config,
|
|
24
|
+
selectData = GetEnsNameData,
|
|
25
|
+
> = Evaluate<
|
|
26
|
+
GetEnsNameOptions<config> &
|
|
27
|
+
ConfigParameter<config> & {
|
|
28
|
+
query?:
|
|
29
|
+
| UseQueryParameters<
|
|
30
|
+
GetEnsNameQueryFnData,
|
|
31
|
+
GetEnsNameError,
|
|
32
|
+
selectData,
|
|
33
|
+
GetEnsNameQueryKey<config>
|
|
34
|
+
>
|
|
35
|
+
| undefined
|
|
36
|
+
}
|
|
37
|
+
>
|
|
38
|
+
|
|
39
|
+
export type UseEnsNameReturnType<selectData = GetEnsNameData> =
|
|
40
|
+
UseQueryReturnType<selectData, GetEnsNameError>
|
|
41
|
+
|
|
42
|
+
/** https://alpha.wagmi.sh/react/api/hooks/useEnsName */
|
|
43
|
+
export function useEnsName<
|
|
44
|
+
config extends Config = ResolvedRegister['config'],
|
|
45
|
+
selectData = GetEnsNameData,
|
|
46
|
+
>(
|
|
47
|
+
parameters: UseEnsNameParameters<config, selectData> = {},
|
|
48
|
+
): UseEnsNameReturnType<selectData> {
|
|
49
|
+
const { address, query = {} } = parameters
|
|
50
|
+
|
|
51
|
+
const config = useConfig(parameters)
|
|
52
|
+
const chainId = useChainId()
|
|
53
|
+
|
|
54
|
+
const queryOptions = getEnsNameQueryOptions(config, {
|
|
55
|
+
...parameters,
|
|
56
|
+
chainId: parameters.chainId ?? chainId,
|
|
57
|
+
})
|
|
58
|
+
const enabled = Boolean(address && (query.enabled ?? true))
|
|
59
|
+
|
|
60
|
+
return useQuery({ ...queryOptions, ...query, enabled })
|
|
61
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import type { Config, GetEnsResolverError, ResolvedRegister } from '@wagmi/core'
|
|
4
|
+
import { type Evaluate } from '@wagmi/core/internal'
|
|
5
|
+
import {
|
|
6
|
+
type GetEnsResolverData,
|
|
7
|
+
type GetEnsResolverOptions,
|
|
8
|
+
type GetEnsResolverQueryFnData,
|
|
9
|
+
type GetEnsResolverQueryKey,
|
|
10
|
+
getEnsResolverQueryOptions,
|
|
11
|
+
} from '@wagmi/core/query'
|
|
12
|
+
|
|
13
|
+
import type { ConfigParameter } from '../types/properties.js'
|
|
14
|
+
import {
|
|
15
|
+
type UseQueryParameters,
|
|
16
|
+
type UseQueryReturnType,
|
|
17
|
+
useQuery,
|
|
18
|
+
} from '../utils/query.js'
|
|
19
|
+
import { useChainId } from './useChainId.js'
|
|
20
|
+
import { useConfig } from './useConfig.js'
|
|
21
|
+
|
|
22
|
+
export type UseEnsResolverParameters<
|
|
23
|
+
config extends Config = Config,
|
|
24
|
+
selectData = GetEnsResolverData,
|
|
25
|
+
> = Evaluate<
|
|
26
|
+
GetEnsResolverOptions<config> &
|
|
27
|
+
ConfigParameter<config> & {
|
|
28
|
+
query?:
|
|
29
|
+
| UseQueryParameters<
|
|
30
|
+
GetEnsResolverQueryFnData,
|
|
31
|
+
GetEnsResolverError,
|
|
32
|
+
selectData,
|
|
33
|
+
GetEnsResolverQueryKey<config>
|
|
34
|
+
>
|
|
35
|
+
| undefined
|
|
36
|
+
}
|
|
37
|
+
>
|
|
38
|
+
|
|
39
|
+
export type UseEnsResolverReturnType<selectData = GetEnsResolverData> =
|
|
40
|
+
UseQueryReturnType<selectData, GetEnsResolverError>
|
|
41
|
+
|
|
42
|
+
/** https://alpha.wagmi.sh/react/api/hooks/useEnsResolver */
|
|
43
|
+
export function useEnsResolver<
|
|
44
|
+
config extends Config = ResolvedRegister['config'],
|
|
45
|
+
selectData = GetEnsResolverData,
|
|
46
|
+
>(
|
|
47
|
+
parameters: UseEnsResolverParameters<config, selectData> = {},
|
|
48
|
+
): UseEnsResolverReturnType<selectData> {
|
|
49
|
+
const { name, query = {} } = parameters
|
|
50
|
+
|
|
51
|
+
const config = useConfig(parameters)
|
|
52
|
+
const chainId = useChainId()
|
|
53
|
+
|
|
54
|
+
const queryOptions = getEnsResolverQueryOptions(config, {
|
|
55
|
+
...parameters,
|
|
56
|
+
chainId: parameters.chainId ?? chainId,
|
|
57
|
+
})
|
|
58
|
+
const enabled = Boolean(name && (query.enabled ?? true))
|
|
59
|
+
|
|
60
|
+
return useQuery({ ...queryOptions, ...query, enabled })
|
|
61
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type Config,
|
|
5
|
+
type EstimateFeesPerGasError,
|
|
6
|
+
type ResolvedRegister,
|
|
7
|
+
} from '@wagmi/core'
|
|
8
|
+
import { type Evaluate } from '@wagmi/core/internal'
|
|
9
|
+
import {
|
|
10
|
+
type EstimateFeesPerGasData,
|
|
11
|
+
type EstimateFeesPerGasOptions,
|
|
12
|
+
type EstimateFeesPerGasQueryFnData,
|
|
13
|
+
type EstimateFeesPerGasQueryKey,
|
|
14
|
+
estimateFeesPerGasQueryOptions,
|
|
15
|
+
} from '@wagmi/core/query'
|
|
16
|
+
import type { FeeValuesType } from 'viem'
|
|
17
|
+
|
|
18
|
+
import type { ConfigParameter } from '../types/properties.js'
|
|
19
|
+
import {
|
|
20
|
+
type UseQueryParameters,
|
|
21
|
+
type UseQueryReturnType,
|
|
22
|
+
useQuery,
|
|
23
|
+
} from '../utils/query.js'
|
|
24
|
+
import { useChainId } from './useChainId.js'
|
|
25
|
+
import { useConfig } from './useConfig.js'
|
|
26
|
+
|
|
27
|
+
export type UseEstimateFeesPerGasParameters<
|
|
28
|
+
type extends FeeValuesType = FeeValuesType,
|
|
29
|
+
config extends Config = Config,
|
|
30
|
+
selectData = EstimateFeesPerGasData<type>,
|
|
31
|
+
> = Evaluate<
|
|
32
|
+
EstimateFeesPerGasOptions<type, config> &
|
|
33
|
+
ConfigParameter<config> & {
|
|
34
|
+
query?:
|
|
35
|
+
| UseQueryParameters<
|
|
36
|
+
EstimateFeesPerGasQueryFnData<type>,
|
|
37
|
+
EstimateFeesPerGasError,
|
|
38
|
+
selectData,
|
|
39
|
+
EstimateFeesPerGasQueryKey<config, type>
|
|
40
|
+
>
|
|
41
|
+
| undefined
|
|
42
|
+
}
|
|
43
|
+
>
|
|
44
|
+
|
|
45
|
+
export type UseEstimateFeesPerGasReturnType<
|
|
46
|
+
type extends FeeValuesType = FeeValuesType,
|
|
47
|
+
selectData = EstimateFeesPerGasData<type>,
|
|
48
|
+
> = UseQueryReturnType<selectData, EstimateFeesPerGasError>
|
|
49
|
+
|
|
50
|
+
/** https://alpha.wagmi.sh/react/api/hooks/useEstimateFeesPerGas */
|
|
51
|
+
export function useEstimateFeesPerGas<
|
|
52
|
+
config extends Config = ResolvedRegister['config'],
|
|
53
|
+
type extends FeeValuesType = 'eip1559',
|
|
54
|
+
selectData = EstimateFeesPerGasData<type>,
|
|
55
|
+
>(
|
|
56
|
+
parameters: UseEstimateFeesPerGasParameters<type, config, selectData> = {},
|
|
57
|
+
): UseEstimateFeesPerGasReturnType<type, selectData> {
|
|
58
|
+
const { query = {} } = parameters
|
|
59
|
+
|
|
60
|
+
const config = useConfig(parameters)
|
|
61
|
+
const chainId = useChainId()
|
|
62
|
+
|
|
63
|
+
const queryOptions = estimateFeesPerGasQueryOptions(config, {
|
|
64
|
+
...parameters,
|
|
65
|
+
chainId: parameters.chainId ?? chainId,
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
return useQuery({ ...queryOptions, ...query })
|
|
69
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import type { Config, EstimateGasError, ResolvedRegister } from '@wagmi/core'
|
|
4
|
+
import {
|
|
5
|
+
type EstimateGasData,
|
|
6
|
+
type EstimateGasOptions,
|
|
7
|
+
type EstimateGasQueryFnData,
|
|
8
|
+
type EstimateGasQueryKey,
|
|
9
|
+
estimateGasQueryOptions,
|
|
10
|
+
} from '@wagmi/core/query'
|
|
11
|
+
|
|
12
|
+
import type { ConfigParameter } from '../types/properties.js'
|
|
13
|
+
import {
|
|
14
|
+
type UseQueryParameters,
|
|
15
|
+
type UseQueryReturnType,
|
|
16
|
+
useQuery,
|
|
17
|
+
} from '../utils/query.js'
|
|
18
|
+
import { useChainId } from './useChainId.js'
|
|
19
|
+
import { useConfig } from './useConfig.js'
|
|
20
|
+
import { useConnectorClient } from './useConnectorClient.js'
|
|
21
|
+
|
|
22
|
+
export type UseEstimateGasParameters<
|
|
23
|
+
config extends Config = Config,
|
|
24
|
+
chainId extends config['chains'][number]['id'] | undefined = undefined,
|
|
25
|
+
selectData = EstimateGasData,
|
|
26
|
+
> = EstimateGasOptions<config, chainId> &
|
|
27
|
+
ConfigParameter<config> & {
|
|
28
|
+
query?:
|
|
29
|
+
| UseQueryParameters<
|
|
30
|
+
EstimateGasQueryFnData,
|
|
31
|
+
EstimateGasError,
|
|
32
|
+
selectData,
|
|
33
|
+
EstimateGasQueryKey<config, chainId>
|
|
34
|
+
>
|
|
35
|
+
| undefined
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type UseEstimateGasReturnType<selectData = EstimateGasData> =
|
|
39
|
+
UseQueryReturnType<selectData, EstimateGasError>
|
|
40
|
+
|
|
41
|
+
/** https://alpha.wagmi.sh/react/api/hooks/useEstimateGas */
|
|
42
|
+
export function useEstimateGas<
|
|
43
|
+
config extends Config = ResolvedRegister['config'],
|
|
44
|
+
chainId extends config['chains'][number]['id'] | undefined = undefined,
|
|
45
|
+
selectData = EstimateGasData,
|
|
46
|
+
>(
|
|
47
|
+
parameters?: UseEstimateGasParameters<config, chainId, selectData>,
|
|
48
|
+
): UseEstimateGasReturnType<selectData>
|
|
49
|
+
|
|
50
|
+
export function useEstimateGas(
|
|
51
|
+
parameters: UseEstimateGasParameters = {},
|
|
52
|
+
): UseEstimateGasReturnType {
|
|
53
|
+
const { connector, query = {} } = parameters
|
|
54
|
+
|
|
55
|
+
const config = useConfig(parameters)
|
|
56
|
+
const { data: connectorClient } = useConnectorClient({
|
|
57
|
+
connector,
|
|
58
|
+
query: { enabled: parameters.account === undefined },
|
|
59
|
+
})
|
|
60
|
+
const account = parameters.account ?? connectorClient?.account
|
|
61
|
+
const chainId = useChainId()
|
|
62
|
+
|
|
63
|
+
const queryOptions = estimateGasQueryOptions(config, {
|
|
64
|
+
...(parameters as any),
|
|
65
|
+
account,
|
|
66
|
+
chainId: parameters.chainId ?? chainId,
|
|
67
|
+
connector,
|
|
68
|
+
})
|
|
69
|
+
const enabled = Boolean((account || connector) && (query.enabled ?? true))
|
|
70
|
+
|
|
71
|
+
return useQuery({ ...queryOptions, ...query, enabled })
|
|
72
|
+
}
|