@wagmi/solid 0.0.0-alpha → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/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/context.js +28 -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 +15 -0
- package/dist/esm/errors/context.js.map +1 -0
- package/dist/esm/exports/actions.js +7 -0
- package/dist/esm/exports/actions.js.map +1 -0
- package/dist/esm/exports/chains.js +7 -0
- package/dist/esm/exports/chains.js.map +1 -0
- package/dist/esm/exports/connectors.js +7 -0
- package/dist/esm/exports/connectors.js.map +1 -0
- package/dist/esm/exports/index.js +47 -0
- package/dist/esm/exports/index.js.map +1 -0
- package/dist/esm/exports/query.js +8 -0
- package/dist/esm/exports/query.js.map +1 -0
- package/dist/esm/hydrate.js +19 -0
- package/dist/esm/hydrate.js.map +1 -0
- package/dist/esm/primitives/useBalance.js +16 -0
- package/dist/esm/primitives/useBalance.js.map +1 -0
- package/dist/esm/primitives/useBlockNumber.js +36 -0
- package/dist/esm/primitives/useBlockNumber.js.map +1 -0
- package/dist/esm/primitives/useChainId.js +20 -0
- package/dist/esm/primitives/useChainId.js.map +1 -0
- package/dist/esm/primitives/useChains.js +19 -0
- package/dist/esm/primitives/useChains.js.map +1 -0
- package/dist/esm/primitives/useClient.js +22 -0
- package/dist/esm/primitives/useClient.js.map +1 -0
- package/dist/esm/primitives/useConfig.js +12 -0
- package/dist/esm/primitives/useConfig.js.map +1 -0
- package/dist/esm/primitives/useConnect.js +20 -0
- package/dist/esm/primitives/useConnect.js.map +1 -0
- package/dist/esm/primitives/useConnection.js +20 -0
- package/dist/esm/primitives/useConnection.js.map +1 -0
- package/dist/esm/primitives/useConnectionEffect.js +36 -0
- package/dist/esm/primitives/useConnectionEffect.js.map +1 -0
- package/dist/esm/primitives/useConnections.js +20 -0
- package/dist/esm/primitives/useConnections.js.map +1 -0
- package/dist/esm/primitives/useConnectorClient.js +31 -0
- package/dist/esm/primitives/useConnectorClient.js.map +1 -0
- package/dist/esm/primitives/useConnectors.js +20 -0
- package/dist/esm/primitives/useConnectors.js.map +1 -0
- package/dist/esm/primitives/useDisconnect.js +10 -0
- package/dist/esm/primitives/useDisconnect.js.map +1 -0
- package/dist/esm/primitives/useReconnect.js +10 -0
- package/dist/esm/primitives/useReconnect.js.map +1 -0
- package/dist/esm/primitives/useSwitchChain.js +10 -0
- package/dist/esm/primitives/useSwitchChain.js.map +1 -0
- package/dist/esm/primitives/useSwitchConnection.js +10 -0
- package/dist/esm/primitives/useSwitchConnection.js.map +1 -0
- package/dist/esm/primitives/useWatchBlockNumber.js +23 -0
- package/dist/esm/primitives/useWatchBlockNumber.js.map +1 -0
- package/dist/esm/tsconfig.build.tsbuildinfo +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 +29 -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 +10 -0
- package/dist/types/context.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/context.d.ts +9 -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 +24 -0
- package/dist/types/exports/index.d.ts.map +1 -0
- package/dist/types/exports/query.d.ts +3 -0
- package/dist/types/exports/query.d.ts.map +1 -0
- package/dist/types/hydrate.d.ts +9 -0
- package/dist/types/hydrate.d.ts.map +1 -0
- package/dist/types/primitives/useBalance.d.ts +13 -0
- package/dist/types/primitives/useBalance.d.ts.map +1 -0
- package/dist/types/primitives/useBlockNumber.d.ts +16 -0
- package/dist/types/primitives/useBlockNumber.d.ts.map +1 -0
- package/dist/types/primitives/useChainId.d.ts +12 -0
- package/dist/types/primitives/useChainId.d.ts.map +1 -0
- package/dist/types/primitives/useChains.d.ts +12 -0
- package/dist/types/primitives/useChains.d.ts.map +1 -0
- package/dist/types/primitives/useClient.d.ts +12 -0
- package/dist/types/primitives/useClient.d.ts.map +1 -0
- package/dist/types/primitives/useConfig.d.ts +11 -0
- package/dist/types/primitives/useConfig.d.ts.map +1 -0
- package/dist/types/primitives/useConnect.d.ts +13 -0
- package/dist/types/primitives/useConnect.d.ts.map +1 -0
- package/dist/types/primitives/useConnection.d.ts +12 -0
- package/dist/types/primitives/useConnection.d.ts.map +1 -0
- package/dist/types/primitives/useConnectionEffect.d.ts +17 -0
- package/dist/types/primitives/useConnectionEffect.d.ts.map +1 -0
- package/dist/types/primitives/useConnections.d.ts +12 -0
- package/dist/types/primitives/useConnections.d.ts.map +1 -0
- package/dist/types/primitives/useConnectorClient.d.ts +13 -0
- package/dist/types/primitives/useConnectorClient.d.ts.map +1 -0
- package/dist/types/primitives/useConnectors.d.ts +12 -0
- package/dist/types/primitives/useConnectors.d.ts.map +1 -0
- package/dist/types/primitives/useDisconnect.d.ts +13 -0
- package/dist/types/primitives/useDisconnect.d.ts.map +1 -0
- package/dist/types/primitives/useReconnect.d.ts +13 -0
- package/dist/types/primitives/useReconnect.d.ts.map +1 -0
- package/dist/types/primitives/useSwitchChain.d.ts +13 -0
- package/dist/types/primitives/useSwitchChain.d.ts.map +1 -0
- package/dist/types/primitives/useSwitchConnection.d.ts +13 -0
- package/dist/types/primitives/useSwitchConnection.d.ts.map +1 -0
- package/dist/types/primitives/useWatchBlockNumber.d.ts +11 -0
- package/dist/types/primitives/useWatchBlockNumber.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 +28 -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 +95 -7
- package/query/package.json +5 -0
- package/src/context.ts +43 -0
- package/src/errors/base.ts +14 -0
- package/src/errors/context.ts +13 -0
- package/src/exports/actions.ts +7 -0
- package/src/exports/chains.ts +7 -0
- package/src/exports/connectors.ts +7 -0
- package/src/exports/index.ts +134 -0
- package/src/exports/query.ts +19 -0
- package/src/hydrate.ts +27 -0
- package/src/primitives/useBalance.ts +46 -0
- package/src/primitives/useBlockNumber.ts +99 -0
- package/src/primitives/useChainId.ts +42 -0
- package/src/primitives/useChains.ts +42 -0
- package/src/primitives/useClient.ts +67 -0
- package/src/primitives/useConfig.ts +27 -0
- package/src/primitives/useConnect.ts +63 -0
- package/src/primitives/useConnection.ts +44 -0
- package/src/primitives/useConnectionEffect.ts +66 -0
- package/src/primitives/useConnections.ts +34 -0
- package/src/primitives/useConnectorClient.ts +86 -0
- package/src/primitives/useConnectors.ts +47 -0
- package/src/primitives/useDisconnect.ts +44 -0
- package/src/primitives/useReconnect.ts +44 -0
- package/src/primitives/useSwitchChain.ts +58 -0
- package/src/primitives/useSwitchConnection.ts +60 -0
- package/src/primitives/useWatchBlockNumber.ts +65 -0
- package/src/utils/getVersion.ts +3 -0
- package/src/utils/query.ts +171 -0
- package/src/version.ts +1 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Config,
|
|
3
|
+
type GetClientParameters,
|
|
4
|
+
type GetClientReturnType,
|
|
5
|
+
getClient,
|
|
6
|
+
type ResolvedRegister,
|
|
7
|
+
watchClient,
|
|
8
|
+
} from '@wagmi/core'
|
|
9
|
+
import type { Compute, ConfigParameter } from '@wagmi/core/internal'
|
|
10
|
+
import type { Accessor } from 'solid-js'
|
|
11
|
+
import { createEffect, createSignal, onCleanup } from 'solid-js'
|
|
12
|
+
import { useConfig } from './useConfig.js'
|
|
13
|
+
|
|
14
|
+
/** https://wagmi.sh/solid/api/primitives/useClient */
|
|
15
|
+
export function useClient<
|
|
16
|
+
config extends Config = ResolvedRegister['config'],
|
|
17
|
+
chainId extends config['chains'][number]['id'] | number | undefined =
|
|
18
|
+
| config['chains'][number]['id']
|
|
19
|
+
| undefined,
|
|
20
|
+
>(
|
|
21
|
+
parameters: useClient.Parameters<config, chainId> = () => ({}),
|
|
22
|
+
): useClient.ReturnType<config, chainId> {
|
|
23
|
+
const config = useConfig(parameters)
|
|
24
|
+
const [client, setClient] = createSignal(getClient(config(), parameters()))
|
|
25
|
+
createEffect(() => {
|
|
26
|
+
const _config = config()
|
|
27
|
+
setClient(() => getClient(_config, parameters()))
|
|
28
|
+
const unsubscribe = watchClient(_config, {
|
|
29
|
+
onChange(data) {
|
|
30
|
+
if (client()?.uid === data?.uid) return
|
|
31
|
+
setClient(() => data)
|
|
32
|
+
},
|
|
33
|
+
})
|
|
34
|
+
onCleanup(() => unsubscribe())
|
|
35
|
+
})
|
|
36
|
+
return client as unknown as useClient.ReturnType<config, chainId>
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export namespace useClient {
|
|
40
|
+
export type Parameters<
|
|
41
|
+
config extends Config = Config,
|
|
42
|
+
chainId extends config['chains'][number]['id'] | number | undefined =
|
|
43
|
+
| config['chains'][number]['id']
|
|
44
|
+
| undefined,
|
|
45
|
+
> = Accessor<SolidParameters<config, chainId>>
|
|
46
|
+
|
|
47
|
+
export type ReturnType<
|
|
48
|
+
config extends Config = Config,
|
|
49
|
+
chainId extends config['chains'][number]['id'] | number | undefined =
|
|
50
|
+
| config['chains'][number]['id']
|
|
51
|
+
| undefined,
|
|
52
|
+
> = Accessor<SolidReturnType<config, chainId>>
|
|
53
|
+
|
|
54
|
+
export type SolidParameters<
|
|
55
|
+
config extends Config = Config,
|
|
56
|
+
chainId extends config['chains'][number]['id'] | number | undefined =
|
|
57
|
+
| config['chains'][number]['id']
|
|
58
|
+
| undefined,
|
|
59
|
+
> = Compute<GetClientParameters<config, chainId> & ConfigParameter<config>>
|
|
60
|
+
|
|
61
|
+
export type SolidReturnType<
|
|
62
|
+
config extends Config = Config,
|
|
63
|
+
chainId extends config['chains'][number]['id'] | number | undefined =
|
|
64
|
+
| config['chains'][number]['id']
|
|
65
|
+
| undefined,
|
|
66
|
+
> = GetClientReturnType<config, chainId>
|
|
67
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Config, ResolvedRegister } from '@wagmi/core'
|
|
2
|
+
import type { ConfigParameter } from '@wagmi/core/internal'
|
|
3
|
+
import { type Accessor, createMemo, useContext } from 'solid-js'
|
|
4
|
+
import { WagmiContext } from '../context.js'
|
|
5
|
+
import { WagmiProviderNotFoundError } from '../errors/context.js'
|
|
6
|
+
|
|
7
|
+
export function useConfig<config extends Config = ResolvedRegister['config']>(
|
|
8
|
+
parameters: useConfig.Parameters<config> = () => ({}),
|
|
9
|
+
): useConfig.ReturnType<config> {
|
|
10
|
+
return createMemo(() => {
|
|
11
|
+
const config = parameters().config ?? useContext(WagmiContext)
|
|
12
|
+
if (!config) throw new WagmiProviderNotFoundError()
|
|
13
|
+
return config as config
|
|
14
|
+
})
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export namespace useConfig {
|
|
18
|
+
export type Parameters<config extends Config = Config> = Accessor<
|
|
19
|
+
SolidParameters<config>
|
|
20
|
+
>
|
|
21
|
+
export type ReturnType<config extends Config = Config> = Accessor<
|
|
22
|
+
SolidReturnType<config>
|
|
23
|
+
>
|
|
24
|
+
export type SolidParameters<config extends Config = Config> =
|
|
25
|
+
ConfigParameter<config>
|
|
26
|
+
export type SolidReturnType<config extends Config = Config> = config
|
|
27
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { Config, ConnectErrorType } from '@wagmi/core'
|
|
2
|
+
import type { Compute, ConfigParameter } from '@wagmi/core/internal'
|
|
3
|
+
import {
|
|
4
|
+
type ConnectData,
|
|
5
|
+
type ConnectMutate,
|
|
6
|
+
type ConnectMutateAsync,
|
|
7
|
+
type ConnectOptions,
|
|
8
|
+
type ConnectVariables,
|
|
9
|
+
connectMutationOptions,
|
|
10
|
+
} from '@wagmi/core/query'
|
|
11
|
+
import { type Accessor, createEffect, onCleanup } from 'solid-js'
|
|
12
|
+
import type { UseMutationReturnType } from '../utils/query.js'
|
|
13
|
+
import { useMutation } from '../utils/query.js'
|
|
14
|
+
import { useConfig } from './useConfig.js'
|
|
15
|
+
|
|
16
|
+
/** https://wagmi.sh/solid/api/hooks/useConnect */
|
|
17
|
+
export function useConnect<config extends Config = Config, context = unknown>(
|
|
18
|
+
parameters: useConnect.Parameters<config, context> = () => ({}),
|
|
19
|
+
): useConnect.ReturnType<config, context> {
|
|
20
|
+
const config = useConfig(parameters)
|
|
21
|
+
const mutation = useMutation(() =>
|
|
22
|
+
connectMutationOptions(config(), parameters()),
|
|
23
|
+
)
|
|
24
|
+
// Reset mutation back to an idle state when the connector disconnects.
|
|
25
|
+
createEffect(() => {
|
|
26
|
+
const unsubscribe = config().subscribe(
|
|
27
|
+
({ status }) => status,
|
|
28
|
+
(status, previousStatus) => {
|
|
29
|
+
if (previousStatus === 'connected' && status === 'disconnected') {
|
|
30
|
+
mutation.reset()
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
)
|
|
34
|
+
onCleanup(() => unsubscribe())
|
|
35
|
+
})
|
|
36
|
+
return mutation as unknown as useConnect.ReturnType<config, context>
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export namespace useConnect {
|
|
40
|
+
export type Parameters<
|
|
41
|
+
config extends Config = Config,
|
|
42
|
+
context = unknown,
|
|
43
|
+
> = Accessor<SolidParameters<config, context>>
|
|
44
|
+
|
|
45
|
+
export type ReturnType<
|
|
46
|
+
config extends Config = Config,
|
|
47
|
+
context = unknown,
|
|
48
|
+
> = Compute<
|
|
49
|
+
UseMutationReturnType<
|
|
50
|
+
ConnectData<config, config['connectors'][number], boolean>,
|
|
51
|
+
ConnectErrorType,
|
|
52
|
+
ConnectVariables<config, config['connectors'][number], boolean>,
|
|
53
|
+
context,
|
|
54
|
+
ConnectMutate<config, context>,
|
|
55
|
+
ConnectMutateAsync<config, context>
|
|
56
|
+
>
|
|
57
|
+
>
|
|
58
|
+
|
|
59
|
+
export type SolidParameters<
|
|
60
|
+
config extends Config = Config,
|
|
61
|
+
context = unknown,
|
|
62
|
+
> = Compute<ConfigParameter<config> & ConnectOptions<config, context>>
|
|
63
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Config,
|
|
3
|
+
type GetConnectionReturnType,
|
|
4
|
+
getConnection,
|
|
5
|
+
type ResolvedRegister,
|
|
6
|
+
watchConnection,
|
|
7
|
+
} from '@wagmi/core'
|
|
8
|
+
import type { ConfigParameter } from '@wagmi/core/internal'
|
|
9
|
+
import { type Accessor, createEffect, createSignal, onCleanup } from 'solid-js'
|
|
10
|
+
import { useConfig } from './useConfig.js'
|
|
11
|
+
|
|
12
|
+
/** https://wagmi.sh/solid/api/primitives/useConnection */
|
|
13
|
+
export function useConnection<
|
|
14
|
+
config extends Config = ResolvedRegister['config'],
|
|
15
|
+
>(
|
|
16
|
+
parameters: useConnection.Parameters<config> = () => ({}),
|
|
17
|
+
): useConnection.ReturnType<config> {
|
|
18
|
+
const config = useConfig(parameters)
|
|
19
|
+
const [connection, setConnection] = createSignal(getConnection(config()))
|
|
20
|
+
createEffect(() => {
|
|
21
|
+
const _config = config()
|
|
22
|
+
setConnection(() => getConnection(_config))
|
|
23
|
+
const unsubscribe = watchConnection(_config, {
|
|
24
|
+
onChange(data) {
|
|
25
|
+
setConnection(() => data)
|
|
26
|
+
},
|
|
27
|
+
})
|
|
28
|
+
onCleanup(() => unsubscribe())
|
|
29
|
+
})
|
|
30
|
+
return connection
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export namespace useConnection {
|
|
34
|
+
export type Parameters<config extends Config = Config> = Accessor<
|
|
35
|
+
SolidParameters<config>
|
|
36
|
+
>
|
|
37
|
+
export type ReturnType<config extends Config = Config> = Accessor<
|
|
38
|
+
SolidReturnType<config>
|
|
39
|
+
>
|
|
40
|
+
export type SolidParameters<config extends Config = Config> =
|
|
41
|
+
ConfigParameter<config>
|
|
42
|
+
export type SolidReturnType<config extends Config = Config> =
|
|
43
|
+
GetConnectionReturnType<config>
|
|
44
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { type GetConnectionReturnType, watchConnection } from '@wagmi/core'
|
|
2
|
+
import type { Compute, ConfigParameter } from '@wagmi/core/internal'
|
|
3
|
+
import type { Accessor } from 'solid-js'
|
|
4
|
+
import { createEffect, onCleanup } from 'solid-js'
|
|
5
|
+
import { useConfig } from './useConfig.js'
|
|
6
|
+
|
|
7
|
+
/** https://wagmi.sh/solid/api/primitives/useConnectionEffect */
|
|
8
|
+
export function useConnectionEffect(
|
|
9
|
+
parameters: useConnectionEffect.Parameters = () => ({}),
|
|
10
|
+
) {
|
|
11
|
+
const config = useConfig(parameters)
|
|
12
|
+
|
|
13
|
+
createEffect(() => {
|
|
14
|
+
const { onConnect, onDisconnect } = parameters()
|
|
15
|
+
|
|
16
|
+
const unsubscribe = watchConnection(config(), {
|
|
17
|
+
onChange(data, prevData) {
|
|
18
|
+
if (
|
|
19
|
+
(prevData.status === 'reconnecting' ||
|
|
20
|
+
(prevData.status === 'connecting' &&
|
|
21
|
+
prevData.address === undefined)) &&
|
|
22
|
+
data.status === 'connected'
|
|
23
|
+
) {
|
|
24
|
+
const { address, addresses, chain, chainId, connector } = data
|
|
25
|
+
const isReconnected =
|
|
26
|
+
prevData.status === 'reconnecting' ||
|
|
27
|
+
// if `previousAccount.status` is `undefined`, the connector connected immediately.
|
|
28
|
+
prevData.status === undefined
|
|
29
|
+
onConnect?.({
|
|
30
|
+
address,
|
|
31
|
+
addresses,
|
|
32
|
+
chain,
|
|
33
|
+
chainId,
|
|
34
|
+
connector,
|
|
35
|
+
isReconnected,
|
|
36
|
+
})
|
|
37
|
+
} else if (
|
|
38
|
+
prevData.status === 'connected' &&
|
|
39
|
+
data.status === 'disconnected'
|
|
40
|
+
)
|
|
41
|
+
onDisconnect?.()
|
|
42
|
+
},
|
|
43
|
+
})
|
|
44
|
+
onCleanup(() => unsubscribe())
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export namespace useConnectionEffect {
|
|
49
|
+
export type Parameters = Accessor<SolidParameters>
|
|
50
|
+
|
|
51
|
+
export type SolidParameters = Compute<
|
|
52
|
+
{
|
|
53
|
+
onConnect?(
|
|
54
|
+
data: Compute<
|
|
55
|
+
Pick<
|
|
56
|
+
Extract<GetConnectionReturnType, { status: 'connected' }>,
|
|
57
|
+
'address' | 'addresses' | 'chain' | 'chainId' | 'connector'
|
|
58
|
+
> & {
|
|
59
|
+
isReconnected: boolean
|
|
60
|
+
}
|
|
61
|
+
>,
|
|
62
|
+
): void
|
|
63
|
+
onDisconnect?(): void
|
|
64
|
+
} & ConfigParameter
|
|
65
|
+
>
|
|
66
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type GetConnectionsReturnType,
|
|
3
|
+
getConnections,
|
|
4
|
+
watchConnections,
|
|
5
|
+
} from '@wagmi/core'
|
|
6
|
+
import type { ConfigParameter } from '@wagmi/core/internal'
|
|
7
|
+
import { type Accessor, createEffect, createSignal, onCleanup } from 'solid-js'
|
|
8
|
+
import { useConfig } from './useConfig.js'
|
|
9
|
+
|
|
10
|
+
/** https://wagmi.sh/solid/api/primitives/useConnections */
|
|
11
|
+
export function useConnections(
|
|
12
|
+
parameters: useConnections.Parameters = () => ({}),
|
|
13
|
+
): useConnections.ReturnType {
|
|
14
|
+
const config = useConfig(parameters)
|
|
15
|
+
const [connections, setConnections] = createSignal(getConnections(config()))
|
|
16
|
+
createEffect(() => {
|
|
17
|
+
const _config = config()
|
|
18
|
+
setConnections(() => getConnections(_config))
|
|
19
|
+
const unsubscribe = watchConnections(_config, {
|
|
20
|
+
onChange(data) {
|
|
21
|
+
setConnections(() => data)
|
|
22
|
+
},
|
|
23
|
+
})
|
|
24
|
+
onCleanup(() => unsubscribe())
|
|
25
|
+
})
|
|
26
|
+
return connections
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export namespace useConnections {
|
|
30
|
+
export type Parameters = Accessor<SolidParameters>
|
|
31
|
+
export type ReturnType = Accessor<SolidReturnType>
|
|
32
|
+
export type SolidParameters = ConfigParameter
|
|
33
|
+
export type SolidReturnType = GetConnectionsReturnType
|
|
34
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { useQueryClient } from '@tanstack/solid-query'
|
|
2
|
+
import type {
|
|
3
|
+
Config,
|
|
4
|
+
GetConnectorClientErrorType,
|
|
5
|
+
ResolvedRegister,
|
|
6
|
+
} from '@wagmi/core'
|
|
7
|
+
import type { Compute, ConfigParameter } from '@wagmi/core/internal'
|
|
8
|
+
import {
|
|
9
|
+
type GetConnectorClientData,
|
|
10
|
+
type GetConnectorClientOptions,
|
|
11
|
+
getConnectorClientQueryOptions,
|
|
12
|
+
} from '@wagmi/core/query'
|
|
13
|
+
import type { Accessor } from 'solid-js'
|
|
14
|
+
import { createEffect, createMemo, on } from 'solid-js'
|
|
15
|
+
import { type UseQueryReturnType, useQuery } from '../utils/query.js'
|
|
16
|
+
import { useChainId } from './useChainId.js'
|
|
17
|
+
import { useConfig } from './useConfig.js'
|
|
18
|
+
import { useConnection } from './useConnection.js'
|
|
19
|
+
|
|
20
|
+
/** https://wagmi.sh/solid/api/primitives/useConnectorClient */
|
|
21
|
+
export function useConnectorClient<
|
|
22
|
+
config extends Config = ResolvedRegister['config'],
|
|
23
|
+
chainId extends
|
|
24
|
+
config['chains'][number]['id'] = config['chains'][number]['id'],
|
|
25
|
+
selectData = GetConnectorClientData<config, chainId>,
|
|
26
|
+
>(
|
|
27
|
+
parameters: useConnectorClient.Parameters<
|
|
28
|
+
config,
|
|
29
|
+
chainId,
|
|
30
|
+
selectData
|
|
31
|
+
> = () => ({}),
|
|
32
|
+
): useConnectorClient.ReturnType<config, chainId, selectData> {
|
|
33
|
+
const config = useConfig(parameters)
|
|
34
|
+
const chainId = useChainId(() => ({ config: config() }))
|
|
35
|
+
const connection = useConnection(() => ({ config: config() }))
|
|
36
|
+
const options = createMemo(() =>
|
|
37
|
+
getConnectorClientQueryOptions<config, chainId>(config(), {
|
|
38
|
+
...(parameters() as any),
|
|
39
|
+
chainId: parameters().chainId ?? chainId(),
|
|
40
|
+
connector: parameters().connector ?? connection().connector,
|
|
41
|
+
}),
|
|
42
|
+
)
|
|
43
|
+
const queryClient = useQueryClient()
|
|
44
|
+
createEffect(
|
|
45
|
+
on(
|
|
46
|
+
() => connection().address,
|
|
47
|
+
(currentAddress, previousAddress) => {
|
|
48
|
+
if (!currentAddress && previousAddress) {
|
|
49
|
+
// remove when account is disconnected
|
|
50
|
+
queryClient.removeQueries({ queryKey: options().queryKey })
|
|
51
|
+
} else if (currentAddress !== previousAddress) {
|
|
52
|
+
// invalidate when address changes
|
|
53
|
+
queryClient.invalidateQueries({ queryKey: options().queryKey })
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
{ defer: true },
|
|
57
|
+
),
|
|
58
|
+
)
|
|
59
|
+
return useQuery(options) as any
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export namespace useConnectorClient {
|
|
63
|
+
export type Parameters<
|
|
64
|
+
config extends Config = Config,
|
|
65
|
+
chainId extends
|
|
66
|
+
config['chains'][number]['id'] = config['chains'][number]['id'],
|
|
67
|
+
selectData = GetConnectorClientData<config, chainId>,
|
|
68
|
+
> = Accessor<SolidParameters<config, chainId, selectData>>
|
|
69
|
+
|
|
70
|
+
export type ReturnType<
|
|
71
|
+
config extends Config = Config,
|
|
72
|
+
chainId extends
|
|
73
|
+
config['chains'][number]['id'] = config['chains'][number]['id'],
|
|
74
|
+
selectData = GetConnectorClientData<config, chainId>,
|
|
75
|
+
> = UseQueryReturnType<selectData, GetConnectorClientErrorType>
|
|
76
|
+
|
|
77
|
+
export type SolidParameters<
|
|
78
|
+
config extends Config = Config,
|
|
79
|
+
chainId extends
|
|
80
|
+
config['chains'][number]['id'] = config['chains'][number]['id'],
|
|
81
|
+
selectData = GetConnectorClientData<config, chainId>,
|
|
82
|
+
> = Compute<
|
|
83
|
+
GetConnectorClientOptions<config, chainId, selectData> &
|
|
84
|
+
ConfigParameter<config>
|
|
85
|
+
>
|
|
86
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Config,
|
|
3
|
+
type GetConnectorsReturnType,
|
|
4
|
+
getConnectors,
|
|
5
|
+
type ResolvedRegister,
|
|
6
|
+
watchConnectors,
|
|
7
|
+
} from '@wagmi/core'
|
|
8
|
+
import { type Accessor, createEffect, createSignal, onCleanup } from 'solid-js'
|
|
9
|
+
import { useConfig } from './useConfig.js'
|
|
10
|
+
|
|
11
|
+
/** https://wagmi.sh/solid/api/primitives/useConnectors */
|
|
12
|
+
export function useConnectors<
|
|
13
|
+
config extends Config = ResolvedRegister['config'],
|
|
14
|
+
>(
|
|
15
|
+
parameters: useConnectors.Parameters<config> = () => ({}),
|
|
16
|
+
): useConnectors.ReturnType<config> {
|
|
17
|
+
const config = useConfig(parameters)
|
|
18
|
+
const [connectors, setConnectors] = createSignal(getConnectors(config()))
|
|
19
|
+
createEffect(() => {
|
|
20
|
+
const _config = config()
|
|
21
|
+
setConnectors(() => getConnectors(_config))
|
|
22
|
+
|
|
23
|
+
const unsubscribe = watchConnectors(_config, {
|
|
24
|
+
onChange(data) {
|
|
25
|
+
setConnectors(() => data)
|
|
26
|
+
},
|
|
27
|
+
})
|
|
28
|
+
onCleanup(() => unsubscribe())
|
|
29
|
+
})
|
|
30
|
+
return connectors
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export namespace useConnectors {
|
|
34
|
+
export type Parameters<config extends Config = Config> = Accessor<
|
|
35
|
+
SolidParameters<config>
|
|
36
|
+
>
|
|
37
|
+
|
|
38
|
+
export type ReturnType<config extends Config = Config> = Accessor<
|
|
39
|
+
SolidReturnType<config>
|
|
40
|
+
>
|
|
41
|
+
|
|
42
|
+
export type SolidParameters<config extends Config = Config> =
|
|
43
|
+
useConfig.SolidParameters<config>
|
|
44
|
+
|
|
45
|
+
export type SolidReturnType<config extends Config = Config> =
|
|
46
|
+
GetConnectorsReturnType<config>
|
|
47
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { createMutation as useMutation } from '@tanstack/solid-query'
|
|
2
|
+
import type { DisconnectErrorType } from '@wagmi/core'
|
|
3
|
+
import type { Compute, ConfigParameter } from '@wagmi/core/internal'
|
|
4
|
+
import {
|
|
5
|
+
type DisconnectData,
|
|
6
|
+
type DisconnectMutate,
|
|
7
|
+
type DisconnectMutateAsync,
|
|
8
|
+
type DisconnectOptions,
|
|
9
|
+
type DisconnectVariables,
|
|
10
|
+
disconnectMutationOptions,
|
|
11
|
+
} from '@wagmi/core/query'
|
|
12
|
+
import type { Accessor } from 'solid-js'
|
|
13
|
+
import type { UseMutationReturnType } from '../utils/query.js'
|
|
14
|
+
import { useConfig } from './useConfig.js'
|
|
15
|
+
|
|
16
|
+
/** https://wagmi.sh/solid/api/primitives/useDisconnect */
|
|
17
|
+
export function useDisconnect<context = unknown>(
|
|
18
|
+
parameters: useDisconnect.Parameters<context> = () => ({}),
|
|
19
|
+
): useDisconnect.ReturnType<context> {
|
|
20
|
+
const config = useConfig(parameters)
|
|
21
|
+
const mutation = useMutation(() =>
|
|
22
|
+
disconnectMutationOptions(config(), parameters()),
|
|
23
|
+
)
|
|
24
|
+
return mutation as useDisconnect.ReturnType<context>
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export namespace useDisconnect {
|
|
28
|
+
export type Parameters<context = unknown> = Accessor<SolidParameters<context>>
|
|
29
|
+
|
|
30
|
+
export type ReturnType<context = unknown> = Compute<
|
|
31
|
+
UseMutationReturnType<
|
|
32
|
+
DisconnectData,
|
|
33
|
+
DisconnectErrorType,
|
|
34
|
+
DisconnectVariables,
|
|
35
|
+
context,
|
|
36
|
+
DisconnectMutate<context>,
|
|
37
|
+
DisconnectMutateAsync<context>
|
|
38
|
+
>
|
|
39
|
+
>
|
|
40
|
+
|
|
41
|
+
export type SolidParameters<context = unknown> = Compute<
|
|
42
|
+
ConfigParameter & DisconnectOptions<context>
|
|
43
|
+
>
|
|
44
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { createMutation as useMutation } from '@tanstack/solid-query'
|
|
2
|
+
import type { ReconnectErrorType } from '@wagmi/core'
|
|
3
|
+
import type { Compute, ConfigParameter } from '@wagmi/core/internal'
|
|
4
|
+
import {
|
|
5
|
+
type ReconnectData,
|
|
6
|
+
type ReconnectMutate,
|
|
7
|
+
type ReconnectMutateAsync,
|
|
8
|
+
type ReconnectOptions,
|
|
9
|
+
type ReconnectVariables,
|
|
10
|
+
reconnectMutationOptions,
|
|
11
|
+
} from '@wagmi/core/query'
|
|
12
|
+
import type { Accessor } from 'solid-js'
|
|
13
|
+
import type { UseMutationReturnType } from '../utils/query.js'
|
|
14
|
+
import { useConfig } from './useConfig.js'
|
|
15
|
+
|
|
16
|
+
/** https://wagmi.sh/solid/api/primitives/useReconnect */
|
|
17
|
+
export function useReconnect<context = unknown>(
|
|
18
|
+
parameters: useReconnect.Parameters<context> = () => ({}),
|
|
19
|
+
): useReconnect.ReturnType<context> {
|
|
20
|
+
const config = useConfig(parameters)
|
|
21
|
+
const mutation = useMutation(() =>
|
|
22
|
+
reconnectMutationOptions(config(), parameters()),
|
|
23
|
+
)
|
|
24
|
+
return mutation as useReconnect.ReturnType<context>
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export namespace useReconnect {
|
|
28
|
+
export type Parameters<context = unknown> = Accessor<SolidParameters<context>>
|
|
29
|
+
|
|
30
|
+
export type ReturnType<context = unknown> = Compute<
|
|
31
|
+
UseMutationReturnType<
|
|
32
|
+
ReconnectData,
|
|
33
|
+
ReconnectErrorType,
|
|
34
|
+
ReconnectVariables,
|
|
35
|
+
context,
|
|
36
|
+
ReconnectMutate<context>,
|
|
37
|
+
ReconnectMutateAsync<context>
|
|
38
|
+
>
|
|
39
|
+
>
|
|
40
|
+
|
|
41
|
+
export type SolidParameters<context = unknown> = Compute<
|
|
42
|
+
ConfigParameter & ReconnectOptions<context>
|
|
43
|
+
>
|
|
44
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { createMutation as useMutation } from '@tanstack/solid-query'
|
|
2
|
+
import type {
|
|
3
|
+
Config,
|
|
4
|
+
ResolvedRegister,
|
|
5
|
+
SwitchChainErrorType,
|
|
6
|
+
} from '@wagmi/core'
|
|
7
|
+
import type { Compute, ConfigParameter } from '@wagmi/core/internal'
|
|
8
|
+
import {
|
|
9
|
+
type SwitchChainData,
|
|
10
|
+
type SwitchChainMutate,
|
|
11
|
+
type SwitchChainMutateAsync,
|
|
12
|
+
type SwitchChainOptions,
|
|
13
|
+
type SwitchChainVariables,
|
|
14
|
+
switchChainMutationOptions,
|
|
15
|
+
} from '@wagmi/core/query'
|
|
16
|
+
import type { Accessor } from 'solid-js'
|
|
17
|
+
import type { UseMutationReturnType } from '../utils/query.js'
|
|
18
|
+
import { useConfig } from './useConfig.js'
|
|
19
|
+
|
|
20
|
+
/** https://wagmi.sh/solid/api/primitives/useSwitchChain */
|
|
21
|
+
export function useSwitchChain<
|
|
22
|
+
config extends Config = ResolvedRegister['config'],
|
|
23
|
+
context = unknown,
|
|
24
|
+
>(
|
|
25
|
+
parameters: useSwitchChain.Parameters<config, context> = () => ({}),
|
|
26
|
+
): useSwitchChain.ReturnType<config, context> {
|
|
27
|
+
const config = useConfig(parameters)
|
|
28
|
+
const mutation = useMutation(() =>
|
|
29
|
+
switchChainMutationOptions(config(), parameters()),
|
|
30
|
+
)
|
|
31
|
+
return mutation as useSwitchChain.ReturnType<config, context>
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export namespace useSwitchChain {
|
|
35
|
+
export type Parameters<
|
|
36
|
+
config extends Config = Config,
|
|
37
|
+
context = unknown,
|
|
38
|
+
> = Accessor<SolidParameters<config, context>>
|
|
39
|
+
|
|
40
|
+
export type ReturnType<
|
|
41
|
+
config extends Config = Config,
|
|
42
|
+
context = unknown,
|
|
43
|
+
> = Compute<
|
|
44
|
+
UseMutationReturnType<
|
|
45
|
+
SwitchChainData<config, config['chains'][number]['id']>,
|
|
46
|
+
SwitchChainErrorType,
|
|
47
|
+
SwitchChainVariables<config, config['chains'][number]['id']>,
|
|
48
|
+
context,
|
|
49
|
+
SwitchChainMutate<config, context>,
|
|
50
|
+
SwitchChainMutateAsync<config, context>
|
|
51
|
+
>
|
|
52
|
+
>
|
|
53
|
+
|
|
54
|
+
export type SolidParameters<
|
|
55
|
+
config extends Config = Config,
|
|
56
|
+
context = unknown,
|
|
57
|
+
> = Compute<ConfigParameter<config> & SwitchChainOptions<config, context>>
|
|
58
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { createMutation as useMutation } from '@tanstack/solid-query'
|
|
2
|
+
import type {
|
|
3
|
+
Config,
|
|
4
|
+
ResolvedRegister,
|
|
5
|
+
SwitchConnectionErrorType,
|
|
6
|
+
} from '@wagmi/core'
|
|
7
|
+
import type { Compute, ConfigParameter } from '@wagmi/core/internal'
|
|
8
|
+
import {
|
|
9
|
+
type SwitchConnectionData,
|
|
10
|
+
type SwitchConnectionMutate,
|
|
11
|
+
type SwitchConnectionMutateAsync,
|
|
12
|
+
type SwitchConnectionOptions,
|
|
13
|
+
type SwitchConnectionVariables,
|
|
14
|
+
switchConnectionMutationOptions,
|
|
15
|
+
} from '@wagmi/core/query'
|
|
16
|
+
import type { Accessor } from 'solid-js'
|
|
17
|
+
import type { UseMutationReturnType } from '../utils/query.js'
|
|
18
|
+
import { useConfig } from './useConfig.js'
|
|
19
|
+
|
|
20
|
+
/** https://wagmi.sh/solid/api/primitives/useSwitchConnection */
|
|
21
|
+
export function useSwitchConnection<
|
|
22
|
+
config extends Config = ResolvedRegister['config'],
|
|
23
|
+
context = unknown,
|
|
24
|
+
>(
|
|
25
|
+
parameters: useSwitchConnection.Parameters<config, context> = () => ({}),
|
|
26
|
+
): useSwitchConnection.ReturnType<config, context> {
|
|
27
|
+
const config = useConfig<config>(parameters)
|
|
28
|
+
const mutation = useMutation(() =>
|
|
29
|
+
switchConnectionMutationOptions(config(), parameters()),
|
|
30
|
+
)
|
|
31
|
+
return mutation as useSwitchConnection.ReturnType<config, context>
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export namespace useSwitchConnection {
|
|
35
|
+
export type Parameters<
|
|
36
|
+
config extends Config = Config,
|
|
37
|
+
context = unknown,
|
|
38
|
+
> = Accessor<SolidParameters<config, context>>
|
|
39
|
+
|
|
40
|
+
export type ReturnType<
|
|
41
|
+
config extends Config = Config,
|
|
42
|
+
context = unknown,
|
|
43
|
+
> = Compute<
|
|
44
|
+
UseMutationReturnType<
|
|
45
|
+
SwitchConnectionData<config>,
|
|
46
|
+
SwitchConnectionErrorType,
|
|
47
|
+
SwitchConnectionVariables,
|
|
48
|
+
context,
|
|
49
|
+
SwitchConnectionMutate<config, context>,
|
|
50
|
+
SwitchConnectionMutateAsync<config, context>
|
|
51
|
+
>
|
|
52
|
+
>
|
|
53
|
+
|
|
54
|
+
export type SolidParameters<
|
|
55
|
+
config extends Config = Config,
|
|
56
|
+
context = unknown,
|
|
57
|
+
> = Compute<
|
|
58
|
+
ConfigParameter<config> & SwitchConnectionOptions<config, context>
|
|
59
|
+
>
|
|
60
|
+
}
|