@wagmi/vue 0.0.0-canary-20240515232917
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/README.md +14 -0
- package/actions/package.json +5 -0
- package/chains/package.json +5 -0
- package/connectors/package.json +5 -0
- package/dist/esm/composables/useAccount.js +18 -0
- package/dist/esm/composables/useAccount.js.map +1 -0
- package/dist/esm/composables/useAccountEffect.js +37 -0
- package/dist/esm/composables/useAccountEffect.js.map +1 -0
- package/dist/esm/composables/useBalance.js +24 -0
- package/dist/esm/composables/useBalance.js.map +1 -0
- package/dist/esm/composables/useBlockNumber.js +46 -0
- package/dist/esm/composables/useBlockNumber.js.map +1 -0
- package/dist/esm/composables/useChainId.js +17 -0
- package/dist/esm/composables/useChainId.js.map +1 -0
- package/dist/esm/composables/useChains.js +17 -0
- package/dist/esm/composables/useChains.js.map +1 -0
- package/dist/esm/composables/useClient.js +23 -0
- package/dist/esm/composables/useClient.js.map +1 -0
- package/dist/esm/composables/useConfig.js +19 -0
- package/dist/esm/composables/useConfig.js.map +1 -0
- package/dist/esm/composables/useConnect.js +29 -0
- package/dist/esm/composables/useConnect.js.map +1 -0
- package/dist/esm/composables/useConnections.js +16 -0
- package/dist/esm/composables/useConnections.js.map +1 -0
- package/dist/esm/composables/useConnectorClient.js +49 -0
- package/dist/esm/composables/useConnectorClient.js.map +1 -0
- package/dist/esm/composables/useConnectors.js +16 -0
- package/dist/esm/composables/useConnectors.js.map +1 -0
- package/dist/esm/composables/useDisconnect.js +24 -0
- package/dist/esm/composables/useDisconnect.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/useReconnect.js +21 -0
- package/dist/esm/composables/useReconnect.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/useSwitchAccount.js +23 -0
- package/dist/esm/composables/useSwitchAccount.js.map +1 -0
- package/dist/esm/composables/useSwitchChain.js +25 -0
- package/dist/esm/composables/useSwitchChain.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/useWatchBlockNumber.js +27 -0
- package/dist/esm/composables/useWatchBlockNumber.js.map +1 -0
- package/dist/esm/composables/useWriteContract.js +19 -0
- package/dist/esm/composables/useWriteContract.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/plugin.js +28 -0
- package/dist/esm/errors/plugin.js.map +1 -0
- package/dist/esm/exports/actions.js +5 -0
- package/dist/esm/exports/actions.js.map +1 -0
- package/dist/esm/exports/chains.js +5 -0
- package/dist/esm/exports/chains.js.map +1 -0
- package/dist/esm/exports/connectors.js +5 -0
- package/dist/esm/exports/connectors.js.map +1 -0
- package/dist/esm/exports/index.js +55 -0
- package/dist/esm/exports/index.js.map +1 -0
- package/dist/esm/exports/nuxt.js +4 -0
- package/dist/esm/exports/nuxt.js.map +1 -0
- package/dist/esm/exports/query.js +7 -0
- package/dist/esm/exports/query.js.map +1 -0
- package/dist/esm/nuxt/module.js +53 -0
- package/dist/esm/nuxt/module.js.map +1 -0
- package/dist/esm/nuxt/runtime/composables.js +2 -0
- package/dist/esm/nuxt/runtime/composables.js.map +1 -0
- package/dist/esm/plugin.js +14 -0
- package/dist/esm/plugin.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/types/ref.js +3 -0
- package/dist/esm/types/ref.js.map +1 -0
- package/dist/esm/utils/cloneDeep.js +36 -0
- package/dist/esm/utils/cloneDeep.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 +73 -0
- package/dist/esm/utils/query.js.map +1 -0
- package/dist/esm/utils/updateState.js +7 -0
- package/dist/esm/utils/updateState.js.map +1 -0
- package/dist/esm/version.js +2 -0
- package/dist/esm/version.js.map +1 -0
- package/dist/types/composables/useAccount.d.ts +8 -0
- package/dist/types/composables/useAccount.d.ts.map +1 -0
- package/dist/types/composables/useAccountEffect.d.ts +15 -0
- package/dist/types/composables/useAccountEffect.d.ts.map +1 -0
- package/dist/types/composables/useBalance.d.ts +12 -0
- package/dist/types/composables/useBalance.d.ts.map +1 -0
- package/dist/types/composables/useBlockNumber.d.ts +14 -0
- package/dist/types/composables/useBlockNumber.d.ts.map +1 -0
- package/dist/types/composables/useChainId.d.ts +8 -0
- package/dist/types/composables/useChainId.d.ts.map +1 -0
- package/dist/types/composables/useChains.d.ts +9 -0
- package/dist/types/composables/useChains.d.ts.map +1 -0
- package/dist/types/composables/useClient.d.ts +10 -0
- package/dist/types/composables/useClient.d.ts.map +1 -0
- package/dist/types/composables/useConfig.d.ts +8 -0
- package/dist/types/composables/useConfig.d.ts.map +1 -0
- package/dist/types/composables/useConnect.d.ts +16 -0
- package/dist/types/composables/useConnect.d.ts.map +1 -0
- package/dist/types/composables/useConnections.d.ts +8 -0
- package/dist/types/composables/useConnections.d.ts.map +1 -0
- package/dist/types/composables/useConnectorClient.d.ts +13 -0
- package/dist/types/composables/useConnectorClient.d.ts.map +1 -0
- package/dist/types/composables/useConnectors.d.ts +8 -0
- package/dist/types/composables/useConnectors.d.ts.map +1 -0
- package/dist/types/composables/useDisconnect.d.ts +17 -0
- package/dist/types/composables/useDisconnect.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/useReconnect.d.ts +16 -0
- package/dist/types/composables/useReconnect.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/useSwitchAccount.d.ts +17 -0
- package/dist/types/composables/useSwitchAccount.d.ts.map +1 -0
- package/dist/types/composables/useSwitchChain.d.ts +17 -0
- package/dist/types/composables/useSwitchChain.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/useWatchBlockNumber.d.ts +9 -0
- package/dist/types/composables/useWatchBlockNumber.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/errors/base.d.ts +10 -0
- package/dist/types/errors/base.d.ts.map +1 -0
- package/dist/types/errors/plugin.d.ts +16 -0
- package/dist/types/errors/plugin.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 +36 -0
- package/dist/types/exports/index.d.ts.map +1 -0
- package/dist/types/exports/nuxt.d.ts +4 -0
- package/dist/types/exports/nuxt.d.ts.map +1 -0
- package/dist/types/exports/query.d.ts +4 -0
- package/dist/types/exports/query.d.ts.map +1 -0
- package/dist/types/nuxt/module.d.ts +4 -0
- package/dist/types/nuxt/module.d.ts.map +1 -0
- package/dist/types/nuxt/runtime/composables.d.ts +2 -0
- package/dist/types/nuxt/runtime/composables.d.ts.map +1 -0
- package/dist/types/plugin.d.ts +11 -0
- package/dist/types/plugin.d.ts.map +1 -0
- package/dist/types/types/properties.d.ts +15 -0
- package/dist/types/types/properties.d.ts.map +1 -0
- package/dist/types/types/ref.d.ts +12 -0
- package/dist/types/types/ref.d.ts.map +1 -0
- package/dist/types/utils/cloneDeep.d.ts +3 -0
- package/dist/types/utils/cloneDeep.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 +17 -0
- package/dist/types/utils/query.d.ts.map +1 -0
- package/dist/types/utils/updateState.d.ts +2 -0
- package/dist/types/utils/updateState.d.ts.map +1 -0
- package/dist/types/version.d.ts +2 -0
- package/dist/types/version.d.ts.map +1 -0
- package/nuxt/package.json +5 -0
- package/package.json +108 -0
- package/query/package.json +5 -0
- package/src/composables/useAccount.ts +37 -0
- package/src/composables/useAccountEffect.ts +66 -0
- package/src/composables/useBalance.ts +69 -0
- package/src/composables/useBlockNumber.ts +118 -0
- package/src/composables/useChainId.ts +35 -0
- package/src/composables/useChains.ts +38 -0
- package/src/composables/useClient.ts +66 -0
- package/src/composables/useConfig.ts +34 -0
- package/src/composables/useConnect.ts +91 -0
- package/src/composables/useConnections.ts +30 -0
- package/src/composables/useConnectorClient.ts +127 -0
- package/src/composables/useConnectors.ts +30 -0
- package/src/composables/useDisconnect.ts +70 -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/useReconnect.ts +65 -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/useSwitchAccount.ts +84 -0
- package/src/composables/useSwitchChain.ts +80 -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/useWatchBlockNumber.ts +61 -0
- package/src/composables/useWriteContract.ts +85 -0
- package/src/errors/base.ts +14 -0
- package/src/errors/plugin.ts +31 -0
- package/src/exports/actions.ts +5 -0
- package/src/exports/chains.ts +5 -0
- package/src/exports/connectors.ts +5 -0
- package/src/exports/index.ts +260 -0
- package/src/exports/nuxt.ts +4 -0
- package/src/exports/query.ts +17 -0
- package/src/nuxt/module.ts +59 -0
- package/src/nuxt/runtime/composables.ts +1 -0
- package/src/plugin.ts +22 -0
- package/src/types/properties.ts +27 -0
- package/src/types/ref.ts +36 -0
- package/src/utils/cloneDeep.ts +43 -0
- package/src/utils/getVersion.ts +3 -0
- package/src/utils/query.ts +161 -0
- package/src/utils/updateState.ts +10 -0
- package/src/version.ts +1 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Config,
|
|
3
|
+
type GetAccountReturnType,
|
|
4
|
+
type ResolvedRegister,
|
|
5
|
+
getAccount,
|
|
6
|
+
watchAccount,
|
|
7
|
+
} from '@wagmi/core'
|
|
8
|
+
import { type ToRefs, onScopeDispose, reactive, readonly, toRefs } from 'vue'
|
|
9
|
+
|
|
10
|
+
import { type ConfigParameter } from '../types/properties.js'
|
|
11
|
+
import { updateState } from '../utils/updateState.js'
|
|
12
|
+
import { useConfig } from './useConfig.js'
|
|
13
|
+
|
|
14
|
+
export type UseAccountParameters<config extends Config = Config> =
|
|
15
|
+
ConfigParameter<config>
|
|
16
|
+
|
|
17
|
+
export type UseAccountReturnType<config extends Config = Config> = ToRefs<
|
|
18
|
+
GetAccountReturnType<config>
|
|
19
|
+
>
|
|
20
|
+
|
|
21
|
+
/** https://wagmi.sh/vue/api/composables/useAccount */
|
|
22
|
+
export function useAccount<config extends Config = ResolvedRegister['config']>(
|
|
23
|
+
parameters: UseAccountParameters<config> = {},
|
|
24
|
+
): UseAccountReturnType<config> {
|
|
25
|
+
const config = useConfig(parameters)
|
|
26
|
+
|
|
27
|
+
const account = reactive(getAccount(config))
|
|
28
|
+
|
|
29
|
+
const unsubscribe = watchAccount(config, {
|
|
30
|
+
onChange(data) {
|
|
31
|
+
updateState(account, data)
|
|
32
|
+
},
|
|
33
|
+
})
|
|
34
|
+
onScopeDispose(() => unsubscribe())
|
|
35
|
+
|
|
36
|
+
return toRefs(readonly(account)) as UseAccountReturnType<config>
|
|
37
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { type GetAccountReturnType, watchAccount } from '@wagmi/core'
|
|
2
|
+
import type { Evaluate } from '@wagmi/core/internal'
|
|
3
|
+
import { watchEffect } from 'vue'
|
|
4
|
+
|
|
5
|
+
import type { ConfigParameter } from '../types/properties.js'
|
|
6
|
+
import type { DeepMaybeRef } from '../types/ref.js'
|
|
7
|
+
import { deepUnref } from '../utils/cloneDeep.js'
|
|
8
|
+
import { useConfig } from './useConfig.js'
|
|
9
|
+
|
|
10
|
+
export type UseAccountEffectParameters = Evaluate<
|
|
11
|
+
DeepMaybeRef<
|
|
12
|
+
{
|
|
13
|
+
onConnect?(
|
|
14
|
+
data: Evaluate<
|
|
15
|
+
Pick<
|
|
16
|
+
Extract<GetAccountReturnType, { status: 'connected' }>,
|
|
17
|
+
'address' | 'addresses' | 'chain' | 'chainId' | 'connector'
|
|
18
|
+
> & {
|
|
19
|
+
isReconnected: boolean
|
|
20
|
+
}
|
|
21
|
+
>,
|
|
22
|
+
): void
|
|
23
|
+
onDisconnect?(): void
|
|
24
|
+
} & ConfigParameter
|
|
25
|
+
>
|
|
26
|
+
>
|
|
27
|
+
|
|
28
|
+
/** https://wagmi.sh/vue/api/composables/useAccountEffect */
|
|
29
|
+
export function useAccountEffect(parameters: UseAccountEffectParameters = {}) {
|
|
30
|
+
const config = useConfig(parameters)
|
|
31
|
+
|
|
32
|
+
watchEffect((onCleanup) => {
|
|
33
|
+
const { onConnect, onDisconnect } = deepUnref(parameters)
|
|
34
|
+
|
|
35
|
+
const unwatch = watchAccount(config, {
|
|
36
|
+
onChange(data, prevData) {
|
|
37
|
+
if (
|
|
38
|
+
(prevData.status === 'reconnecting' ||
|
|
39
|
+
(prevData.status === 'connecting' &&
|
|
40
|
+
prevData.address === undefined)) &&
|
|
41
|
+
data.status === 'connected'
|
|
42
|
+
) {
|
|
43
|
+
const { address, addresses, chain, chainId, connector } = data
|
|
44
|
+
const isReconnected =
|
|
45
|
+
prevData.status === 'reconnecting' ||
|
|
46
|
+
// if `previousAccount.status` is `undefined`, the connector connected immediately.
|
|
47
|
+
prevData.status === undefined
|
|
48
|
+
onConnect?.({
|
|
49
|
+
address,
|
|
50
|
+
addresses,
|
|
51
|
+
chain,
|
|
52
|
+
chainId,
|
|
53
|
+
connector,
|
|
54
|
+
isReconnected,
|
|
55
|
+
})
|
|
56
|
+
} else if (
|
|
57
|
+
prevData.status === 'connected' &&
|
|
58
|
+
data.status === 'disconnected'
|
|
59
|
+
)
|
|
60
|
+
onDisconnect?.()
|
|
61
|
+
},
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
onCleanup(() => unwatch())
|
|
65
|
+
})
|
|
66
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Config,
|
|
3
|
+
type GetBalanceErrorType,
|
|
4
|
+
type ResolvedRegister,
|
|
5
|
+
} from '@wagmi/core'
|
|
6
|
+
import type { Evaluate } from '@wagmi/core/internal'
|
|
7
|
+
import {
|
|
8
|
+
type GetBalanceData,
|
|
9
|
+
type GetBalanceOptions,
|
|
10
|
+
type GetBalanceQueryKey,
|
|
11
|
+
getBalanceQueryOptions,
|
|
12
|
+
} from '@wagmi/core/query'
|
|
13
|
+
import type { GetBalanceQueryFnData } 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 UseBalanceParameters<
|
|
24
|
+
config extends Config = Config,
|
|
25
|
+
selectData = GetBalanceData,
|
|
26
|
+
> = Evaluate<
|
|
27
|
+
DeepMaybeRef<
|
|
28
|
+
GetBalanceOptions<config> &
|
|
29
|
+
ConfigParameter<config> &
|
|
30
|
+
QueryParameter<
|
|
31
|
+
GetBalanceQueryFnData,
|
|
32
|
+
GetBalanceErrorType,
|
|
33
|
+
selectData,
|
|
34
|
+
GetBalanceQueryKey<config>
|
|
35
|
+
>
|
|
36
|
+
>
|
|
37
|
+
>
|
|
38
|
+
|
|
39
|
+
export type UseBalanceReturnType<selectData = GetBalanceData> =
|
|
40
|
+
UseQueryReturnType<selectData, GetBalanceErrorType>
|
|
41
|
+
|
|
42
|
+
/** https://wagmi.sh/vue/api/composables/useBalance */
|
|
43
|
+
export function useBalance<
|
|
44
|
+
config extends Config = ResolvedRegister['config'],
|
|
45
|
+
selectData = GetBalanceData,
|
|
46
|
+
>(
|
|
47
|
+
parameters_: UseBalanceParameters<config, selectData> = {},
|
|
48
|
+
): UseBalanceReturnType<selectData> {
|
|
49
|
+
const parameters = computed(() => deepUnref(parameters_))
|
|
50
|
+
|
|
51
|
+
const config = useConfig(parameters)
|
|
52
|
+
const configChainId = useChainId({ config })
|
|
53
|
+
|
|
54
|
+
const queryOptions = computed(() => {
|
|
55
|
+
const {
|
|
56
|
+
address,
|
|
57
|
+
chainId = configChainId.value,
|
|
58
|
+
query = {},
|
|
59
|
+
} = parameters.value
|
|
60
|
+
const options = getBalanceQueryOptions(config, {
|
|
61
|
+
...parameters.value,
|
|
62
|
+
chainId,
|
|
63
|
+
})
|
|
64
|
+
const enabled = Boolean(address && (query.enabled ?? true))
|
|
65
|
+
return { ...query, ...options, enabled }
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
return useQuery(queryOptions as any) as UseBalanceReturnType<selectData>
|
|
69
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { useQueryClient } from '@tanstack/vue-query'
|
|
2
|
+
import {
|
|
3
|
+
type Config,
|
|
4
|
+
type GetBlockNumberErrorType,
|
|
5
|
+
type ResolvedRegister,
|
|
6
|
+
} from '@wagmi/core'
|
|
7
|
+
import {
|
|
8
|
+
type Evaluate,
|
|
9
|
+
type UnionEvaluate,
|
|
10
|
+
type UnionOmit,
|
|
11
|
+
} from '@wagmi/core/internal'
|
|
12
|
+
import {
|
|
13
|
+
type GetBlockNumberData,
|
|
14
|
+
type GetBlockNumberOptions,
|
|
15
|
+
type GetBlockNumberQueryFnData,
|
|
16
|
+
type GetBlockNumberQueryKey,
|
|
17
|
+
getBlockNumberQueryOptions,
|
|
18
|
+
} from '@wagmi/core/query'
|
|
19
|
+
import { computed } from 'vue'
|
|
20
|
+
|
|
21
|
+
import type { ConfigParameter, QueryParameter } from '../types/properties.js'
|
|
22
|
+
import type { DeepMaybeRef, DeepUnwrapRef } from '../types/ref.js'
|
|
23
|
+
import { deepUnref } from '../utils/cloneDeep.js'
|
|
24
|
+
import { type UseQueryReturnType, useQuery } from '../utils/query.js'
|
|
25
|
+
import { useChainId } from './useChainId.js'
|
|
26
|
+
import { useConfig } from './useConfig.js'
|
|
27
|
+
import {
|
|
28
|
+
type UseWatchBlockNumberParameters,
|
|
29
|
+
useWatchBlockNumber,
|
|
30
|
+
} from './useWatchBlockNumber.js'
|
|
31
|
+
|
|
32
|
+
export type UseBlockNumberParameters<
|
|
33
|
+
config extends Config = Config,
|
|
34
|
+
chainId extends config['chains'][number]['id'] = config['chains'][number]['id'],
|
|
35
|
+
selectData = GetBlockNumberData,
|
|
36
|
+
> = Evaluate<
|
|
37
|
+
DeepMaybeRef<
|
|
38
|
+
GetBlockNumberOptions<config, chainId> &
|
|
39
|
+
ConfigParameter<config> &
|
|
40
|
+
QueryParameter<
|
|
41
|
+
GetBlockNumberQueryFnData,
|
|
42
|
+
GetBlockNumberErrorType,
|
|
43
|
+
selectData,
|
|
44
|
+
GetBlockNumberQueryKey<config, chainId>
|
|
45
|
+
> & {
|
|
46
|
+
watch?:
|
|
47
|
+
| boolean
|
|
48
|
+
| UnionEvaluate<
|
|
49
|
+
UnionOmit<
|
|
50
|
+
DeepUnwrapRef<UseWatchBlockNumberParameters<config, chainId>>,
|
|
51
|
+
'chainId' | 'config' | 'onBlockNumber' | 'onError'
|
|
52
|
+
>
|
|
53
|
+
>
|
|
54
|
+
| undefined
|
|
55
|
+
}
|
|
56
|
+
>
|
|
57
|
+
>
|
|
58
|
+
|
|
59
|
+
export type UseBlockNumberReturnType<selectData = GetBlockNumberData> =
|
|
60
|
+
UseQueryReturnType<selectData, GetBlockNumberErrorType>
|
|
61
|
+
|
|
62
|
+
/** https://wagmi.sh/vue/api/composables/useBlockNumber */
|
|
63
|
+
export function useBlockNumber<
|
|
64
|
+
config extends Config = ResolvedRegister['config'],
|
|
65
|
+
chainId extends config['chains'][number]['id'] = config['chains'][number]['id'],
|
|
66
|
+
selectData = GetBlockNumberData,
|
|
67
|
+
>(
|
|
68
|
+
parameters_: UseBlockNumberParameters<config, chainId, selectData> = {},
|
|
69
|
+
): UseBlockNumberReturnType<selectData> {
|
|
70
|
+
const parameters = computed(() => deepUnref(parameters_))
|
|
71
|
+
|
|
72
|
+
const config = useConfig(parameters)
|
|
73
|
+
const queryClient = useQueryClient()
|
|
74
|
+
const configChainId = useChainId({ config })
|
|
75
|
+
|
|
76
|
+
const queryOptions = computed(() => {
|
|
77
|
+
const {
|
|
78
|
+
chainId = configChainId.value,
|
|
79
|
+
query = {},
|
|
80
|
+
watch: _,
|
|
81
|
+
...rest
|
|
82
|
+
} = parameters.value
|
|
83
|
+
const options = getBlockNumberQueryOptions(config, {
|
|
84
|
+
...deepUnref(rest),
|
|
85
|
+
chainId,
|
|
86
|
+
})
|
|
87
|
+
return {
|
|
88
|
+
...query,
|
|
89
|
+
...options,
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
const watchBlockNumberArgs = computed(() => {
|
|
94
|
+
const {
|
|
95
|
+
config,
|
|
96
|
+
chainId = configChainId.value,
|
|
97
|
+
query,
|
|
98
|
+
watch,
|
|
99
|
+
} = parameters.value
|
|
100
|
+
return {
|
|
101
|
+
...({
|
|
102
|
+
config,
|
|
103
|
+
chainId,
|
|
104
|
+
...(typeof watch === 'object' ? watch : {}),
|
|
105
|
+
} as UseWatchBlockNumberParameters),
|
|
106
|
+
enabled:
|
|
107
|
+
(query?.enabled ?? true) &&
|
|
108
|
+
(typeof watch === 'object' ? watch.enabled : watch),
|
|
109
|
+
onBlockNumber(blockNumber) {
|
|
110
|
+
queryClient.setQueryData(queryOptions.value.queryKey, blockNumber)
|
|
111
|
+
},
|
|
112
|
+
} satisfies UseWatchBlockNumberParameters
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
useWatchBlockNumber(watchBlockNumberArgs)
|
|
116
|
+
|
|
117
|
+
return useQuery(queryOptions as any) as UseBlockNumberReturnType<selectData>
|
|
118
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Config,
|
|
3
|
+
type GetChainIdReturnType,
|
|
4
|
+
type ResolvedRegister,
|
|
5
|
+
getChainId,
|
|
6
|
+
watchChainId,
|
|
7
|
+
} from '@wagmi/core'
|
|
8
|
+
import { type Ref, onScopeDispose, readonly, ref } from 'vue'
|
|
9
|
+
|
|
10
|
+
import { type ConfigParameter } from '../types/properties.js'
|
|
11
|
+
import { useConfig } from './useConfig.js'
|
|
12
|
+
|
|
13
|
+
export type UseChainIdParameters<config extends Config = Config> =
|
|
14
|
+
ConfigParameter<config>
|
|
15
|
+
|
|
16
|
+
export type UseChainIdReturnType<config extends Config = Config> = Ref<
|
|
17
|
+
GetChainIdReturnType<config>
|
|
18
|
+
>
|
|
19
|
+
|
|
20
|
+
/** https://wagmi.sh/vue/api/composables/useChainId */
|
|
21
|
+
export function useChainId<config extends Config = ResolvedRegister['config']>(
|
|
22
|
+
parameters: UseChainIdParameters<config> = {},
|
|
23
|
+
): UseChainIdReturnType<config> {
|
|
24
|
+
const config = useConfig(parameters)
|
|
25
|
+
|
|
26
|
+
const chainId = ref<GetChainIdReturnType>(getChainId(config))
|
|
27
|
+
const unsubscribe = watchChainId(config, {
|
|
28
|
+
onChange(data) {
|
|
29
|
+
chainId.value = data
|
|
30
|
+
},
|
|
31
|
+
})
|
|
32
|
+
onScopeDispose(() => unsubscribe())
|
|
33
|
+
|
|
34
|
+
return readonly(chainId)
|
|
35
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Config,
|
|
3
|
+
type GetChainsReturnType,
|
|
4
|
+
type ResolvedRegister,
|
|
5
|
+
getChains,
|
|
6
|
+
} from '@wagmi/core'
|
|
7
|
+
import { watchChains } from '@wagmi/core/internal'
|
|
8
|
+
|
|
9
|
+
import type { Chain } from 'viem'
|
|
10
|
+
import { type Ref, onScopeDispose, readonly, ref } from 'vue'
|
|
11
|
+
import type { ConfigParameter } from '../types/properties.js'
|
|
12
|
+
import { useConfig } from './useConfig.js'
|
|
13
|
+
|
|
14
|
+
export type UseChainsParameters<config extends Config = Config> =
|
|
15
|
+
ConfigParameter<config>
|
|
16
|
+
|
|
17
|
+
export type UseChainsReturnType<config extends Config = Config> = Ref<
|
|
18
|
+
config['chains'] extends readonly [Chain, ...Chain[]]
|
|
19
|
+
? config['chains']
|
|
20
|
+
: readonly [Chain, ...Chain[]]
|
|
21
|
+
>
|
|
22
|
+
|
|
23
|
+
/** https://wagmi.sh/vue/api/composables/useChains */
|
|
24
|
+
export function useChains<config extends Config = ResolvedRegister['config']>(
|
|
25
|
+
parameters: UseChainsParameters<config> = {},
|
|
26
|
+
): UseChainsReturnType<config> {
|
|
27
|
+
const config = useConfig(parameters)
|
|
28
|
+
|
|
29
|
+
const chains = ref<GetChainsReturnType>(getChains(config))
|
|
30
|
+
const unsubscribe = watchChains(config, {
|
|
31
|
+
onChange(data) {
|
|
32
|
+
chains.value = data
|
|
33
|
+
},
|
|
34
|
+
})
|
|
35
|
+
onScopeDispose(() => unsubscribe())
|
|
36
|
+
|
|
37
|
+
return readonly(chains)
|
|
38
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Config,
|
|
3
|
+
type GetClientParameters,
|
|
4
|
+
type GetClientReturnType,
|
|
5
|
+
type ResolvedRegister,
|
|
6
|
+
getClient,
|
|
7
|
+
watchClient,
|
|
8
|
+
} from '@wagmi/core'
|
|
9
|
+
import type { Evaluate } from '@wagmi/core/internal'
|
|
10
|
+
import {
|
|
11
|
+
type Ref,
|
|
12
|
+
computed,
|
|
13
|
+
onScopeDispose,
|
|
14
|
+
readonly,
|
|
15
|
+
ref,
|
|
16
|
+
watchEffect,
|
|
17
|
+
} from 'vue'
|
|
18
|
+
|
|
19
|
+
import type { ConfigParameter } from '../types/properties.js'
|
|
20
|
+
import type { DeepMaybeRef } from '../types/ref.js'
|
|
21
|
+
import { deepUnref } from '../utils/cloneDeep.js'
|
|
22
|
+
import { useConfig } from './useConfig.js'
|
|
23
|
+
|
|
24
|
+
export type UseClientParameters<
|
|
25
|
+
config extends Config = Config,
|
|
26
|
+
chainId extends config['chains'][number]['id'] | number | undefined =
|
|
27
|
+
| config['chains'][number]['id']
|
|
28
|
+
| undefined,
|
|
29
|
+
> = Evaluate<
|
|
30
|
+
DeepMaybeRef<GetClientParameters<config, chainId> & ConfigParameter<config>>
|
|
31
|
+
>
|
|
32
|
+
|
|
33
|
+
export type UseClientReturnType<
|
|
34
|
+
config extends Config = Config,
|
|
35
|
+
chainId extends config['chains'][number]['id'] | number | undefined =
|
|
36
|
+
| config['chains'][number]['id']
|
|
37
|
+
| undefined,
|
|
38
|
+
> = Ref<GetClientReturnType<config, chainId>>
|
|
39
|
+
|
|
40
|
+
/** https://wagmi.sh/vue/api/composables/useClient */
|
|
41
|
+
export function useClient<
|
|
42
|
+
config extends Config = ResolvedRegister['config'],
|
|
43
|
+
chainId extends config['chains'][number]['id'] | number | undefined =
|
|
44
|
+
| config['chains'][number]['id']
|
|
45
|
+
| undefined,
|
|
46
|
+
>(
|
|
47
|
+
parameters: UseClientParameters<config, chainId> = {},
|
|
48
|
+
): UseClientReturnType<config, chainId> {
|
|
49
|
+
const params = computed(() => deepUnref(parameters))
|
|
50
|
+
|
|
51
|
+
const config = useConfig(params)
|
|
52
|
+
|
|
53
|
+
const client = ref(getClient(config, params.value as GetClientParameters))
|
|
54
|
+
watchEffect(() => {
|
|
55
|
+
client.value = getClient(config, params.value as GetClientParameters)
|
|
56
|
+
})
|
|
57
|
+
const unsubscribe = watchClient(config, {
|
|
58
|
+
onChange(data) {
|
|
59
|
+
if (client.value?.uid === data?.uid) return
|
|
60
|
+
client.value = data
|
|
61
|
+
},
|
|
62
|
+
})
|
|
63
|
+
onScopeDispose(() => unsubscribe())
|
|
64
|
+
|
|
65
|
+
return readonly(client) as UseClientReturnType<config, chainId>
|
|
66
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type Config, type ResolvedRegister } from '@wagmi/core'
|
|
2
|
+
import { hasInjectionContext, inject, unref } from 'vue'
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
WagmiInjectionContextError,
|
|
6
|
+
WagmiPluginNotFoundError,
|
|
7
|
+
} from '../errors/plugin.js'
|
|
8
|
+
import { configKey } from '../plugin.js'
|
|
9
|
+
import type { ConfigParameter } from '../types/properties.js'
|
|
10
|
+
import type { DeepMaybeRef } from '../types/ref.js'
|
|
11
|
+
|
|
12
|
+
export type UseConfigParameters<config extends Config = Config> = DeepMaybeRef<
|
|
13
|
+
ConfigParameter<config>
|
|
14
|
+
>
|
|
15
|
+
|
|
16
|
+
export type UseConfigReturnType<config extends Config = Config> = config
|
|
17
|
+
|
|
18
|
+
/** https://wagmi.sh/vue/api/composables/useConfig */
|
|
19
|
+
export function useConfig<config extends Config = ResolvedRegister['config']>(
|
|
20
|
+
parameters_: UseConfigParameters<config> = {},
|
|
21
|
+
): UseConfigReturnType<config> {
|
|
22
|
+
const parameters = unref(parameters_)
|
|
23
|
+
|
|
24
|
+
// passthrough config if provided
|
|
25
|
+
if (parameters.config) return parameters.config as UseConfigReturnType<config>
|
|
26
|
+
|
|
27
|
+
// ensures that `inject()` can be used
|
|
28
|
+
if (!hasInjectionContext()) throw new WagmiInjectionContextError()
|
|
29
|
+
|
|
30
|
+
const config = inject<Config | undefined>(configKey)
|
|
31
|
+
if (!config) throw new WagmiPluginNotFoundError()
|
|
32
|
+
|
|
33
|
+
return config as UseConfigReturnType<config>
|
|
34
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { useMutation } from '@tanstack/vue-query'
|
|
2
|
+
import {
|
|
3
|
+
type Config,
|
|
4
|
+
type ConnectErrorType,
|
|
5
|
+
type GetConnectorsReturnType,
|
|
6
|
+
type ResolvedRegister,
|
|
7
|
+
} from '@wagmi/core'
|
|
8
|
+
import type { Evaluate } from '@wagmi/core/internal'
|
|
9
|
+
import {
|
|
10
|
+
type ConnectData,
|
|
11
|
+
type ConnectMutate,
|
|
12
|
+
type ConnectMutateAsync,
|
|
13
|
+
type ConnectVariables,
|
|
14
|
+
connectMutationOptions,
|
|
15
|
+
} from '@wagmi/core/query'
|
|
16
|
+
import { onScopeDispose } from 'vue'
|
|
17
|
+
|
|
18
|
+
import type { ConfigParameter } from '../types/properties.js'
|
|
19
|
+
import type {
|
|
20
|
+
UseMutationParameters,
|
|
21
|
+
UseMutationReturnType,
|
|
22
|
+
} from '../utils/query.js'
|
|
23
|
+
import { useConfig } from './useConfig.js'
|
|
24
|
+
import { useConnectors } from './useConnectors.js'
|
|
25
|
+
|
|
26
|
+
export type UseConnectParameters<
|
|
27
|
+
config extends Config = Config,
|
|
28
|
+
context = unknown,
|
|
29
|
+
> = Evaluate<
|
|
30
|
+
ConfigParameter<config> & {
|
|
31
|
+
mutation?:
|
|
32
|
+
| UseMutationParameters<
|
|
33
|
+
ConnectData<config>,
|
|
34
|
+
ConnectErrorType,
|
|
35
|
+
ConnectVariables<config>,
|
|
36
|
+
context
|
|
37
|
+
>
|
|
38
|
+
| undefined
|
|
39
|
+
}
|
|
40
|
+
>
|
|
41
|
+
|
|
42
|
+
export type UseConnectReturnType<
|
|
43
|
+
config extends Config = Config,
|
|
44
|
+
context = unknown,
|
|
45
|
+
> = Evaluate<
|
|
46
|
+
UseMutationReturnType<
|
|
47
|
+
ConnectData<config>,
|
|
48
|
+
ConnectErrorType,
|
|
49
|
+
ConnectVariables<config>,
|
|
50
|
+
context
|
|
51
|
+
> & {
|
|
52
|
+
connect: ConnectMutate<config, context>
|
|
53
|
+
connectAsync: ConnectMutateAsync<config, context>
|
|
54
|
+
connectors: Evaluate<GetConnectorsReturnType>
|
|
55
|
+
}
|
|
56
|
+
>
|
|
57
|
+
|
|
58
|
+
/** https://wagmi.sh/vue/api/composables/useConnect */
|
|
59
|
+
export function useConnect<
|
|
60
|
+
config extends Config = ResolvedRegister['config'],
|
|
61
|
+
context = unknown,
|
|
62
|
+
>(
|
|
63
|
+
parameters: UseConnectParameters<config, context> = {},
|
|
64
|
+
): UseConnectReturnType<config, context> {
|
|
65
|
+
const { mutation } = parameters
|
|
66
|
+
|
|
67
|
+
const config = useConfig(parameters)
|
|
68
|
+
|
|
69
|
+
const mutationOptions = connectMutationOptions(config)
|
|
70
|
+
const { mutate, mutateAsync, ...result } = useMutation({
|
|
71
|
+
...mutation,
|
|
72
|
+
...mutationOptions,
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
// Reset mutation back to an idle state when the connector disconnects.
|
|
76
|
+
const unsubscribe = config.subscribe(
|
|
77
|
+
({ status }) => status,
|
|
78
|
+
(status, previousStatus) => {
|
|
79
|
+
if (previousStatus === 'connected' && status === 'disconnected')
|
|
80
|
+
result.reset()
|
|
81
|
+
},
|
|
82
|
+
)
|
|
83
|
+
onScopeDispose(() => unsubscribe())
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
...result,
|
|
87
|
+
connect: mutate,
|
|
88
|
+
connectAsync: mutateAsync,
|
|
89
|
+
connectors: useConnectors({ config }).value,
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type GetConnectionsReturnType,
|
|
3
|
+
getConnections,
|
|
4
|
+
watchConnections,
|
|
5
|
+
} from '@wagmi/core'
|
|
6
|
+
import { type Ref, onScopeDispose, readonly, ref } from 'vue'
|
|
7
|
+
|
|
8
|
+
import type { ConfigParameter } from '../types/properties.js'
|
|
9
|
+
import { useConfig } from './useConfig.js'
|
|
10
|
+
|
|
11
|
+
export type UseConnectionsParameters = ConfigParameter
|
|
12
|
+
|
|
13
|
+
export type UseConnectionsReturnType = Ref<GetConnectionsReturnType>
|
|
14
|
+
|
|
15
|
+
/** https://wagmi.sh/vue/api/composables/useConnections */
|
|
16
|
+
export function useConnections(
|
|
17
|
+
parameters: UseConnectionsParameters = {},
|
|
18
|
+
): UseConnectionsReturnType {
|
|
19
|
+
const config = useConfig(parameters)
|
|
20
|
+
|
|
21
|
+
const connections = ref(getConnections(config))
|
|
22
|
+
const unsubscribe = watchConnections(config, {
|
|
23
|
+
onChange(data) {
|
|
24
|
+
connections.value = data
|
|
25
|
+
},
|
|
26
|
+
})
|
|
27
|
+
onScopeDispose(() => unsubscribe())
|
|
28
|
+
|
|
29
|
+
return readonly(connections) as UseConnectionsReturnType
|
|
30
|
+
}
|