@wagmi/vue 0.0.0-vue-20240513033839
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/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/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/useReconnect.js +21 -0
- package/dist/esm/composables/useReconnect.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/useWatchBlockNumber.js +27 -0
- package/dist/esm/composables/useWatchBlockNumber.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 +41 -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 +19 -0
- package/dist/esm/nuxt/module.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/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/useReconnect.d.ts +16 -0
- package/dist/types/composables/useReconnect.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/useWatchBlockNumber.d.ts +9 -0
- package/dist/types/composables/useWatchBlockNumber.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 +22 -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/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/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/useReconnect.ts +65 -0
- package/src/composables/useSwitchAccount.ts +84 -0
- package/src/composables/useSwitchChain.ts +80 -0
- package/src/composables/useWatchBlockNumber.ts +61 -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 +176 -0
- package/src/exports/nuxt.ts +4 -0
- package/src/exports/query.ts +17 -0
- package/src/nuxt/module.ts +25 -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 +159 -0
- package/src/utils/updateState.ts +10 -0
- package/src/version.ts +1 -0
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { useQueryClient } from '@tanstack/vue-query'
|
|
2
|
+
import type {
|
|
3
|
+
Config,
|
|
4
|
+
Connector,
|
|
5
|
+
GetConnectorClientErrorType,
|
|
6
|
+
ResolvedRegister,
|
|
7
|
+
} from '@wagmi/core'
|
|
8
|
+
import { type Evaluate, type Omit } from '@wagmi/core/internal'
|
|
9
|
+
import {
|
|
10
|
+
type GetConnectorClientData,
|
|
11
|
+
type GetConnectorClientOptions,
|
|
12
|
+
type GetConnectorClientQueryFnData,
|
|
13
|
+
type GetConnectorClientQueryKey,
|
|
14
|
+
getConnectorClientQueryOptions,
|
|
15
|
+
} from '@wagmi/core/query'
|
|
16
|
+
import { computed, ref, watchEffect } from 'vue'
|
|
17
|
+
|
|
18
|
+
import type { ConfigParameter } from '../types/properties.js'
|
|
19
|
+
import type { DeepMaybeRef, DeepUnwrapRef } from '../types/ref.js'
|
|
20
|
+
import { deepUnref } from '../utils/cloneDeep.js'
|
|
21
|
+
import {
|
|
22
|
+
type UseQueryParameters,
|
|
23
|
+
type UseQueryReturnType,
|
|
24
|
+
useQuery,
|
|
25
|
+
} from '../utils/query.js'
|
|
26
|
+
import { useAccount } from './useAccount.js'
|
|
27
|
+
import { useChainId } from './useChainId.js'
|
|
28
|
+
import { useConfig } from './useConfig.js'
|
|
29
|
+
|
|
30
|
+
export type UseConnectorClientParameters<
|
|
31
|
+
config extends Config = Config,
|
|
32
|
+
chainId extends config['chains'][number]['id'] = config['chains'][number]['id'],
|
|
33
|
+
selectData = GetConnectorClientData<config, chainId>,
|
|
34
|
+
> = Evaluate<
|
|
35
|
+
DeepMaybeRef<
|
|
36
|
+
GetConnectorClientOptions<config, chainId> &
|
|
37
|
+
ConfigParameter<config> & {
|
|
38
|
+
query?:
|
|
39
|
+
| Evaluate<
|
|
40
|
+
Omit<
|
|
41
|
+
DeepUnwrapRef<
|
|
42
|
+
UseQueryParameters<
|
|
43
|
+
GetConnectorClientQueryFnData<config, chainId>,
|
|
44
|
+
GetConnectorClientErrorType,
|
|
45
|
+
selectData,
|
|
46
|
+
GetConnectorClientQueryKey<config, chainId>
|
|
47
|
+
>
|
|
48
|
+
>,
|
|
49
|
+
'gcTime' | 'staleTime'
|
|
50
|
+
>
|
|
51
|
+
>
|
|
52
|
+
| undefined
|
|
53
|
+
}
|
|
54
|
+
>
|
|
55
|
+
>
|
|
56
|
+
|
|
57
|
+
export type UseConnectorClientReturnType<
|
|
58
|
+
config extends Config = Config,
|
|
59
|
+
chainId extends config['chains'][number]['id'] = config['chains'][number]['id'],
|
|
60
|
+
selectData = GetConnectorClientData<config, chainId>,
|
|
61
|
+
> = UseQueryReturnType<selectData, GetConnectorClientErrorType>
|
|
62
|
+
|
|
63
|
+
/** https://wagmi.sh/vue/api/composables/useConnectorClient */
|
|
64
|
+
export function useConnectorClient<
|
|
65
|
+
config extends Config = ResolvedRegister['config'],
|
|
66
|
+
chainId extends config['chains'][number]['id'] = config['chains'][number]['id'],
|
|
67
|
+
selectData = GetConnectorClientData<config, chainId>,
|
|
68
|
+
>(
|
|
69
|
+
parameters_: UseConnectorClientParameters<config, chainId, selectData> = {},
|
|
70
|
+
): UseConnectorClientReturnType<config, chainId, selectData> {
|
|
71
|
+
const parameters = computed(() => deepUnref(parameters_))
|
|
72
|
+
|
|
73
|
+
const config = useConfig(parameters)
|
|
74
|
+
const queryClient = useQueryClient()
|
|
75
|
+
const {
|
|
76
|
+
address,
|
|
77
|
+
connector: accountConnector,
|
|
78
|
+
status,
|
|
79
|
+
} = useAccount({ config })
|
|
80
|
+
const configChainId = useChainId({ config })
|
|
81
|
+
|
|
82
|
+
const queryOptions = computed(() => {
|
|
83
|
+
const {
|
|
84
|
+
chainId = configChainId.value,
|
|
85
|
+
connector = accountConnector.value,
|
|
86
|
+
query = {},
|
|
87
|
+
} = parameters.value
|
|
88
|
+
const { queryKey, ...options } = getConnectorClientQueryOptions<
|
|
89
|
+
config,
|
|
90
|
+
chainId
|
|
91
|
+
>(config as config, {
|
|
92
|
+
...deepUnref(parameters),
|
|
93
|
+
chainId: chainId as chainId,
|
|
94
|
+
connector: connector as Connector,
|
|
95
|
+
})
|
|
96
|
+
const enabled = Boolean(
|
|
97
|
+
status.value !== 'disconnected' && (query.enabled ?? true),
|
|
98
|
+
)
|
|
99
|
+
return {
|
|
100
|
+
...query,
|
|
101
|
+
...options,
|
|
102
|
+
queryKey,
|
|
103
|
+
enabled,
|
|
104
|
+
staleTime: Infinity,
|
|
105
|
+
}
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
const addressRef = ref(address)
|
|
109
|
+
watchEffect(() => {
|
|
110
|
+
const previousAddress = addressRef.value
|
|
111
|
+
if (!address && previousAddress) {
|
|
112
|
+
// remove when account is disconnected
|
|
113
|
+
queryClient.removeQueries({ queryKey: queryOptions.value.queryKey })
|
|
114
|
+
addressRef.value = undefined
|
|
115
|
+
} else if (address.value !== previousAddress) {
|
|
116
|
+
// invalidate when address changes
|
|
117
|
+
queryClient.invalidateQueries({ queryKey: queryOptions.value.queryKey })
|
|
118
|
+
addressRef.value = address.value
|
|
119
|
+
}
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
return useQuery(queryOptions as any) as UseConnectorClientReturnType<
|
|
123
|
+
config,
|
|
124
|
+
chainId,
|
|
125
|
+
selectData
|
|
126
|
+
>
|
|
127
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type GetConnectorsReturnType,
|
|
3
|
+
getConnectors,
|
|
4
|
+
watchConnectors,
|
|
5
|
+
} from '@wagmi/core'
|
|
6
|
+
import { type Ref, onScopeDispose, ref } from 'vue'
|
|
7
|
+
|
|
8
|
+
import type { ConfigParameter } from '../types/properties.js'
|
|
9
|
+
import { useConfig } from './useConfig.js'
|
|
10
|
+
|
|
11
|
+
export type UseConnectorsParameters = ConfigParameter
|
|
12
|
+
|
|
13
|
+
export type UseConnectorsReturnType = Ref<GetConnectorsReturnType>
|
|
14
|
+
|
|
15
|
+
/** https://wagmi.sh/vue/api/composables/useConnectors */
|
|
16
|
+
export function useConnectors(
|
|
17
|
+
parameters: UseConnectorsParameters = {},
|
|
18
|
+
): UseConnectorsReturnType {
|
|
19
|
+
const config = useConfig(parameters)
|
|
20
|
+
|
|
21
|
+
const connectors = ref(getConnectors(config))
|
|
22
|
+
const unsubscribe = watchConnectors(config, {
|
|
23
|
+
onChange(data) {
|
|
24
|
+
connectors.value = data
|
|
25
|
+
},
|
|
26
|
+
})
|
|
27
|
+
onScopeDispose(() => unsubscribe())
|
|
28
|
+
|
|
29
|
+
return connectors
|
|
30
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { useMutation } from '@tanstack/vue-query'
|
|
2
|
+
import { type Connector, type DisconnectErrorType } from '@wagmi/core'
|
|
3
|
+
import type { Evaluate } from '@wagmi/core/internal'
|
|
4
|
+
import {
|
|
5
|
+
type DisconnectData,
|
|
6
|
+
type DisconnectMutate,
|
|
7
|
+
type DisconnectMutateAsync,
|
|
8
|
+
type DisconnectVariables,
|
|
9
|
+
disconnectMutationOptions,
|
|
10
|
+
} from '@wagmi/core/query'
|
|
11
|
+
import { type Ref, computed } from 'vue'
|
|
12
|
+
|
|
13
|
+
import type { ConfigParameter } from '../types/properties.js'
|
|
14
|
+
import type {
|
|
15
|
+
UseMutationParameters,
|
|
16
|
+
UseMutationReturnType,
|
|
17
|
+
} from '../utils/query.js'
|
|
18
|
+
import { useConfig } from './useConfig.js'
|
|
19
|
+
import { useConnections } from './useConnections.js'
|
|
20
|
+
|
|
21
|
+
export type UseDisconnectParameters<context = unknown> = Evaluate<
|
|
22
|
+
ConfigParameter & {
|
|
23
|
+
mutation?:
|
|
24
|
+
| UseMutationParameters<
|
|
25
|
+
DisconnectData,
|
|
26
|
+
DisconnectErrorType,
|
|
27
|
+
DisconnectVariables,
|
|
28
|
+
context
|
|
29
|
+
>
|
|
30
|
+
| undefined
|
|
31
|
+
}
|
|
32
|
+
>
|
|
33
|
+
|
|
34
|
+
export type UseDisconnectReturnType<context = unknown> = Evaluate<
|
|
35
|
+
UseMutationReturnType<
|
|
36
|
+
DisconnectData,
|
|
37
|
+
DisconnectErrorType,
|
|
38
|
+
DisconnectVariables,
|
|
39
|
+
context
|
|
40
|
+
> & {
|
|
41
|
+
connectors: Ref<readonly Connector[]>
|
|
42
|
+
disconnect: DisconnectMutate<context>
|
|
43
|
+
disconnectAsync: DisconnectMutateAsync<context>
|
|
44
|
+
}
|
|
45
|
+
>
|
|
46
|
+
|
|
47
|
+
/** https://wagmi.sh/vue/api/composables/useDisconnect */
|
|
48
|
+
export function useDisconnect<context = unknown>(
|
|
49
|
+
parameters: UseDisconnectParameters<context> = {},
|
|
50
|
+
): UseDisconnectReturnType<context> {
|
|
51
|
+
const { mutation } = parameters
|
|
52
|
+
|
|
53
|
+
const config = useConfig(parameters)
|
|
54
|
+
const connections = useConnections({ config })
|
|
55
|
+
|
|
56
|
+
const mutationOptions = disconnectMutationOptions(config)
|
|
57
|
+
const { mutate, mutateAsync, ...result } = useMutation({
|
|
58
|
+
...mutation,
|
|
59
|
+
...mutationOptions,
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
...result,
|
|
64
|
+
connectors: computed(() =>
|
|
65
|
+
connections.value.map((connection) => connection.connector),
|
|
66
|
+
),
|
|
67
|
+
disconnect: mutate,
|
|
68
|
+
disconnectAsync: mutateAsync,
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { useMutation } from '@tanstack/vue-query'
|
|
2
|
+
import { type Connector, type ReconnectErrorType } from '@wagmi/core'
|
|
3
|
+
import type { Evaluate } from '@wagmi/core/internal'
|
|
4
|
+
import {
|
|
5
|
+
type ReconnectData,
|
|
6
|
+
type ReconnectMutate,
|
|
7
|
+
type ReconnectMutateAsync,
|
|
8
|
+
type ReconnectVariables,
|
|
9
|
+
reconnectMutationOptions,
|
|
10
|
+
} from '@wagmi/core/query'
|
|
11
|
+
|
|
12
|
+
import type { ConfigParameter } from '../types/properties.js'
|
|
13
|
+
import type {
|
|
14
|
+
UseMutationParameters,
|
|
15
|
+
UseMutationReturnType,
|
|
16
|
+
} from '../utils/query.js'
|
|
17
|
+
import { useConfig } from './useConfig.js'
|
|
18
|
+
|
|
19
|
+
export type UseReconnectParameters<context = unknown> = Evaluate<
|
|
20
|
+
ConfigParameter & {
|
|
21
|
+
mutation?:
|
|
22
|
+
| UseMutationParameters<
|
|
23
|
+
ReconnectData,
|
|
24
|
+
ReconnectErrorType,
|
|
25
|
+
ReconnectVariables,
|
|
26
|
+
context
|
|
27
|
+
>
|
|
28
|
+
| undefined
|
|
29
|
+
}
|
|
30
|
+
>
|
|
31
|
+
|
|
32
|
+
export type UseReconnectReturnType<context = unknown> = Evaluate<
|
|
33
|
+
UseMutationReturnType<
|
|
34
|
+
ReconnectData,
|
|
35
|
+
ReconnectErrorType,
|
|
36
|
+
ReconnectVariables,
|
|
37
|
+
context
|
|
38
|
+
> & {
|
|
39
|
+
connectors: readonly Connector[]
|
|
40
|
+
reconnect: ReconnectMutate<context>
|
|
41
|
+
reconnectAsync: ReconnectMutateAsync<context>
|
|
42
|
+
}
|
|
43
|
+
>
|
|
44
|
+
|
|
45
|
+
/** https://wagmi.sh/vue/api/composables/useReconnect */
|
|
46
|
+
export function useReconnect<context = unknown>(
|
|
47
|
+
parameters: UseReconnectParameters<context> = {},
|
|
48
|
+
): UseReconnectReturnType<context> {
|
|
49
|
+
const { mutation } = parameters
|
|
50
|
+
|
|
51
|
+
const config = useConfig(parameters)
|
|
52
|
+
|
|
53
|
+
const mutationOptions = reconnectMutationOptions(config)
|
|
54
|
+
const { mutate, mutateAsync, ...result } = useMutation({
|
|
55
|
+
...mutation,
|
|
56
|
+
...mutationOptions,
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
...result,
|
|
61
|
+
connectors: config.connectors,
|
|
62
|
+
reconnect: mutate,
|
|
63
|
+
reconnectAsync: mutateAsync,
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { useMutation } from '@tanstack/vue-query'
|
|
2
|
+
import type {
|
|
3
|
+
Config,
|
|
4
|
+
Connector,
|
|
5
|
+
ResolvedRegister,
|
|
6
|
+
SwitchAccountErrorType,
|
|
7
|
+
} from '@wagmi/core'
|
|
8
|
+
import type { Evaluate } from '@wagmi/core/internal'
|
|
9
|
+
import {
|
|
10
|
+
type SwitchAccountData,
|
|
11
|
+
type SwitchAccountMutate,
|
|
12
|
+
type SwitchAccountMutateAsync,
|
|
13
|
+
type SwitchAccountVariables,
|
|
14
|
+
switchAccountMutationOptions,
|
|
15
|
+
} from '@wagmi/core/query'
|
|
16
|
+
import { type Ref, computed } 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 { useConnections } from './useConnections.js'
|
|
25
|
+
|
|
26
|
+
export type UseSwitchAccountParameters<
|
|
27
|
+
config extends Config = Config,
|
|
28
|
+
context = unknown,
|
|
29
|
+
> = Evaluate<
|
|
30
|
+
ConfigParameter<config> & {
|
|
31
|
+
mutation?:
|
|
32
|
+
| UseMutationParameters<
|
|
33
|
+
SwitchAccountData<config>,
|
|
34
|
+
SwitchAccountErrorType,
|
|
35
|
+
SwitchAccountVariables,
|
|
36
|
+
context
|
|
37
|
+
>
|
|
38
|
+
| undefined
|
|
39
|
+
}
|
|
40
|
+
>
|
|
41
|
+
|
|
42
|
+
export type UseSwitchAccountReturnType<
|
|
43
|
+
config extends Config = Config,
|
|
44
|
+
context = unknown,
|
|
45
|
+
> = Evaluate<
|
|
46
|
+
UseMutationReturnType<
|
|
47
|
+
SwitchAccountData<config>,
|
|
48
|
+
SwitchAccountErrorType,
|
|
49
|
+
SwitchAccountVariables,
|
|
50
|
+
context
|
|
51
|
+
> & {
|
|
52
|
+
connectors: Ref<readonly Connector[]>
|
|
53
|
+
switchAccount: SwitchAccountMutate<config, context>
|
|
54
|
+
switchAccountAsync: SwitchAccountMutateAsync<config, context>
|
|
55
|
+
}
|
|
56
|
+
>
|
|
57
|
+
|
|
58
|
+
/** https://wagmi.sh/vue/api/composables/useSwitchAccount */
|
|
59
|
+
export function useSwitchAccount<
|
|
60
|
+
config extends Config = ResolvedRegister['config'],
|
|
61
|
+
context = unknown,
|
|
62
|
+
>(
|
|
63
|
+
parameters: UseSwitchAccountParameters<config, context> = {},
|
|
64
|
+
): UseSwitchAccountReturnType<config, context> {
|
|
65
|
+
const { mutation } = parameters
|
|
66
|
+
|
|
67
|
+
const config = useConfig(parameters)
|
|
68
|
+
const connections = useConnections({ config })
|
|
69
|
+
|
|
70
|
+
const mutationOptions = switchAccountMutationOptions(config)
|
|
71
|
+
const { mutate, mutateAsync, ...result } = useMutation({
|
|
72
|
+
...mutation,
|
|
73
|
+
...mutationOptions,
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
...result,
|
|
78
|
+
connectors: computed(() =>
|
|
79
|
+
connections.value.map((connection) => connection.connector),
|
|
80
|
+
),
|
|
81
|
+
switchAccount: mutate,
|
|
82
|
+
switchAccountAsync: mutateAsync,
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { useMutation } from '@tanstack/vue-query'
|
|
2
|
+
import {
|
|
3
|
+
type Config,
|
|
4
|
+
type ResolvedRegister,
|
|
5
|
+
type SwitchChainErrorType,
|
|
6
|
+
} from '@wagmi/core'
|
|
7
|
+
import { type Evaluate } from '@wagmi/core/internal'
|
|
8
|
+
import {
|
|
9
|
+
type SwitchChainData,
|
|
10
|
+
type SwitchChainMutate,
|
|
11
|
+
type SwitchChainMutateAsync,
|
|
12
|
+
type SwitchChainVariables,
|
|
13
|
+
switchChainMutationOptions,
|
|
14
|
+
} from '@wagmi/core/query'
|
|
15
|
+
|
|
16
|
+
import { type ConfigParameter } from '../types/properties.js'
|
|
17
|
+
import {
|
|
18
|
+
type UseMutationParameters,
|
|
19
|
+
type UseMutationReturnType,
|
|
20
|
+
} from '../utils/query.js'
|
|
21
|
+
import { type UseChainsReturnType, useChains } from './useChains.js'
|
|
22
|
+
import { useConfig } from './useConfig.js'
|
|
23
|
+
|
|
24
|
+
export type UseSwitchChainParameters<
|
|
25
|
+
config extends Config = Config,
|
|
26
|
+
context = unknown,
|
|
27
|
+
> = Evaluate<
|
|
28
|
+
ConfigParameter<config> & {
|
|
29
|
+
mutation?:
|
|
30
|
+
| UseMutationParameters<
|
|
31
|
+
SwitchChainData<config, config['chains'][number]['id']>,
|
|
32
|
+
SwitchChainErrorType,
|
|
33
|
+
SwitchChainVariables<config, config['chains'][number]['id']>,
|
|
34
|
+
context
|
|
35
|
+
>
|
|
36
|
+
| undefined
|
|
37
|
+
}
|
|
38
|
+
>
|
|
39
|
+
|
|
40
|
+
export type UseSwitchChainReturnType<
|
|
41
|
+
config extends Config = Config,
|
|
42
|
+
context = unknown,
|
|
43
|
+
> = Evaluate<
|
|
44
|
+
UseMutationReturnType<
|
|
45
|
+
SwitchChainData<config, config['chains'][number]['id']>,
|
|
46
|
+
SwitchChainErrorType,
|
|
47
|
+
SwitchChainVariables<config, config['chains'][number]['id']>,
|
|
48
|
+
context
|
|
49
|
+
> & {
|
|
50
|
+
chains: Evaluate<UseChainsReturnType<config>>
|
|
51
|
+
switchChain: SwitchChainMutate<config, context>
|
|
52
|
+
switchChainAsync: SwitchChainMutateAsync<config, context>
|
|
53
|
+
}
|
|
54
|
+
>
|
|
55
|
+
|
|
56
|
+
/** https://wagmi.sh/vue/api/composables/useSwitchChain */
|
|
57
|
+
export function useSwitchChain<
|
|
58
|
+
config extends Config = ResolvedRegister['config'],
|
|
59
|
+
context = unknown,
|
|
60
|
+
>(
|
|
61
|
+
parameters: UseSwitchChainParameters<config, context> = {},
|
|
62
|
+
): UseSwitchChainReturnType<config, context> {
|
|
63
|
+
const { mutation } = parameters
|
|
64
|
+
|
|
65
|
+
const config = useConfig(parameters)
|
|
66
|
+
|
|
67
|
+
const mutationOptions = switchChainMutationOptions(config)
|
|
68
|
+
const { mutate, mutateAsync, ...result } = useMutation({
|
|
69
|
+
...mutation,
|
|
70
|
+
...mutationOptions,
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
type Return = UseSwitchChainReturnType<config, context>
|
|
74
|
+
return {
|
|
75
|
+
...result,
|
|
76
|
+
chains: useChains({ config }),
|
|
77
|
+
switchChain: mutate as Return['switchChain'],
|
|
78
|
+
switchChainAsync: mutateAsync as Return['switchChainAsync'],
|
|
79
|
+
} as Return
|
|
80
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Config,
|
|
3
|
+
type ResolvedRegister,
|
|
4
|
+
type WatchBlockNumberParameters,
|
|
5
|
+
watchBlockNumber,
|
|
6
|
+
} from '@wagmi/core'
|
|
7
|
+
import { type UnionEvaluate, type UnionPartial } from '@wagmi/core/internal'
|
|
8
|
+
import { computed, watchEffect } from 'vue'
|
|
9
|
+
|
|
10
|
+
import type { ConfigParameter, EnabledParameter } from '../types/properties.js'
|
|
11
|
+
import type { DeepMaybeRef } from '../types/ref.js'
|
|
12
|
+
import { deepUnref } from '../utils/cloneDeep.js'
|
|
13
|
+
import { useChainId } from './useChainId.js'
|
|
14
|
+
import { useConfig } from './useConfig.js'
|
|
15
|
+
|
|
16
|
+
export type UseWatchBlockNumberParameters<
|
|
17
|
+
config extends Config = Config,
|
|
18
|
+
chainId extends config['chains'][number]['id'] = config['chains'][number]['id'],
|
|
19
|
+
> = DeepMaybeRef<
|
|
20
|
+
UnionEvaluate<
|
|
21
|
+
UnionPartial<WatchBlockNumberParameters<config, chainId>> &
|
|
22
|
+
ConfigParameter<config> &
|
|
23
|
+
EnabledParameter
|
|
24
|
+
>
|
|
25
|
+
>
|
|
26
|
+
|
|
27
|
+
export type UseWatchBlockNumberReturnType = void
|
|
28
|
+
|
|
29
|
+
/** https://wagmi.sh/vue/api/composables/useWatchBlockNumber */
|
|
30
|
+
export function useWatchBlockNumber<
|
|
31
|
+
config extends Config = ResolvedRegister['config'],
|
|
32
|
+
chainId extends config['chains'][number]['id'] = config['chains'][number]['id'],
|
|
33
|
+
>(
|
|
34
|
+
parameters_: UseWatchBlockNumberParameters<config, chainId> = {} as any,
|
|
35
|
+
): UseWatchBlockNumberReturnType {
|
|
36
|
+
const parameters = computed(() => deepUnref(parameters_))
|
|
37
|
+
|
|
38
|
+
const config = useConfig(parameters)
|
|
39
|
+
const configChainId = useChainId({ config })
|
|
40
|
+
|
|
41
|
+
watchEffect((onCleanup) => {
|
|
42
|
+
const {
|
|
43
|
+
chainId = configChainId.value,
|
|
44
|
+
enabled = true,
|
|
45
|
+
onBlockNumber,
|
|
46
|
+
config: _,
|
|
47
|
+
...rest
|
|
48
|
+
} = parameters.value
|
|
49
|
+
|
|
50
|
+
if (!enabled) return
|
|
51
|
+
if (!onBlockNumber) return
|
|
52
|
+
|
|
53
|
+
const unwatch = watchBlockNumber(config, {
|
|
54
|
+
...(rest as any),
|
|
55
|
+
chainId,
|
|
56
|
+
onBlockNumber,
|
|
57
|
+
emitOnBegin: true,
|
|
58
|
+
})
|
|
59
|
+
onCleanup(unwatch)
|
|
60
|
+
})
|
|
61
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BaseError as CoreError } from '@wagmi/core'
|
|
2
|
+
|
|
3
|
+
import { getVersion } from '../utils/getVersion.js'
|
|
4
|
+
|
|
5
|
+
export type BaseErrorType = BaseError & { name: 'WagmiError' }
|
|
6
|
+
export class BaseError extends CoreError {
|
|
7
|
+
override name = 'WagmiError'
|
|
8
|
+
override get docsBaseUrl() {
|
|
9
|
+
return 'https://wagmi.sh/vue'
|
|
10
|
+
}
|
|
11
|
+
override get version() {
|
|
12
|
+
return getVersion()
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { BaseError } from './base.js'
|
|
2
|
+
|
|
3
|
+
export type WagmiPluginNotFoundErrorType = WagmiPluginNotFoundError & {
|
|
4
|
+
name: 'WagmiPluginNotFoundError'
|
|
5
|
+
}
|
|
6
|
+
export class WagmiPluginNotFoundError extends BaseError {
|
|
7
|
+
override name = 'WagmiPluginNotFoundError'
|
|
8
|
+
constructor() {
|
|
9
|
+
super(
|
|
10
|
+
'No `config` found in Vue context, use `WagmiPlugin` to properly initialize the library.',
|
|
11
|
+
{
|
|
12
|
+
docsPath: '/api/TODO',
|
|
13
|
+
},
|
|
14
|
+
)
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type WagmiInjectionContextErrorType = WagmiInjectionContextError & {
|
|
19
|
+
name: 'WagmiInjectionContextError'
|
|
20
|
+
}
|
|
21
|
+
export class WagmiInjectionContextError extends BaseError {
|
|
22
|
+
override name = 'WagmiInjectionContextError'
|
|
23
|
+
constructor() {
|
|
24
|
+
super(
|
|
25
|
+
'Wagmi composables can only be used inside `setup()` function or functions that support injection context.',
|
|
26
|
+
{
|
|
27
|
+
docsPath: '/api/TODO',
|
|
28
|
+
},
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
}
|