@wagmi/core 2.8.1 → 2.9.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 (81) hide show
  1. package/dist/esm/actions/sendTransaction.js +1 -1
  2. package/dist/esm/actions/sendTransaction.js.map +1 -1
  3. package/dist/esm/connectors/mock.js +81 -2
  4. package/dist/esm/connectors/mock.js.map +1 -1
  5. package/dist/esm/experimental/actions/getCallsStatus.js +10 -0
  6. package/dist/esm/experimental/actions/getCallsStatus.js.map +1 -0
  7. package/dist/esm/experimental/actions/getCapabilities.js +10 -0
  8. package/dist/esm/experimental/actions/getCapabilities.js.map +1 -0
  9. package/dist/esm/experimental/actions/sendCalls.js +21 -0
  10. package/dist/esm/experimental/actions/sendCalls.js.map +1 -0
  11. package/dist/esm/experimental/actions/showCallsStatus.js +10 -0
  12. package/dist/esm/experimental/actions/showCallsStatus.js.map +1 -0
  13. package/dist/esm/experimental/actions/writeContracts.js +20 -0
  14. package/dist/esm/experimental/actions/writeContracts.js.map +1 -0
  15. package/dist/esm/experimental/query/getCallsStatus.js +24 -0
  16. package/dist/esm/experimental/query/getCallsStatus.js.map +1 -0
  17. package/dist/esm/experimental/query/getCapabilities.js +24 -0
  18. package/dist/esm/experimental/query/getCapabilities.js.map +1 -0
  19. package/dist/esm/experimental/query/sendCalls.js +12 -0
  20. package/dist/esm/experimental/query/sendCalls.js.map +1 -0
  21. package/dist/esm/experimental/query/showCallsStatus.js +12 -0
  22. package/dist/esm/experimental/query/showCallsStatus.js.map +1 -0
  23. package/dist/esm/experimental/query/writeContracts.js +12 -0
  24. package/dist/esm/experimental/query/writeContracts.js.map +1 -0
  25. package/dist/esm/exports/experimental.js +17 -0
  26. package/dist/esm/exports/experimental.js.map +1 -0
  27. package/dist/esm/tsconfig.build.tsbuildinfo +1 -1
  28. package/dist/esm/version.js +1 -1
  29. package/dist/types/connectors/injected.d.ts +19 -1
  30. package/dist/types/connectors/injected.d.ts.map +1 -1
  31. package/dist/types/connectors/mock.d.ts.map +1 -1
  32. package/dist/types/experimental/actions/getCallsStatus.d.ts +9 -0
  33. package/dist/types/experimental/actions/getCallsStatus.d.ts.map +1 -0
  34. package/dist/types/experimental/actions/getCapabilities.d.ts +10 -0
  35. package/dist/types/experimental/actions/getCapabilities.d.ts.map +1 -0
  36. package/dist/types/experimental/actions/sendCalls.d.ts +16 -0
  37. package/dist/types/experimental/actions/sendCalls.d.ts.map +1 -0
  38. package/dist/types/experimental/actions/showCallsStatus.d.ts +9 -0
  39. package/dist/types/experimental/actions/showCallsStatus.d.ts.map +1 -0
  40. package/dist/types/experimental/actions/writeContracts.d.ts +16 -0
  41. package/dist/types/experimental/actions/writeContracts.d.ts.map +1 -0
  42. package/dist/types/experimental/query/getCallsStatus.d.ts +34 -0
  43. package/dist/types/experimental/query/getCallsStatus.d.ts.map +1 -0
  44. package/dist/types/experimental/query/getCapabilities.d.ts +33 -0
  45. package/dist/types/experimental/query/getCapabilities.d.ts.map +1 -0
  46. package/dist/types/experimental/query/sendCalls.d.ts +13 -0
  47. package/dist/types/experimental/query/sendCalls.d.ts.map +1 -0
  48. package/dist/types/experimental/query/showCallsStatus.d.ts +13 -0
  49. package/dist/types/experimental/query/showCallsStatus.d.ts.map +1 -0
  50. package/dist/types/experimental/query/writeContracts.d.ts +13 -0
  51. package/dist/types/experimental/query/writeContracts.d.ts.map +1 -0
  52. package/dist/types/exports/experimental.d.ts +11 -0
  53. package/dist/types/exports/experimental.d.ts.map +1 -0
  54. package/dist/types/query/getConnectorClient.d.ts +25 -2
  55. package/dist/types/query/getConnectorClient.d.ts.map +1 -1
  56. package/dist/types/query/getWalletClient.d.ts +181 -177
  57. package/dist/types/query/getWalletClient.d.ts.map +1 -1
  58. package/dist/types/query/infiniteReadContracts.d.ts +3 -3
  59. package/dist/types/query/readContracts.d.ts +6 -3
  60. package/dist/types/query/readContracts.d.ts.map +1 -1
  61. package/dist/types/query/signTypedData.d.ts +14 -14
  62. package/dist/types/query/verifyMessage.d.ts +3 -3
  63. package/dist/types/transports/fallback.d.ts +1 -1
  64. package/dist/types/transports/fallback.d.ts.map +1 -1
  65. package/dist/types/version.d.ts +1 -1
  66. package/experimental/package.json +5 -0
  67. package/package.json +9 -1
  68. package/src/actions/sendTransaction.ts +1 -1
  69. package/src/connectors/mock.ts +88 -1
  70. package/src/experimental/actions/getCallsStatus.ts +27 -0
  71. package/src/experimental/actions/getCapabilities.ts +28 -0
  72. package/src/experimental/actions/sendCalls.ts +68 -0
  73. package/src/experimental/actions/showCallsStatus.ts +27 -0
  74. package/src/experimental/actions/writeContracts.ts +77 -0
  75. package/src/experimental/query/getCallsStatus.ts +50 -0
  76. package/src/experimental/query/getCapabilities.ts +50 -0
  77. package/src/experimental/query/sendCalls.ts +64 -0
  78. package/src/experimental/query/showCallsStatus.ts +57 -0
  79. package/src/experimental/query/writeContracts.ts +70 -0
  80. package/src/exports/experimental.ts +84 -0
  81. package/src/version.ts +1 -1
@@ -0,0 +1,77 @@
1
+ import { type Account, type Chain, type ContractFunctionParameters } from 'viem'
2
+ import {
3
+ type WriteContractsErrorType as viem_WriteContractsErrorType,
4
+ type WriteContractsParameters as viem_WriteContractsParameters,
5
+ type WriteContractsReturnType as viem_WriteContractsReturnType,
6
+ writeContracts as viem_writeContracts,
7
+ } from 'viem/experimental'
8
+
9
+ import {
10
+ type GetConnectorClientErrorType,
11
+ getConnectorClient,
12
+ } from '../../actions/getConnectorClient.js'
13
+ import { type Config } from '../../createConfig.js'
14
+ import type { BaseErrorType, ErrorType } from '../../errors/base.js'
15
+ import type { SelectChains } from '../../types/chain.js'
16
+ import type {
17
+ ChainIdParameter,
18
+ ConnectorParameter,
19
+ } from '../../types/properties.js'
20
+ import { type Evaluate } from '../../types/utils.js'
21
+
22
+ export type WriteContractsParameters<
23
+ contracts extends readonly unknown[] = readonly ContractFunctionParameters[],
24
+ config extends Config = Config,
25
+ chainId extends config['chains'][number]['id'] = config['chains'][number]['id'],
26
+ ///
27
+ chains extends readonly Chain[] = SelectChains<config, chainId>,
28
+ > = {
29
+ [key in keyof chains]: Evaluate<
30
+ Omit<
31
+ viem_WriteContractsParameters<
32
+ contracts,
33
+ chains[key],
34
+ Account,
35
+ chains[key]
36
+ >,
37
+ 'chain'
38
+ > &
39
+ ChainIdParameter<config, chainId> &
40
+ ConnectorParameter
41
+ >
42
+ }[number]
43
+
44
+ export type WriteContractsReturnType = viem_WriteContractsReturnType
45
+
46
+ export type WriteContractsErrorType =
47
+ // getConnectorClient()
48
+ | GetConnectorClientErrorType
49
+ // base
50
+ | BaseErrorType
51
+ | ErrorType
52
+ // viem
53
+ | viem_WriteContractsErrorType
54
+
55
+ /** https://wagmi.sh/core/api/actions/writeContracts */
56
+ export async function writeContracts<
57
+ const contracts extends readonly unknown[],
58
+ config extends Config,
59
+ chainId extends config['chains'][number]['id'],
60
+ >(
61
+ config: config,
62
+ parameters: WriteContractsParameters<contracts, config, chainId>,
63
+ ): Promise<WriteContractsReturnType> {
64
+ const { account, chainId, connector, ...rest } = parameters
65
+
66
+ const client = await getConnectorClient(config, {
67
+ account,
68
+ chainId,
69
+ connector,
70
+ })
71
+
72
+ return viem_writeContracts(client, {
73
+ ...(rest as any),
74
+ ...(account ? { account } : {}),
75
+ chain: chainId ? { id: chainId } : undefined,
76
+ })
77
+ }
@@ -0,0 +1,50 @@
1
+ import { type QueryOptions } from '@tanstack/query-core'
2
+
3
+ import { type Config } from '../../createConfig.js'
4
+ import { ConnectorNotConnectedError } from '../../errors/config.js'
5
+ import { filterQueryOptions } from '../../query/utils.js'
6
+ import type { ScopeKeyParameter } from '../../types/properties.js'
7
+ import type { Evaluate } from '../../types/utils.js'
8
+ import {
9
+ type GetCallsStatusErrorType,
10
+ type GetCallsStatusParameters,
11
+ type GetCallsStatusReturnType,
12
+ getCallsStatus,
13
+ } from '../actions/getCallsStatus.js'
14
+
15
+ export type GetCallsStatusOptions = Evaluate<
16
+ GetCallsStatusParameters & ScopeKeyParameter
17
+ >
18
+
19
+ export function getCallsStatusQueryOptions<config extends Config,>(
20
+ config: config,
21
+ options: GetCallsStatusOptions,
22
+ ) {
23
+ return {
24
+ async queryFn({ queryKey }) {
25
+ const { scopeKey: _, ...parameters } = queryKey[1]
26
+ const status = await getCallsStatus(config, parameters)
27
+ return status
28
+ },
29
+ queryKey: getCallsStatusQueryKey(options),
30
+ retry(failureCount, error) {
31
+ if (error instanceof ConnectorNotConnectedError) return false
32
+ return failureCount < 3
33
+ },
34
+ } as const satisfies QueryOptions<
35
+ GetCallsStatusQueryFnData,
36
+ GetCallsStatusErrorType,
37
+ GetCallsStatusData,
38
+ GetCallsStatusQueryKey
39
+ >
40
+ }
41
+
42
+ export type GetCallsStatusQueryFnData = GetCallsStatusReturnType
43
+
44
+ export type GetCallsStatusData = GetCallsStatusQueryFnData
45
+
46
+ export function getCallsStatusQueryKey(options: GetCallsStatusOptions) {
47
+ return ['callsStatus', filterQueryOptions(options)] as const
48
+ }
49
+
50
+ export type GetCallsStatusQueryKey = ReturnType<typeof getCallsStatusQueryKey>
@@ -0,0 +1,50 @@
1
+ import { type QueryOptions } from '@tanstack/query-core'
2
+
3
+ import { type Config } from '../../createConfig.js'
4
+ import { ConnectorNotConnectedError } from '../../errors/config.js'
5
+ import { filterQueryOptions } from '../../query/utils.js'
6
+ import type { ScopeKeyParameter } from '../../types/properties.js'
7
+ import type { Evaluate, ExactPartial } from '../../types/utils.js'
8
+ import {
9
+ type GetCapabilitiesErrorType,
10
+ type GetCapabilitiesParameters,
11
+ type GetCapabilitiesReturnType,
12
+ getCapabilities,
13
+ } from '../actions/getCapabilities.js'
14
+
15
+ export type GetCapabilitiesOptions = Evaluate<
16
+ ExactPartial<GetCapabilitiesParameters> & ScopeKeyParameter
17
+ >
18
+
19
+ export function getCapabilitiesQueryOptions<config extends Config,>(
20
+ config: config,
21
+ options: GetCapabilitiesOptions = {},
22
+ ) {
23
+ return {
24
+ async queryFn({ queryKey }) {
25
+ const { scopeKey: _, ...parameters } = queryKey[1]
26
+ const capabilities = await getCapabilities(config, parameters)
27
+ return capabilities
28
+ },
29
+ queryKey: getCapabilitiesQueryKey(options),
30
+ retry(failureCount, error) {
31
+ if (error instanceof ConnectorNotConnectedError) return false
32
+ return failureCount < 3
33
+ },
34
+ } as const satisfies QueryOptions<
35
+ GetCapabilitiesQueryFnData,
36
+ GetCapabilitiesErrorType,
37
+ GetCapabilitiesData,
38
+ GetCapabilitiesQueryKey
39
+ >
40
+ }
41
+
42
+ export type GetCapabilitiesQueryFnData = GetCapabilitiesReturnType
43
+
44
+ export type GetCapabilitiesData = GetCapabilitiesQueryFnData
45
+
46
+ export function getCapabilitiesQueryKey(options: GetCapabilitiesOptions = {}) {
47
+ return ['capabilities', filterQueryOptions(options)] as const
48
+ }
49
+
50
+ export type GetCapabilitiesQueryKey = ReturnType<typeof getCapabilitiesQueryKey>
@@ -0,0 +1,64 @@
1
+ import type { MutateOptions, MutationOptions } from '@tanstack/query-core'
2
+
3
+ import { type Config } from '../../createConfig.js'
4
+ import { type Evaluate } from '../../types/utils.js'
5
+ import {
6
+ type SendCallsErrorType,
7
+ type SendCallsParameters,
8
+ type SendCallsReturnType,
9
+ sendCalls,
10
+ } from '../actions/sendCalls.js'
11
+
12
+ export function sendCallsMutationOptions<config extends Config>(
13
+ config: config,
14
+ ) {
15
+ return {
16
+ mutationFn(variables) {
17
+ return sendCalls(config, variables)
18
+ },
19
+ mutationKey: ['sendCalls'],
20
+ } as const satisfies MutationOptions<
21
+ SendCallsData,
22
+ SendCallsErrorType,
23
+ SendCallsVariables<config, config['chains'][number]['id']>
24
+ >
25
+ }
26
+
27
+ export type SendCallsData = Evaluate<SendCallsReturnType>
28
+
29
+ export type SendCallsVariables<
30
+ config extends Config,
31
+ chainId extends config['chains'][number]['id'],
32
+ > = SendCallsParameters<config, chainId>
33
+
34
+ export type SendCallsMutate<config extends Config, context = unknown> = <
35
+ chainId extends config['chains'][number]['id'],
36
+ >(
37
+ variables: SendCallsVariables<config, chainId>,
38
+ options?:
39
+ | Evaluate<
40
+ MutateOptions<
41
+ SendCallsData,
42
+ SendCallsErrorType,
43
+ Evaluate<SendCallsVariables<config, chainId>>,
44
+ context
45
+ >
46
+ >
47
+ | undefined,
48
+ ) => void
49
+
50
+ export type SendCallsMutateAsync<config extends Config, context = unknown> = <
51
+ chainId extends config['chains'][number]['id'],
52
+ >(
53
+ variables: SendCallsVariables<config, chainId>,
54
+ options?:
55
+ | Evaluate<
56
+ MutateOptions<
57
+ SendCallsData,
58
+ SendCallsErrorType,
59
+ Evaluate<SendCallsVariables<config, chainId>>,
60
+ context
61
+ >
62
+ >
63
+ | undefined,
64
+ ) => Promise<SendCallsData>
@@ -0,0 +1,57 @@
1
+ import type { MutateOptions, MutationOptions } from '@tanstack/query-core'
2
+
3
+ import { type Config } from '../../createConfig.js'
4
+ import { type Evaluate } from '../../types/utils.js'
5
+ import {
6
+ type ShowCallsStatusErrorType,
7
+ type ShowCallsStatusParameters,
8
+ type ShowCallsStatusReturnType,
9
+ showCallsStatus,
10
+ } from '../actions/showCallsStatus.js'
11
+
12
+ export function showCallsStatusMutationOptions<config extends Config>(
13
+ config: config,
14
+ ) {
15
+ return {
16
+ mutationFn(variables) {
17
+ return showCallsStatus(config, variables)
18
+ },
19
+ mutationKey: ['showCallsStatus'],
20
+ } as const satisfies MutationOptions<
21
+ ShowCallsStatusData,
22
+ ShowCallsStatusErrorType,
23
+ ShowCallsStatusVariables
24
+ >
25
+ }
26
+
27
+ export type ShowCallsStatusData = Evaluate<ShowCallsStatusReturnType>
28
+
29
+ export type ShowCallsStatusVariables = ShowCallsStatusParameters
30
+
31
+ export type ShowCallsStatusMutate<context = unknown> = (
32
+ variables: ShowCallsStatusVariables,
33
+ options?:
34
+ | Evaluate<
35
+ MutateOptions<
36
+ ShowCallsStatusData,
37
+ ShowCallsStatusErrorType,
38
+ Evaluate<ShowCallsStatusVariables>,
39
+ context
40
+ >
41
+ >
42
+ | undefined,
43
+ ) => void
44
+
45
+ export type ShowCallsStatusMutateAsync<context = unknown,> = (
46
+ variables: ShowCallsStatusVariables,
47
+ options?:
48
+ | Evaluate<
49
+ MutateOptions<
50
+ ShowCallsStatusData,
51
+ ShowCallsStatusErrorType,
52
+ Evaluate<ShowCallsStatusVariables>,
53
+ context
54
+ >
55
+ >
56
+ | undefined,
57
+ ) => Promise<ShowCallsStatusData>
@@ -0,0 +1,70 @@
1
+ import type { MutateOptions, MutationOptions } from '@tanstack/query-core'
2
+
3
+ import { type Config } from '../../createConfig.js'
4
+ import { type Evaluate } from '../../types/utils.js'
5
+ import {
6
+ type WriteContractsErrorType,
7
+ type WriteContractsParameters,
8
+ type WriteContractsReturnType,
9
+ writeContracts,
10
+ } from '../actions/writeContracts.js'
11
+
12
+ export function writeContractsMutationOptions<
13
+ const contracts extends readonly unknown[],
14
+ config extends Config,
15
+ >(config: config) {
16
+ return {
17
+ mutationFn(variables) {
18
+ return writeContracts(config, variables as any) as any
19
+ },
20
+ mutationKey: ['writeContracts'],
21
+ } as const satisfies MutationOptions<
22
+ WriteContractsData,
23
+ WriteContractsErrorType,
24
+ WriteContractsVariables<contracts, config, config['chains'][number]['id']>
25
+ >
26
+ }
27
+
28
+ export type WriteContractsData = Evaluate<WriteContractsReturnType>
29
+
30
+ export type WriteContractsVariables<
31
+ contracts extends readonly unknown[],
32
+ config extends Config,
33
+ chainId extends config['chains'][number]['id'],
34
+ > = WriteContractsParameters<contracts, config, chainId>
35
+
36
+ export type WriteContractsMutate<
37
+ contracts extends readonly unknown[],
38
+ config extends Config,
39
+ context = unknown,
40
+ > = <chainId extends config['chains'][number]['id'],>(
41
+ variables: WriteContractsVariables<contracts, config, chainId>,
42
+ options?:
43
+ | Evaluate<
44
+ MutateOptions<
45
+ WriteContractsData,
46
+ WriteContractsErrorType,
47
+ Evaluate<WriteContractsVariables<contracts, config, chainId>>,
48
+ context
49
+ >
50
+ >
51
+ | undefined,
52
+ ) => void
53
+
54
+ export type WriteContractsMutateAsync<
55
+ contracts extends readonly unknown[],
56
+ config extends Config,
57
+ context = unknown,
58
+ > = <chainId extends config['chains'][number]['id'],>(
59
+ variables: WriteContractsVariables<contracts, config, chainId>,
60
+ options?:
61
+ | Evaluate<
62
+ MutateOptions<
63
+ WriteContractsData,
64
+ WriteContractsErrorType,
65
+ Evaluate<WriteContractsVariables<contracts, config, chainId>>,
66
+ context
67
+ >
68
+ >
69
+ | undefined,
70
+ ) => Promise<WriteContractsData>
@@ -0,0 +1,84 @@
1
+ ////////////////////////////////////////////////////////////////////////////////
2
+ // Actions
3
+ ////////////////////////////////////////////////////////////////////////////////
4
+
5
+ export {
6
+ type GetCallsStatusErrorType,
7
+ type GetCallsStatusParameters,
8
+ type GetCallsStatusReturnType,
9
+ getCallsStatus,
10
+ } from '../experimental/actions/getCallsStatus.js'
11
+
12
+ export {
13
+ type GetCapabilitiesErrorType,
14
+ type GetCapabilitiesParameters,
15
+ type GetCapabilitiesReturnType,
16
+ getCapabilities,
17
+ } from '../experimental/actions/getCapabilities.js'
18
+
19
+ export {
20
+ type SendCallsErrorType,
21
+ type SendCallsParameters,
22
+ type SendCallsReturnType,
23
+ sendCalls,
24
+ } from '../experimental/actions/sendCalls.js'
25
+
26
+ export {
27
+ type ShowCallsStatusErrorType,
28
+ type ShowCallsStatusParameters,
29
+ type ShowCallsStatusReturnType,
30
+ showCallsStatus,
31
+ } from '../experimental/actions/showCallsStatus.js'
32
+
33
+ export {
34
+ type WriteContractsErrorType,
35
+ type WriteContractsParameters,
36
+ type WriteContractsReturnType,
37
+ writeContracts,
38
+ } from '../experimental/actions/writeContracts.js'
39
+
40
+ ////////////////////////////////////////////////////////////////////////////////
41
+ // Tanstack Query
42
+ ////////////////////////////////////////////////////////////////////////////////
43
+
44
+ export {
45
+ type GetCallsStatusData,
46
+ type GetCallsStatusOptions,
47
+ type GetCallsStatusQueryFnData,
48
+ type GetCallsStatusQueryKey,
49
+ getCallsStatusQueryOptions,
50
+ getCallsStatusQueryKey,
51
+ } from '../experimental/query/getCallsStatus.js'
52
+
53
+ export {
54
+ type GetCapabilitiesData,
55
+ type GetCapabilitiesOptions,
56
+ type GetCapabilitiesQueryFnData,
57
+ type GetCapabilitiesQueryKey,
58
+ getCapabilitiesQueryOptions,
59
+ getCapabilitiesQueryKey,
60
+ } from '../experimental/query/getCapabilities.js'
61
+
62
+ export {
63
+ type SendCallsData,
64
+ type SendCallsMutate,
65
+ type SendCallsMutateAsync,
66
+ type SendCallsVariables,
67
+ sendCallsMutationOptions,
68
+ } from '../experimental/query/sendCalls.js'
69
+
70
+ export {
71
+ type ShowCallsStatusData,
72
+ type ShowCallsStatusMutate,
73
+ type ShowCallsStatusMutateAsync,
74
+ type ShowCallsStatusVariables,
75
+ showCallsStatusMutationOptions,
76
+ } from '../experimental/query/showCallsStatus.js'
77
+
78
+ export {
79
+ type WriteContractsData,
80
+ type WriteContractsMutate,
81
+ type WriteContractsMutateAsync,
82
+ type WriteContractsVariables,
83
+ writeContractsMutationOptions,
84
+ } from '../experimental/query/writeContracts.js'
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '2.8.1'
1
+ export const version = '2.9.1'