@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.
Files changed (153) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +14 -0
  3. package/actions/package.json +5 -0
  4. package/chains/package.json +5 -0
  5. package/connectors/package.json +5 -0
  6. package/dist/esm/context.js +28 -0
  7. package/dist/esm/context.js.map +1 -0
  8. package/dist/esm/errors/base.js +20 -0
  9. package/dist/esm/errors/base.js.map +1 -0
  10. package/dist/esm/errors/context.js +15 -0
  11. package/dist/esm/errors/context.js.map +1 -0
  12. package/dist/esm/exports/actions.js +7 -0
  13. package/dist/esm/exports/actions.js.map +1 -0
  14. package/dist/esm/exports/chains.js +7 -0
  15. package/dist/esm/exports/chains.js.map +1 -0
  16. package/dist/esm/exports/connectors.js +7 -0
  17. package/dist/esm/exports/connectors.js.map +1 -0
  18. package/dist/esm/exports/index.js +47 -0
  19. package/dist/esm/exports/index.js.map +1 -0
  20. package/dist/esm/exports/query.js +8 -0
  21. package/dist/esm/exports/query.js.map +1 -0
  22. package/dist/esm/hydrate.js +19 -0
  23. package/dist/esm/hydrate.js.map +1 -0
  24. package/dist/esm/primitives/useBalance.js +16 -0
  25. package/dist/esm/primitives/useBalance.js.map +1 -0
  26. package/dist/esm/primitives/useBlockNumber.js +36 -0
  27. package/dist/esm/primitives/useBlockNumber.js.map +1 -0
  28. package/dist/esm/primitives/useChainId.js +20 -0
  29. package/dist/esm/primitives/useChainId.js.map +1 -0
  30. package/dist/esm/primitives/useChains.js +19 -0
  31. package/dist/esm/primitives/useChains.js.map +1 -0
  32. package/dist/esm/primitives/useClient.js +22 -0
  33. package/dist/esm/primitives/useClient.js.map +1 -0
  34. package/dist/esm/primitives/useConfig.js +12 -0
  35. package/dist/esm/primitives/useConfig.js.map +1 -0
  36. package/dist/esm/primitives/useConnect.js +20 -0
  37. package/dist/esm/primitives/useConnect.js.map +1 -0
  38. package/dist/esm/primitives/useConnection.js +20 -0
  39. package/dist/esm/primitives/useConnection.js.map +1 -0
  40. package/dist/esm/primitives/useConnectionEffect.js +36 -0
  41. package/dist/esm/primitives/useConnectionEffect.js.map +1 -0
  42. package/dist/esm/primitives/useConnections.js +20 -0
  43. package/dist/esm/primitives/useConnections.js.map +1 -0
  44. package/dist/esm/primitives/useConnectorClient.js +31 -0
  45. package/dist/esm/primitives/useConnectorClient.js.map +1 -0
  46. package/dist/esm/primitives/useConnectors.js +20 -0
  47. package/dist/esm/primitives/useConnectors.js.map +1 -0
  48. package/dist/esm/primitives/useDisconnect.js +10 -0
  49. package/dist/esm/primitives/useDisconnect.js.map +1 -0
  50. package/dist/esm/primitives/useReconnect.js +10 -0
  51. package/dist/esm/primitives/useReconnect.js.map +1 -0
  52. package/dist/esm/primitives/useSwitchChain.js +10 -0
  53. package/dist/esm/primitives/useSwitchChain.js.map +1 -0
  54. package/dist/esm/primitives/useSwitchConnection.js +10 -0
  55. package/dist/esm/primitives/useSwitchConnection.js.map +1 -0
  56. package/dist/esm/primitives/useWatchBlockNumber.js +23 -0
  57. package/dist/esm/primitives/useWatchBlockNumber.js.map +1 -0
  58. package/dist/esm/tsconfig.build.tsbuildinfo +1 -0
  59. package/dist/esm/utils/getVersion.js +3 -0
  60. package/dist/esm/utils/getVersion.js.map +1 -0
  61. package/dist/esm/utils/query.js +29 -0
  62. package/dist/esm/utils/query.js.map +1 -0
  63. package/dist/esm/version.js +2 -0
  64. package/dist/esm/version.js.map +1 -0
  65. package/dist/types/context.d.ts +10 -0
  66. package/dist/types/context.d.ts.map +1 -0
  67. package/dist/types/errors/base.d.ts +10 -0
  68. package/dist/types/errors/base.d.ts.map +1 -0
  69. package/dist/types/errors/context.d.ts +9 -0
  70. package/dist/types/errors/context.d.ts.map +1 -0
  71. package/dist/types/exports/actions.d.ts +2 -0
  72. package/dist/types/exports/actions.d.ts.map +1 -0
  73. package/dist/types/exports/chains.d.ts +2 -0
  74. package/dist/types/exports/chains.d.ts.map +1 -0
  75. package/dist/types/exports/connectors.d.ts +2 -0
  76. package/dist/types/exports/connectors.d.ts.map +1 -0
  77. package/dist/types/exports/index.d.ts +24 -0
  78. package/dist/types/exports/index.d.ts.map +1 -0
  79. package/dist/types/exports/query.d.ts +3 -0
  80. package/dist/types/exports/query.d.ts.map +1 -0
  81. package/dist/types/hydrate.d.ts +9 -0
  82. package/dist/types/hydrate.d.ts.map +1 -0
  83. package/dist/types/primitives/useBalance.d.ts +13 -0
  84. package/dist/types/primitives/useBalance.d.ts.map +1 -0
  85. package/dist/types/primitives/useBlockNumber.d.ts +16 -0
  86. package/dist/types/primitives/useBlockNumber.d.ts.map +1 -0
  87. package/dist/types/primitives/useChainId.d.ts +12 -0
  88. package/dist/types/primitives/useChainId.d.ts.map +1 -0
  89. package/dist/types/primitives/useChains.d.ts +12 -0
  90. package/dist/types/primitives/useChains.d.ts.map +1 -0
  91. package/dist/types/primitives/useClient.d.ts +12 -0
  92. package/dist/types/primitives/useClient.d.ts.map +1 -0
  93. package/dist/types/primitives/useConfig.d.ts +11 -0
  94. package/dist/types/primitives/useConfig.d.ts.map +1 -0
  95. package/dist/types/primitives/useConnect.d.ts +13 -0
  96. package/dist/types/primitives/useConnect.d.ts.map +1 -0
  97. package/dist/types/primitives/useConnection.d.ts +12 -0
  98. package/dist/types/primitives/useConnection.d.ts.map +1 -0
  99. package/dist/types/primitives/useConnectionEffect.d.ts +17 -0
  100. package/dist/types/primitives/useConnectionEffect.d.ts.map +1 -0
  101. package/dist/types/primitives/useConnections.d.ts +12 -0
  102. package/dist/types/primitives/useConnections.d.ts.map +1 -0
  103. package/dist/types/primitives/useConnectorClient.d.ts +13 -0
  104. package/dist/types/primitives/useConnectorClient.d.ts.map +1 -0
  105. package/dist/types/primitives/useConnectors.d.ts +12 -0
  106. package/dist/types/primitives/useConnectors.d.ts.map +1 -0
  107. package/dist/types/primitives/useDisconnect.d.ts +13 -0
  108. package/dist/types/primitives/useDisconnect.d.ts.map +1 -0
  109. package/dist/types/primitives/useReconnect.d.ts +13 -0
  110. package/dist/types/primitives/useReconnect.d.ts.map +1 -0
  111. package/dist/types/primitives/useSwitchChain.d.ts +13 -0
  112. package/dist/types/primitives/useSwitchChain.d.ts.map +1 -0
  113. package/dist/types/primitives/useSwitchConnection.d.ts +13 -0
  114. package/dist/types/primitives/useSwitchConnection.d.ts.map +1 -0
  115. package/dist/types/primitives/useWatchBlockNumber.d.ts +11 -0
  116. package/dist/types/primitives/useWatchBlockNumber.d.ts.map +1 -0
  117. package/dist/types/utils/getVersion.d.ts +2 -0
  118. package/dist/types/utils/getVersion.d.ts.map +1 -0
  119. package/dist/types/utils/query.d.ts +28 -0
  120. package/dist/types/utils/query.d.ts.map +1 -0
  121. package/dist/types/version.d.ts +2 -0
  122. package/dist/types/version.d.ts.map +1 -0
  123. package/package.json +95 -7
  124. package/query/package.json +5 -0
  125. package/src/context.ts +43 -0
  126. package/src/errors/base.ts +14 -0
  127. package/src/errors/context.ts +13 -0
  128. package/src/exports/actions.ts +7 -0
  129. package/src/exports/chains.ts +7 -0
  130. package/src/exports/connectors.ts +7 -0
  131. package/src/exports/index.ts +134 -0
  132. package/src/exports/query.ts +19 -0
  133. package/src/hydrate.ts +27 -0
  134. package/src/primitives/useBalance.ts +46 -0
  135. package/src/primitives/useBlockNumber.ts +99 -0
  136. package/src/primitives/useChainId.ts +42 -0
  137. package/src/primitives/useChains.ts +42 -0
  138. package/src/primitives/useClient.ts +67 -0
  139. package/src/primitives/useConfig.ts +27 -0
  140. package/src/primitives/useConnect.ts +63 -0
  141. package/src/primitives/useConnection.ts +44 -0
  142. package/src/primitives/useConnectionEffect.ts +66 -0
  143. package/src/primitives/useConnections.ts +34 -0
  144. package/src/primitives/useConnectorClient.ts +86 -0
  145. package/src/primitives/useConnectors.ts +47 -0
  146. package/src/primitives/useDisconnect.ts +44 -0
  147. package/src/primitives/useReconnect.ts +44 -0
  148. package/src/primitives/useSwitchChain.ts +58 -0
  149. package/src/primitives/useSwitchConnection.ts +60 -0
  150. package/src/primitives/useWatchBlockNumber.ts +65 -0
  151. package/src/utils/getVersion.ts +3 -0
  152. package/src/utils/query.ts +171 -0
  153. package/src/version.ts +1 -0
@@ -0,0 +1,2 @@
1
+ export declare const version = "0.0.1";
2
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,UAAU,CAAA"}
package/package.json CHANGED
@@ -1,8 +1,96 @@
1
1
  {
2
- "name": "@wagmi/solid",
3
- "version": "0.0.0-alpha",
4
- "license": "MIT",
5
- "publishConfig": {
6
- "access": "public"
7
- }
8
- }
2
+ "name": "@wagmi/solid",
3
+ "description": "Solid Primitives for Ethereum",
4
+ "version": "0.0.1",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/wevm/wagmi.git",
9
+ "directory": "packages/solid"
10
+ },
11
+ "files": [
12
+ "dist/**",
13
+ "!dist/**/*.tsbuildinfo",
14
+ "src/**/*.ts",
15
+ "!src/**/*.test.ts",
16
+ "!src/**/*.test-d.ts",
17
+ "/actions",
18
+ "/chains",
19
+ "/connectors",
20
+ "/query"
21
+ ],
22
+ "sideEffects": false,
23
+ "type": "module",
24
+ "main": "./dist/esm/exports/index.js",
25
+ "types": "./dist/types/exports/index.d.ts",
26
+ "typings": "./dist/types/exports/index.d.ts",
27
+ "exports": {
28
+ ".": {
29
+ "types": "./dist/types/exports/index.d.ts",
30
+ "default": "./dist/esm/exports/index.js"
31
+ },
32
+ "./actions": {
33
+ "types": "./dist/types/exports/actions.d.ts",
34
+ "default": "./dist/esm/exports/actions.js"
35
+ },
36
+ "./chains": {
37
+ "types": "./dist/types/exports/chains.d.ts",
38
+ "default": "./dist/esm/exports/chains.js"
39
+ },
40
+ "./connectors": {
41
+ "types": "./dist/types/exports/connectors.d.ts",
42
+ "default": "./dist/esm/exports/connectors.js"
43
+ },
44
+ "./query": {
45
+ "types": "./dist/types/exports/query.d.ts",
46
+ "default": "./dist/esm/exports/query.js"
47
+ },
48
+ "./package.json": "./package.json"
49
+ },
50
+ "typesVersions": {
51
+ "*": {
52
+ "actions": [
53
+ "./dist/types/exports/actions.d.ts"
54
+ ],
55
+ "chains": [
56
+ "./dist/types/exports/chains.d.ts"
57
+ ],
58
+ "connectors": [
59
+ "./dist/types/exports/connectors.d.ts"
60
+ ],
61
+ "query": [
62
+ "./dist/types/exports/query.d.ts"
63
+ ]
64
+ }
65
+ },
66
+ "peerDependencies": {
67
+ "@tanstack/solid-query": ">=5.0.0",
68
+ "solid-js": "1.x",
69
+ "typescript": ">=5.7.3",
70
+ "viem": "2.x"
71
+ },
72
+ "peerDependenciesMeta": {
73
+ "typescript": {
74
+ "optional": true
75
+ }
76
+ },
77
+ "dependencies": {
78
+ "@wagmi/connectors": "7.1.6",
79
+ "@wagmi/core": "3.3.2"
80
+ },
81
+ "contributors": [
82
+ "awkweb.eth <t@wevm.dev>",
83
+ "jxom.eth <j@wevm.dev>"
84
+ ],
85
+ "funding": "https://github.com/sponsors/wevm",
86
+ "keywords": [
87
+ "wagmi",
88
+ "solid",
89
+ "primitives",
90
+ "eth",
91
+ "ethereum",
92
+ "dapps",
93
+ "wallet",
94
+ "web3"
95
+ ]
96
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "type": "module",
3
+ "types": "../dist/types/exports/query.d.ts",
4
+ "main": "../dist/esm/exports/query.js"
5
+ }
package/src/context.ts ADDED
@@ -0,0 +1,43 @@
1
+ import type { ResolvedRegister, State } from '@wagmi/core'
2
+ import {
3
+ createComponent,
4
+ createContext,
5
+ mergeProps,
6
+ type ParentProps,
7
+ } from 'solid-js'
8
+ import { Hydrate } from './hydrate.js'
9
+
10
+ export const WagmiContext = createContext<
11
+ ResolvedRegister['config'] | undefined
12
+ >(undefined)
13
+
14
+ export type WagmiProviderProps = {
15
+ config: ResolvedRegister['config']
16
+ initialState?: State | undefined
17
+ reconnectOnMount?: boolean | undefined
18
+ }
19
+
20
+ export function WagmiProvider(parameters: ParentProps<WagmiProviderProps>) {
21
+ const props = mergeProps({ reconnectOnMount: true }, parameters)
22
+ return createComponent(Hydrate, {
23
+ get config() {
24
+ return props.config
25
+ },
26
+ get initialState() {
27
+ return props.initialState
28
+ },
29
+ get reconnectOnMount() {
30
+ return props.reconnectOnMount
31
+ },
32
+ get children() {
33
+ return createComponent(WagmiContext.Provider, {
34
+ get value() {
35
+ return props.config
36
+ },
37
+ get children() {
38
+ return props.children
39
+ },
40
+ })
41
+ },
42
+ })
43
+ }
@@ -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/solid' // TODO: add solid docs
10
+ }
11
+ override get version() {
12
+ return getVersion()
13
+ }
14
+ }
@@ -0,0 +1,13 @@
1
+ import { BaseError } from './base.js'
2
+
3
+ export type WagmiProviderNotFoundErrorType = WagmiProviderNotFoundError & {
4
+ name: 'WagmiProviderNotFoundError'
5
+ }
6
+ export class WagmiProviderNotFoundError extends BaseError {
7
+ override name = 'WagmiProviderNotFoundError'
8
+ constructor() {
9
+ super('`useConfig` must be used within `WagmiProvider`.', {
10
+ docsPath: '/api/WagmiProvider',
11
+ })
12
+ }
13
+ }
@@ -0,0 +1,7 @@
1
+ ////////////////////////////////////////////////////////////////////////////////
2
+ // @wagmi/core/actions
3
+ ////////////////////////////////////////////////////////////////////////////////
4
+
5
+ // biome-ignore lint/performance/noBarrelFile: entrypoint module
6
+ // biome-ignore lint/performance/noReExportAll: entrypoint module
7
+ export * from '@wagmi/core/actions'
@@ -0,0 +1,7 @@
1
+ ////////////////////////////////////////////////////////////////////////////////
2
+ // viem/chains
3
+ ////////////////////////////////////////////////////////////////////////////////
4
+
5
+ // biome-ignore lint/performance/noBarrelFile: entrypoint module
6
+ // biome-ignore lint/performance/noReExportAll: entrypoint module
7
+ export * from 'viem/chains'
@@ -0,0 +1,7 @@
1
+ ////////////////////////////////////////////////////////////////////////////////
2
+ // @wagmi/connectors
3
+ ////////////////////////////////////////////////////////////////////////////////
4
+
5
+ // biome-ignore lint/performance/noBarrelFile: entrypoint module
6
+ // biome-ignore lint/performance/noReExportAll: entrypoint module
7
+ export * from '@wagmi/connectors'
@@ -0,0 +1,134 @@
1
+ ////////////////////////////////////////////////////////////////////////////////
2
+ // Context
3
+ ////////////////////////////////////////////////////////////////////////////////
4
+
5
+ // biome-ignore lint/performance/noBarrelFile: entrypoint module
6
+ export {
7
+ WagmiContext,
8
+ WagmiProvider,
9
+ type WagmiProviderProps,
10
+ } from '../context.js'
11
+
12
+ ////////////////////////////////////////////////////////////////////////////////
13
+ // Errors
14
+ ////////////////////////////////////////////////////////////////////////////////
15
+
16
+ export { BaseError, type BaseErrorType } from '../errors/base.js'
17
+
18
+ export {
19
+ WagmiProviderNotFoundError,
20
+ type WagmiProviderNotFoundErrorType,
21
+ } from '../errors/context.js'
22
+
23
+ ////////////////////////////////////////////////////////////////////////////////
24
+ // Primitives
25
+ ////////////////////////////////////////////////////////////////////////////////
26
+
27
+ export { useBalance } from '../primitives/useBalance.js'
28
+
29
+ export { useBlockNumber } from '../primitives/useBlockNumber.js'
30
+
31
+ export { useChainId } from '../primitives/useChainId.js'
32
+
33
+ export { useChains } from '../primitives/useChains.js'
34
+
35
+ export { useClient } from '../primitives/useClient.js'
36
+
37
+ export { useConfig } from '../primitives/useConfig.js'
38
+
39
+ export { useConnect } from '../primitives/useConnect.js'
40
+
41
+ export { useConnection } from '../primitives/useConnection.js'
42
+
43
+ export { useConnectionEffect } from '../primitives/useConnectionEffect.js'
44
+
45
+ export { useConnections } from '../primitives/useConnections.js'
46
+
47
+ export { useConnectorClient } from '../primitives/useConnectorClient.js'
48
+
49
+ export { useConnectors } from '../primitives/useConnectors.js'
50
+
51
+ export { useDisconnect } from '../primitives/useDisconnect.js'
52
+
53
+ export { useReconnect } from '../primitives/useReconnect.js'
54
+
55
+ export { useSwitchChain } from '../primitives/useSwitchChain.js'
56
+
57
+ export { useSwitchConnection } from '../primitives/useSwitchConnection.js'
58
+
59
+ export { useWatchBlockNumber } from '../primitives/useWatchBlockNumber.js'
60
+
61
+ ////////////////////////////////////////////////////////////////////////////////
62
+ // Hydrate
63
+ ////////////////////////////////////////////////////////////////////////////////
64
+
65
+ export {
66
+ Hydrate,
67
+ type HydrateProps,
68
+ } from '../hydrate.js'
69
+
70
+ ////////////////////////////////////////////////////////////////////////////////
71
+ // @wagmi/core
72
+ ////////////////////////////////////////////////////////////////////////////////
73
+
74
+ export {
75
+ ChainNotConfiguredError,
76
+ // Errors
77
+ type ChainNotConfiguredErrorType,
78
+ type Config,
79
+ // Config
80
+ type Connection,
81
+ type Connector,
82
+ ConnectorAccountNotFoundError,
83
+ type ConnectorAccountNotFoundErrorType,
84
+ ConnectorAlreadyConnectedError,
85
+ type ConnectorAlreadyConnectedErrorType,
86
+ ConnectorChainMismatchError,
87
+ type ConnectorChainMismatchErrorType,
88
+ // Connector
89
+ type ConnectorEventMap,
90
+ ConnectorNotFoundError,
91
+ type ConnectorNotFoundErrorType,
92
+ ConnectorUnavailableReconnectingError,
93
+ type ConnectorUnavailableReconnectingErrorType,
94
+ type CreateConfigParameters,
95
+ type CreateConnectorFn,
96
+ // Storage
97
+ type CreateStorageParameters,
98
+ // Utilities
99
+ cookieStorage,
100
+ cookieToInitialState,
101
+ createConfig,
102
+ createConnector,
103
+ createStorage,
104
+ // Transports
105
+ custom,
106
+ deepEqual,
107
+ deserialize,
108
+ fallback,
109
+ http,
110
+ injected,
111
+ mock,
112
+ noopStorage,
113
+ type PartializedState,
114
+ ProviderNotFoundError,
115
+ type ProviderNotFoundErrorType,
116
+ parseCookie,
117
+ // Types
118
+ type Register,
119
+ type ResolvedRegister,
120
+ type State,
121
+ type Storage,
122
+ SwitchChainNotSupportedError,
123
+ type SwitchChainNotSupportedErrorType,
124
+ serialize,
125
+ type Transport,
126
+ unstable_connector,
127
+ webSocket,
128
+ } from '@wagmi/core'
129
+
130
+ ////////////////////////////////////////////////////////////////////////////////
131
+ // Version
132
+ ////////////////////////////////////////////////////////////////////////////////
133
+
134
+ export { version } from '../version.js'
@@ -0,0 +1,19 @@
1
+ ////////////////////////////////////////////////////////////////////////////////
2
+ // @wagmi/core/query
3
+ ////////////////////////////////////////////////////////////////////////////////
4
+
5
+ // biome-ignore lint/performance/noBarrelFile: entrypoint module
6
+ // biome-ignore lint/performance/noReExportAll: entrypoint module
7
+ export * from '@wagmi/core/query'
8
+
9
+ export {
10
+ type SolidInfiniteQueryParameters,
11
+ type SolidMutationParameters,
12
+ type SolidQueryParameters,
13
+ type UseInfiniteQueryReturnType,
14
+ type UseMutationReturnType,
15
+ type UseQueryReturnType,
16
+ useInfiniteQuery,
17
+ useMutation,
18
+ useQuery,
19
+ } from '../utils/query.js'
package/src/hydrate.ts ADDED
@@ -0,0 +1,27 @@
1
+ import { hydrate, type ResolvedRegister, type State } from '@wagmi/core'
2
+ import { mergeProps, onMount, type ParentProps } from 'solid-js'
3
+
4
+ export type HydrateProps = {
5
+ config: ResolvedRegister['config']
6
+ initialState?: State | undefined
7
+ reconnectOnMount?: boolean | undefined
8
+ }
9
+
10
+ export function Hydrate(parameters: ParentProps<HydrateProps>) {
11
+ const props = mergeProps({ reconnectOnMount: true }, parameters)
12
+
13
+ const { onMount: hydrateOnMount } = hydrate(props.config, {
14
+ initialState: props.initialState,
15
+ reconnectOnMount: props.reconnectOnMount,
16
+ })
17
+
18
+ // Hydrate for non-SSR
19
+ if (!props.config._internal.ssr) hydrateOnMount()
20
+
21
+ onMount(() => {
22
+ if (!props.config._internal.ssr) return
23
+ hydrateOnMount()
24
+ })
25
+
26
+ return props.children
27
+ }
@@ -0,0 +1,46 @@
1
+ import type { Config, GetBalanceErrorType, ResolvedRegister } from '@wagmi/core'
2
+ import type { Compute, ConfigParameter } from '@wagmi/core/internal'
3
+ import {
4
+ type GetBalanceData,
5
+ type GetBalanceOptions,
6
+ getBalanceQueryOptions,
7
+ } from '@wagmi/core/query'
8
+ import { type Accessor, createMemo } from 'solid-js'
9
+ import { type UseQueryReturnType, useQuery } from '../utils/query.js'
10
+ import { useChainId } from './useChainId.js'
11
+ import { useConfig } from './useConfig.js'
12
+
13
+ /** https://wagmi.sh/solid/api/primitives/useBalance */
14
+ export function useBalance<
15
+ config extends Config = ResolvedRegister['config'],
16
+ selectData = GetBalanceData,
17
+ >(
18
+ parameters: useBalance.Parameters<config, selectData> = () => ({}),
19
+ ): useBalance.ReturnType<selectData> {
20
+ const config = useConfig(parameters)
21
+ const chainId = useChainId(() => ({ config: config() }))
22
+ const options = createMemo(() =>
23
+ getBalanceQueryOptions(config(), {
24
+ ...parameters(),
25
+ chainId: parameters().chainId ?? chainId(),
26
+ }),
27
+ )
28
+ return useQuery(options)
29
+ }
30
+
31
+ export namespace useBalance {
32
+ export type Parameters<
33
+ config extends Config = Config,
34
+ selectData = GetBalanceData,
35
+ > = Accessor<SolidParameters<config, selectData>>
36
+
37
+ export type ReturnType<selectData = GetBalanceData> = UseQueryReturnType<
38
+ selectData,
39
+ GetBalanceErrorType
40
+ >
41
+
42
+ export type SolidParameters<
43
+ config extends Config = Config,
44
+ selectData = GetBalanceData,
45
+ > = Compute<GetBalanceOptions<config, selectData> & ConfigParameter<config>>
46
+ }
@@ -0,0 +1,99 @@
1
+ import { useQueryClient } from '@tanstack/solid-query'
2
+ import type {
3
+ Config,
4
+ GetBlockNumberErrorType,
5
+ ResolvedRegister,
6
+ } from '@wagmi/core'
7
+ import type {
8
+ Compute,
9
+ ConfigParameter,
10
+ UnionCompute,
11
+ UnionStrictOmit,
12
+ } from '@wagmi/core/internal'
13
+ import {
14
+ type GetBlockNumberData,
15
+ type GetBlockNumberOptions,
16
+ getBlockNumberQueryOptions,
17
+ } from '@wagmi/core/query'
18
+ import { type Accessor, createMemo } from 'solid-js'
19
+ import { type UseQueryReturnType, useQuery } from '../utils/query.js'
20
+ import { useChainId } from './useChainId.js'
21
+ import { useConfig } from './useConfig.js'
22
+ import { useWatchBlockNumber } from './useWatchBlockNumber.js'
23
+
24
+ /** https://wagmi.sh/solid/api/hooks/useBlockNumber */
25
+ export function useBlockNumber<
26
+ config extends Config = ResolvedRegister['config'],
27
+ chainId extends
28
+ config['chains'][number]['id'] = config['chains'][number]['id'],
29
+ selectData = GetBlockNumberData,
30
+ >(
31
+ parameters: useBlockNumber.Parameters<
32
+ config,
33
+ chainId,
34
+ selectData
35
+ > = () => ({}),
36
+ ): useBlockNumber.ReturnType<selectData> {
37
+ const config = useConfig(parameters)
38
+ const chainId = useChainId(() => ({ config: config() }))
39
+ const options = createMemo(() =>
40
+ getBlockNumberQueryOptions(config(), {
41
+ ...parameters(),
42
+ chainId: parameters().chainId ?? chainId(),
43
+ }),
44
+ )
45
+ const queryClient = useQueryClient()
46
+ const watchBlockNumberArgs = createMemo(() => {
47
+ // Assign to variable to help type narrowing
48
+ const { watch } = parameters()
49
+ return {
50
+ ...({
51
+ config: config(),
52
+ chainId: parameters().chainId ?? chainId(),
53
+ ...(typeof watch === 'object' ? watch : {}),
54
+ } as useWatchBlockNumber.SolidParameters),
55
+ enabled:
56
+ (parameters().query?.enabled ?? true) &&
57
+ (typeof watch === 'object' ? watch.enabled : watch),
58
+ onBlockNumber(blockNumber) {
59
+ queryClient.setQueryData(options().queryKey, blockNumber)
60
+ },
61
+ } satisfies useWatchBlockNumber.SolidParameters
62
+ })
63
+ useWatchBlockNumber(watchBlockNumberArgs)
64
+ return useQuery(options)
65
+ }
66
+
67
+ export namespace useBlockNumber {
68
+ export type Parameters<
69
+ config extends Config = Config,
70
+ chainId extends
71
+ config['chains'][number]['id'] = config['chains'][number]['id'],
72
+ selectData = GetBlockNumberData,
73
+ > = Accessor<SolidParameters<config, chainId, selectData>>
74
+
75
+ export type ReturnType<selectData = GetBlockNumberData> = UseQueryReturnType<
76
+ selectData,
77
+ GetBlockNumberErrorType
78
+ >
79
+
80
+ export type SolidParameters<
81
+ config extends Config = Config,
82
+ chainId extends
83
+ config['chains'][number]['id'] = config['chains'][number]['id'],
84
+ selectData = GetBlockNumberData,
85
+ > = Compute<
86
+ GetBlockNumberOptions<config, chainId, selectData> &
87
+ ConfigParameter<config> & {
88
+ watch?:
89
+ | boolean
90
+ | UnionCompute<
91
+ UnionStrictOmit<
92
+ useWatchBlockNumber.SolidParameters<config, chainId>,
93
+ 'chainId' | 'config' | 'onBlockNumber' | 'onError'
94
+ >
95
+ >
96
+ | undefined
97
+ }
98
+ >
99
+ }
@@ -0,0 +1,42 @@
1
+ import {
2
+ type Config,
3
+ type GetChainIdReturnType,
4
+ getChainId,
5
+ type ResolvedRegister,
6
+ watchChainId,
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/hooks/useChainId */
13
+ export function useChainId<config extends Config = ResolvedRegister['config']>(
14
+ parameters: useChainId.Parameters<config> = () => ({}),
15
+ ): useChainId.ReturnType<config> {
16
+ const config = useConfig(parameters)
17
+ const [chainId, setChainId] = createSignal(getChainId(config()))
18
+ createEffect(() => {
19
+ const _config = config()
20
+ setChainId(() => getChainId(_config))
21
+ const unsubscribe = watchChainId(_config, {
22
+ onChange(data) {
23
+ setChainId(() => data)
24
+ },
25
+ })
26
+ onCleanup(() => unsubscribe())
27
+ })
28
+ return chainId
29
+ }
30
+
31
+ export namespace useChainId {
32
+ export type Parameters<config extends Config = Config> = Accessor<
33
+ SolidParameters<config>
34
+ >
35
+ export type ReturnType<config extends Config = Config> = Accessor<
36
+ SolidReturnType<config>
37
+ >
38
+ export type SolidParameters<config extends Config = Config> =
39
+ ConfigParameter<config>
40
+ export type SolidReturnType<config extends Config = Config> =
41
+ GetChainIdReturnType<config>
42
+ }
@@ -0,0 +1,42 @@
1
+ import {
2
+ type Config,
3
+ type GetChainsReturnType,
4
+ getChains,
5
+ type ResolvedRegister,
6
+ } from '@wagmi/core'
7
+ import type { ConfigParameter } from '@wagmi/core/internal'
8
+ import { watchChains } 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/useChains */
13
+ export function useChains<config extends Config = ResolvedRegister['config']>(
14
+ parameters: useChains.Parameters<config> = () => ({}),
15
+ ): useChains.ReturnType<config> {
16
+ const config = useConfig(parameters)
17
+ const [chains, setChains] = createSignal<GetChainsReturnType<config>>(
18
+ getChains(config()),
19
+ )
20
+ createEffect(() => {
21
+ const unsubscribe = watchChains(config(), {
22
+ onChange(data) {
23
+ setChains(() => data)
24
+ },
25
+ })
26
+ onCleanup(() => unsubscribe())
27
+ })
28
+ return chains
29
+ }
30
+
31
+ export namespace useChains {
32
+ export type Parameters<config extends Config = Config> = Accessor<
33
+ ConfigParameter<config>
34
+ >
35
+ export type ReturnType<config extends Config = Config> = Accessor<
36
+ GetChainsReturnType<config>
37
+ >
38
+ export type SolidParameters<config extends Config = Config> =
39
+ ConfigParameter<config>
40
+ export type SolidReturnType<config extends Config = Config> =
41
+ GetChainsReturnType<config>
42
+ }