@wagmi/core 2.0.0-alpha.3 → 2.0.0-alpha.5
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/dist/esm/actions/connect.js +4 -4
- package/dist/esm/actions/connect.js.map +1 -1
- package/dist/esm/actions/disconnect.js +3 -3
- package/dist/esm/actions/disconnect.js.map +1 -1
- package/dist/esm/actions/getAccount.js +5 -0
- package/dist/esm/actions/getAccount.js.map +1 -1
- package/dist/esm/actions/reconnect.js +9 -5
- package/dist/esm/actions/reconnect.js.map +1 -1
- package/dist/esm/actions/watchBlockNumber.js +1 -3
- package/dist/esm/actions/watchBlockNumber.js.map +1 -1
- package/dist/esm/actions/watchBlocks.js +1 -3
- package/dist/esm/actions/watchBlocks.js.map +1 -1
- package/dist/esm/actions/watchContractEvent.js +1 -3
- package/dist/esm/actions/watchContractEvent.js.map +1 -1
- package/dist/esm/actions/watchPendingTransactions.js +1 -3
- package/dist/esm/actions/watchPendingTransactions.js.map +1 -1
- package/dist/esm/actions/writeContract.js.map +1 -1
- package/dist/esm/connectors/createConnector.js +8 -0
- package/dist/esm/connectors/createConnector.js.map +1 -0
- package/dist/esm/connectors/injected.js +395 -0
- package/dist/esm/connectors/injected.js.map +1 -0
- package/dist/esm/connectors/mock.js +129 -0
- package/dist/esm/connectors/mock.js.map +1 -0
- package/dist/esm/createConfig.js +40 -27
- package/dist/esm/createConfig.js.map +1 -1
- package/dist/esm/exports/actions.js +33 -11
- package/dist/esm/exports/actions.js.map +1 -1
- package/dist/esm/exports/index.js +34 -13
- package/dist/esm/exports/index.js.map +1 -1
- package/dist/esm/exports/internal.js +4 -0
- package/dist/esm/exports/internal.js.map +1 -1
- package/dist/esm/tsconfig.build.tsbuildinfo +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/types/actions/connect.d.ts +1 -1
- package/dist/types/actions/connect.d.ts.map +1 -1
- package/dist/types/actions/getAccount.d.ts +5 -1
- package/dist/types/actions/getAccount.d.ts.map +1 -1
- package/dist/types/actions/reconnect.d.ts +1 -1
- package/dist/types/actions/reconnect.d.ts.map +1 -1
- package/dist/types/actions/watchBlockNumber.d.ts.map +1 -1
- package/dist/types/actions/watchBlocks.d.ts.map +1 -1
- package/dist/types/actions/watchContractEvent.d.ts.map +1 -1
- package/dist/types/actions/watchPendingTransactions.d.ts.map +1 -1
- package/dist/types/actions/writeContract.d.ts +3 -3
- package/dist/types/actions/writeContract.d.ts.map +1 -1
- package/dist/types/{createConnector.d.ts → connectors/createConnector.d.ts} +5 -3
- package/dist/types/connectors/createConnector.d.ts.map +1 -0
- package/dist/types/connectors/injected.d.ts +346 -0
- package/dist/types/connectors/injected.d.ts.map +1 -0
- package/dist/types/connectors/mock.d.ts +17 -0
- package/dist/types/connectors/mock.d.ts.map +1 -0
- package/dist/types/createConfig.d.ts +8 -12
- package/dist/types/createConfig.d.ts.map +1 -1
- package/dist/types/exports/actions.d.ts +33 -11
- package/dist/types/exports/actions.d.ts.map +1 -1
- package/dist/types/exports/index.d.ts +32 -11
- package/dist/types/exports/index.d.ts.map +1 -1
- package/dist/types/exports/internal.d.ts +2 -0
- package/dist/types/exports/internal.d.ts.map +1 -1
- package/dist/types/query/connect.d.ts +1 -1
- package/dist/types/query/getWalletClient.d.ts +10 -10
- package/dist/types/query/signTypedData.d.ts +8 -8
- package/dist/types/query/writeContract.d.ts +51 -1
- package/dist/types/query/writeContract.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +3 -2
- package/src/actions/connect.ts +4 -4
- package/src/actions/disconnect.ts +3 -3
- package/src/actions/getAccount.ts +10 -1
- package/src/actions/reconnect.ts +9 -5
- package/src/actions/watchBlockNumber.ts +1 -3
- package/src/actions/watchBlocks.ts +1 -3
- package/src/actions/watchContractEvent.ts +1 -3
- package/src/actions/watchPendingTransactions.ts +1 -3
- package/src/actions/writeContract.ts +20 -24
- package/src/{createConnector.ts → connectors/createConnector.ts} +7 -4
- package/src/connectors/injected.ts +550 -0
- package/src/connectors/mock.ts +174 -0
- package/src/createConfig.ts +60 -43
- package/src/exports/actions.ts +40 -7
- package/src/exports/index.ts +31 -9
- package/src/exports/internal.ts +13 -0
- package/src/version.ts +1 -1
- package/dist/esm/createConnector.js +0 -8
- package/dist/esm/createConnector.js.map +0 -1
- package/dist/types/createConnector.d.ts.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Address } from 'viem'
|
|
1
|
+
import { type Address, type Chain } from 'viem'
|
|
2
2
|
|
|
3
3
|
import { type Config, type Connector } from '../createConfig.js'
|
|
4
4
|
|
|
@@ -6,6 +6,7 @@ export type GetAccountReturnType =
|
|
|
6
6
|
| {
|
|
7
7
|
address: Address
|
|
8
8
|
addresses: readonly [Address, ...Address[]]
|
|
9
|
+
chain: Chain | undefined
|
|
9
10
|
chainId: number
|
|
10
11
|
connector: Connector
|
|
11
12
|
isConnected: true
|
|
@@ -17,6 +18,7 @@ export type GetAccountReturnType =
|
|
|
17
18
|
| {
|
|
18
19
|
address: Address | undefined
|
|
19
20
|
addresses: readonly Address[] | undefined
|
|
21
|
+
chain: Chain | undefined
|
|
20
22
|
chainId: number | undefined
|
|
21
23
|
connector: Connector | undefined
|
|
22
24
|
isConnected: boolean
|
|
@@ -28,6 +30,7 @@ export type GetAccountReturnType =
|
|
|
28
30
|
| {
|
|
29
31
|
address: Address | undefined
|
|
30
32
|
addresses: readonly Address[] | undefined
|
|
33
|
+
chain: Chain | undefined
|
|
31
34
|
chainId: number | undefined
|
|
32
35
|
connector: Connector | undefined
|
|
33
36
|
isConnected: false
|
|
@@ -39,6 +42,7 @@ export type GetAccountReturnType =
|
|
|
39
42
|
| {
|
|
40
43
|
address: undefined
|
|
41
44
|
addresses: undefined
|
|
45
|
+
chain: Chain | undefined
|
|
42
46
|
chainId: undefined
|
|
43
47
|
connector: undefined
|
|
44
48
|
isConnected: false
|
|
@@ -54,6 +58,7 @@ export function getAccount(config: Config): GetAccountReturnType {
|
|
|
54
58
|
const connection = config.state.connections.get(uid)
|
|
55
59
|
const addresses = connection?.accounts
|
|
56
60
|
const address = addresses?.[0]
|
|
61
|
+
const chain = config.chains.find((chain) => chain.id === connection?.chainId)
|
|
57
62
|
const status = config.state.status
|
|
58
63
|
|
|
59
64
|
switch (status) {
|
|
@@ -61,6 +66,7 @@ export function getAccount(config: Config): GetAccountReturnType {
|
|
|
61
66
|
return {
|
|
62
67
|
address: address!,
|
|
63
68
|
addresses: addresses!,
|
|
69
|
+
chain,
|
|
64
70
|
chainId: connection?.chainId!,
|
|
65
71
|
connector: connection?.connector!,
|
|
66
72
|
isConnected: true,
|
|
@@ -73,6 +79,7 @@ export function getAccount(config: Config): GetAccountReturnType {
|
|
|
73
79
|
return {
|
|
74
80
|
address,
|
|
75
81
|
addresses,
|
|
82
|
+
chain,
|
|
76
83
|
chainId: connection?.chainId,
|
|
77
84
|
connector: connection?.connector,
|
|
78
85
|
isConnected: !!address,
|
|
@@ -85,6 +92,7 @@ export function getAccount(config: Config): GetAccountReturnType {
|
|
|
85
92
|
return {
|
|
86
93
|
address,
|
|
87
94
|
addresses,
|
|
95
|
+
chain,
|
|
88
96
|
chainId: connection?.chainId,
|
|
89
97
|
connector: connection?.connector,
|
|
90
98
|
isConnected: false,
|
|
@@ -97,6 +105,7 @@ export function getAccount(config: Config): GetAccountReturnType {
|
|
|
97
105
|
return {
|
|
98
106
|
address: undefined,
|
|
99
107
|
addresses: undefined,
|
|
108
|
+
chain,
|
|
100
109
|
chainId: undefined,
|
|
101
110
|
connector: undefined,
|
|
102
111
|
isConnected: false,
|
package/src/actions/reconnect.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Address } from 'viem'
|
|
2
2
|
|
|
3
|
+
import { type CreateConnectorFn } from '../connectors/createConnector.js'
|
|
3
4
|
import type { Config, Connection, Connector } from '../createConfig.js'
|
|
4
|
-
import { type CreateConnectorFn } from '../createConnector.js'
|
|
5
5
|
import type { Evaluate } from '../types/utils.js'
|
|
6
6
|
|
|
7
7
|
export type ReconnectParameters = {
|
|
@@ -63,10 +63,14 @@ export async function reconnect(
|
|
|
63
63
|
const isAuthorized = await connector.isAuthorized()
|
|
64
64
|
if (!isAuthorized) continue
|
|
65
65
|
|
|
66
|
-
const data = await connector
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
const data = await connector
|
|
67
|
+
.connect({ isReconnecting: true })
|
|
68
|
+
.catch(() => null)
|
|
69
|
+
if (!data) continue
|
|
70
|
+
|
|
71
|
+
connector.emitter.off('connect', config._internal.events.connect)
|
|
72
|
+
connector.emitter.on('change', config._internal.events.change)
|
|
73
|
+
connector.emitter.on('disconnect', config._internal.events.disconnect)
|
|
70
74
|
|
|
71
75
|
config.setState((x) => {
|
|
72
76
|
const connections = new Map(connected ? x.connections : new Map()).set(
|
|
@@ -66,9 +66,7 @@ export function watchBlockNumber<
|
|
|
66
66
|
if (syncConnectedChain && !parameters.chainId)
|
|
67
67
|
unsubscribe = config.subscribe(
|
|
68
68
|
({ chainId }) => chainId,
|
|
69
|
-
async (chainId) =>
|
|
70
|
-
return listener(chainId)
|
|
71
|
-
},
|
|
69
|
+
async (chainId) => listener(chainId),
|
|
72
70
|
)
|
|
73
71
|
|
|
74
72
|
return () => {
|
|
@@ -75,9 +75,7 @@ export function watchBlocks<
|
|
|
75
75
|
if (syncConnectedChain && !parameters.chainId)
|
|
76
76
|
unsubscribe = config.subscribe(
|
|
77
77
|
({ chainId }) => chainId,
|
|
78
|
-
async (chainId) =>
|
|
79
|
-
return listener(chainId)
|
|
80
|
-
},
|
|
78
|
+
async (chainId) => listener(chainId),
|
|
81
79
|
)
|
|
82
80
|
|
|
83
81
|
return () => {
|
|
@@ -86,9 +86,7 @@ export function watchContractEvent<
|
|
|
86
86
|
if (syncConnectedChain && !parameters.chainId)
|
|
87
87
|
unsubscribe = config.subscribe(
|
|
88
88
|
({ chainId }) => chainId,
|
|
89
|
-
async (chainId) =>
|
|
90
|
-
return listener(chainId)
|
|
91
|
-
},
|
|
89
|
+
async (chainId) => listener(chainId),
|
|
92
90
|
)
|
|
93
91
|
|
|
94
92
|
return () => {
|
|
@@ -67,9 +67,7 @@ export function watchPendingTransactions<
|
|
|
67
67
|
if (syncConnectedChain && !parameters.chainId)
|
|
68
68
|
unsubscribe = config.subscribe(
|
|
69
69
|
({ chainId }) => chainId,
|
|
70
|
-
async (chainId) =>
|
|
71
|
-
return listener(chainId)
|
|
72
|
-
},
|
|
70
|
+
async (chainId) => listener(chainId),
|
|
73
71
|
)
|
|
74
72
|
|
|
75
73
|
return () => {
|
|
@@ -15,7 +15,7 @@ import type {
|
|
|
15
15
|
ChainIdParameter,
|
|
16
16
|
ConnectorParameter,
|
|
17
17
|
} from '../types/properties.js'
|
|
18
|
-
import type { Evaluate, UnionOmit } from '../types/utils.js'
|
|
18
|
+
import type { Evaluate, UnionEvaluate, UnionOmit } from '../types/utils.js'
|
|
19
19
|
import { assertActiveChain } from '../utils/assertActiveChain.js'
|
|
20
20
|
import { getConnectorClient } from './getConnectorClient.js'
|
|
21
21
|
import {
|
|
@@ -39,22 +39,24 @@ export type WriteContractParameters<
|
|
|
39
39
|
///
|
|
40
40
|
allFunctionNames = ContractFunctionName<abi, 'nonpayable' | 'payable'>,
|
|
41
41
|
chains extends readonly Chain[] = SelectChains<config, chainId>,
|
|
42
|
-
> =
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
42
|
+
> = UnionEvaluate<
|
|
43
|
+
{
|
|
44
|
+
[key in keyof chains]: UnionOmit<
|
|
45
|
+
viem_WriteContractParameters<
|
|
46
|
+
abi,
|
|
47
|
+
functionName,
|
|
48
|
+
args,
|
|
49
|
+
chains[key],
|
|
50
|
+
Account,
|
|
51
|
+
chains[key],
|
|
52
|
+
allFunctionNames
|
|
53
|
+
>,
|
|
54
|
+
'chain'
|
|
55
|
+
>
|
|
56
|
+
}[number] &
|
|
57
|
+
Evaluate<ChainIdParameter<config, chainId>> &
|
|
58
|
+
ConnectorParameter & { __mode?: 'prepared' }
|
|
59
|
+
>
|
|
58
60
|
|
|
59
61
|
export type WriteContractReturnType = viem_WriteContractReturnType
|
|
60
62
|
|
|
@@ -91,13 +93,7 @@ export async function writeContract<
|
|
|
91
93
|
} else {
|
|
92
94
|
const { request: simulateRequest } = await simulateContract(
|
|
93
95
|
config,
|
|
94
|
-
rest as
|
|
95
|
-
abi,
|
|
96
|
-
functionName,
|
|
97
|
-
args,
|
|
98
|
-
config,
|
|
99
|
-
chainId
|
|
100
|
-
>,
|
|
96
|
+
rest as SimulateContractParameters,
|
|
101
97
|
)
|
|
102
98
|
request = simulateRequest
|
|
103
99
|
}
|
|
@@ -6,9 +6,9 @@ import {
|
|
|
6
6
|
type ProviderMessage,
|
|
7
7
|
} from 'viem'
|
|
8
8
|
|
|
9
|
-
import { Emitter } from '
|
|
10
|
-
import { type Storage } from '
|
|
11
|
-
import { type Evaluate } from '
|
|
9
|
+
import { Emitter } from '../createEmitter.js'
|
|
10
|
+
import { type Storage } from '../createStorage.js'
|
|
11
|
+
import { type Evaluate } from '../types/utils.js'
|
|
12
12
|
|
|
13
13
|
export type ConnectorEventMap = {
|
|
14
14
|
change: {
|
|
@@ -31,12 +31,15 @@ export type CreateConnectorFn<
|
|
|
31
31
|
storage?: Evaluate<Storage<storageItem>> | null | undefined
|
|
32
32
|
}) => Evaluate<
|
|
33
33
|
{
|
|
34
|
+
readonly icon?: string | undefined
|
|
34
35
|
readonly id: string
|
|
35
36
|
readonly name: string
|
|
36
37
|
|
|
37
38
|
setup?(): Promise<void>
|
|
38
39
|
connect(
|
|
39
|
-
parameters?:
|
|
40
|
+
parameters?:
|
|
41
|
+
| { chainId?: number | undefined; isReconnecting?: boolean | undefined }
|
|
42
|
+
| undefined,
|
|
40
43
|
): Promise<{
|
|
41
44
|
accounts: readonly Address[]
|
|
42
45
|
chainId: number
|