@wagmi/core 2.5.0 → 2.6.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/dist/esm/actions/call.js +3 -1
- package/dist/esm/actions/call.js.map +1 -1
- package/dist/esm/actions/estimateFeesPerGas.js +6 -1
- package/dist/esm/actions/estimateFeesPerGas.js.map +1 -1
- package/dist/esm/actions/estimateGas.js +3 -4
- package/dist/esm/actions/estimateGas.js.map +1 -1
- package/dist/esm/actions/estimateMaxPriorityFeePerGas.js +3 -1
- package/dist/esm/actions/estimateMaxPriorityFeePerGas.js.map +1 -1
- package/dist/esm/actions/getBalance.js +3 -1
- package/dist/esm/actions/getBalance.js.map +1 -1
- package/dist/esm/actions/getBlock.js +3 -1
- package/dist/esm/actions/getBlock.js.map +1 -1
- package/dist/esm/actions/getBlockNumber.js +3 -1
- package/dist/esm/actions/getBlockNumber.js.map +1 -1
- package/dist/esm/actions/getBlockTransactionCount.js +3 -1
- package/dist/esm/actions/getBlockTransactionCount.js.map +1 -1
- package/dist/esm/actions/getBytecode.js +3 -1
- package/dist/esm/actions/getBytecode.js.map +1 -1
- package/dist/esm/actions/getClient.js +6 -1
- package/dist/esm/actions/getClient.js.map +1 -1
- package/dist/esm/actions/getEnsAddress.js +3 -1
- package/dist/esm/actions/getEnsAddress.js.map +1 -1
- package/dist/esm/actions/getEnsAvatar.js +3 -1
- package/dist/esm/actions/getEnsAvatar.js.map +1 -1
- package/dist/esm/actions/getEnsName.js +3 -1
- package/dist/esm/actions/getEnsName.js.map +1 -1
- package/dist/esm/actions/getEnsResolver.js +3 -1
- package/dist/esm/actions/getEnsResolver.js.map +1 -1
- package/dist/esm/actions/getEnsText.js +3 -1
- package/dist/esm/actions/getEnsText.js.map +1 -1
- package/dist/esm/actions/getFeeHistory.js +3 -1
- package/dist/esm/actions/getFeeHistory.js.map +1 -1
- package/dist/esm/actions/getGasPrice.js +3 -1
- package/dist/esm/actions/getGasPrice.js.map +1 -1
- package/dist/esm/actions/getProof.js +3 -1
- package/dist/esm/actions/getProof.js.map +1 -1
- package/dist/esm/actions/getPublicClient.js +3 -2
- package/dist/esm/actions/getPublicClient.js.map +1 -1
- package/dist/esm/actions/getStorageAt.js +3 -1
- package/dist/esm/actions/getStorageAt.js.map +1 -1
- package/dist/esm/actions/getTransaction.js +3 -1
- package/dist/esm/actions/getTransaction.js.map +1 -1
- package/dist/esm/actions/getTransactionConfirmations.js +3 -1
- package/dist/esm/actions/getTransactionConfirmations.js.map +1 -1
- package/dist/esm/actions/getTransactionCount.js +3 -1
- package/dist/esm/actions/getTransactionCount.js.map +1 -1
- package/dist/esm/actions/getTransactionReceipt.js +3 -1
- package/dist/esm/actions/getTransactionReceipt.js.map +1 -1
- package/dist/esm/actions/multicall.js +3 -1
- package/dist/esm/actions/multicall.js.map +1 -1
- package/dist/esm/actions/prepareTransactionRequest.js +3 -1
- package/dist/esm/actions/prepareTransactionRequest.js.map +1 -1
- package/dist/esm/actions/readContract.js +3 -1
- package/dist/esm/actions/readContract.js.map +1 -1
- package/dist/esm/actions/sendTransaction.js +7 -3
- package/dist/esm/actions/sendTransaction.js.map +1 -1
- package/dist/esm/actions/signMessage.js +3 -1
- package/dist/esm/actions/signMessage.js.map +1 -1
- package/dist/esm/actions/signTypedData.js +3 -1
- package/dist/esm/actions/signTypedData.js.map +1 -1
- package/dist/esm/actions/simulateContract.js +3 -5
- package/dist/esm/actions/simulateContract.js.map +1 -1
- package/dist/esm/actions/verifyMessage.js +3 -1
- package/dist/esm/actions/verifyMessage.js.map +1 -1
- package/dist/esm/actions/verifyTypedData.js +3 -1
- package/dist/esm/actions/verifyTypedData.js.map +1 -1
- package/dist/esm/actions/waitForTransactionReceipt.js +10 -10
- package/dist/esm/actions/waitForTransactionReceipt.js.map +1 -1
- package/dist/esm/actions/watchBlockNumber.js +3 -1
- package/dist/esm/actions/watchBlockNumber.js.map +1 -1
- package/dist/esm/actions/watchBlocks.js +3 -1
- package/dist/esm/actions/watchBlocks.js.map +1 -1
- package/dist/esm/actions/watchContractEvent.js +3 -1
- package/dist/esm/actions/watchContractEvent.js.map +1 -1
- package/dist/esm/actions/watchPendingTransactions.js +3 -1
- package/dist/esm/actions/watchPendingTransactions.js.map +1 -1
- package/dist/esm/actions/writeContract.js +3 -1
- package/dist/esm/actions/writeContract.js.map +1 -1
- package/dist/esm/connectors/injected.js +6 -4
- package/dist/esm/connectors/injected.js.map +1 -1
- package/dist/esm/connectors/mock.js +4 -2
- package/dist/esm/connectors/mock.js.map +1 -1
- package/dist/esm/createConfig.js +9 -15
- package/dist/esm/createConfig.js.map +1 -1
- package/dist/esm/tsconfig.build.tsbuildinfo +1 -1
- package/dist/esm/utils/getAction.js +18 -0
- package/dist/esm/utils/getAction.js.map +1 -0
- package/dist/esm/version.js +1 -1
- package/dist/types/actions/call.d.ts.map +1 -1
- package/dist/types/actions/estimateFeesPerGas.d.ts.map +1 -1
- package/dist/types/actions/estimateGas.d.ts.map +1 -1
- package/dist/types/actions/estimateMaxPriorityFeePerGas.d.ts.map +1 -1
- package/dist/types/actions/getBalance.d.ts.map +1 -1
- package/dist/types/actions/getBlock.d.ts.map +1 -1
- package/dist/types/actions/getBlockNumber.d.ts.map +1 -1
- package/dist/types/actions/getBlockTransactionCount.d.ts.map +1 -1
- package/dist/types/actions/getBytecode.d.ts.map +1 -1
- package/dist/types/actions/getClient.d.ts +6 -6
- package/dist/types/actions/getClient.d.ts.map +1 -1
- package/dist/types/actions/getEnsAddress.d.ts.map +1 -1
- package/dist/types/actions/getEnsAvatar.d.ts.map +1 -1
- package/dist/types/actions/getEnsName.d.ts.map +1 -1
- package/dist/types/actions/getEnsResolver.d.ts.map +1 -1
- package/dist/types/actions/getEnsText.d.ts.map +1 -1
- package/dist/types/actions/getFeeHistory.d.ts.map +1 -1
- package/dist/types/actions/getGasPrice.d.ts.map +1 -1
- package/dist/types/actions/getProof.d.ts.map +1 -1
- package/dist/types/actions/getPublicClient.d.ts +6 -6
- package/dist/types/actions/getPublicClient.d.ts.map +1 -1
- package/dist/types/actions/getStorageAt.d.ts.map +1 -1
- package/dist/types/actions/getTransaction.d.ts.map +1 -1
- package/dist/types/actions/getTransactionConfirmations.d.ts.map +1 -1
- package/dist/types/actions/getTransactionCount.d.ts.map +1 -1
- package/dist/types/actions/getTransactionReceipt.d.ts.map +1 -1
- package/dist/types/actions/multicall.d.ts.map +1 -1
- package/dist/types/actions/prepareTransactionRequest.d.ts.map +1 -1
- package/dist/types/actions/readContract.d.ts.map +1 -1
- package/dist/types/actions/sendTransaction.d.ts.map +1 -1
- package/dist/types/actions/signMessage.d.ts.map +1 -1
- package/dist/types/actions/signTypedData.d.ts.map +1 -1
- package/dist/types/actions/simulateContract.d.ts.map +1 -1
- package/dist/types/actions/verifyMessage.d.ts.map +1 -1
- package/dist/types/actions/verifyTypedData.d.ts.map +1 -1
- package/dist/types/actions/waitForTransactionReceipt.d.ts +2 -2
- package/dist/types/actions/waitForTransactionReceipt.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.map +1 -1
- package/dist/types/connectors/injected.d.ts +1 -1
- package/dist/types/connectors/injected.d.ts.map +1 -1
- package/dist/types/connectors/mock.d.ts.map +1 -1
- package/dist/types/createConfig.d.ts.map +1 -1
- package/dist/types/utils/getAction.d.ts +12 -0
- package/dist/types/utils/getAction.d.ts.map +1 -0
- package/dist/types/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/actions/call.ts +3 -1
- package/src/actions/estimateFeesPerGas.ts +10 -2
- package/src/actions/estimateGas.ts +3 -4
- package/src/actions/estimateMaxPriorityFeePerGas.ts +7 -1
- package/src/actions/getBalance.ts +3 -2
- package/src/actions/getBlock.ts +3 -1
- package/src/actions/getBlockNumber.ts +3 -1
- package/src/actions/getBlockTransactionCount.ts +7 -1
- package/src/actions/getBytecode.ts +3 -1
- package/src/actions/getClient.ts +33 -11
- package/src/actions/getEnsAddress.ts +3 -1
- package/src/actions/getEnsAvatar.ts +3 -1
- package/src/actions/getEnsName.ts +3 -1
- package/src/actions/getEnsResolver.ts +3 -1
- package/src/actions/getEnsText.ts +3 -1
- package/src/actions/getFeeHistory.ts +3 -1
- package/src/actions/getGasPrice.ts +3 -1
- package/src/actions/getProof.ts +3 -1
- package/src/actions/getPublicClient.ts +30 -12
- package/src/actions/getStorageAt.ts +3 -1
- package/src/actions/getTransaction.ts +3 -1
- package/src/actions/getTransactionConfirmations.ts +5 -2
- package/src/actions/getTransactionCount.ts +5 -2
- package/src/actions/getTransactionReceipt.ts +7 -1
- package/src/actions/multicall.ts +3 -1
- package/src/actions/prepareTransactionRequest.ts +6 -1
- package/src/actions/readContract.ts +3 -1
- package/src/actions/sendTransaction.ts +7 -3
- package/src/actions/signMessage.ts +3 -1
- package/src/actions/signTypedData.ts +3 -4
- package/src/actions/simulateContract.ts +3 -5
- package/src/actions/verifyMessage.ts +3 -1
- package/src/actions/verifyTypedData.ts +3 -1
- package/src/actions/waitForTransactionReceipt.ts +19 -16
- package/src/actions/watchBlockNumber.ts +3 -4
- package/src/actions/watchBlocks.ts +3 -1
- package/src/actions/watchContractEvent.ts +5 -2
- package/src/actions/watchPendingTransactions.ts +5 -2
- package/src/actions/writeContract.ts +3 -1
- package/src/connectors/injected.ts +9 -4
- package/src/connectors/mock.ts +5 -2
- package/src/createConfig.ts +9 -15
- package/src/utils/getAction.ts +38 -0
- package/src/version.ts +1 -1
|
@@ -10,6 +10,7 @@ import { type Config } from '../createConfig.js'
|
|
|
10
10
|
import type { BaseErrorType, ErrorType } from '../errors/base.js'
|
|
11
11
|
import type { ConnectorParameter } from '../types/properties.js'
|
|
12
12
|
import type { UnionEvaluate } from '../types/utils.js'
|
|
13
|
+
import { getAction } from '../utils/getAction.js'
|
|
13
14
|
import {
|
|
14
15
|
type GetConnectorClientErrorType,
|
|
15
16
|
getConnectorClient,
|
|
@@ -46,8 +47,6 @@ export async function signTypedData<
|
|
|
46
47
|
): Promise<SignTypedDataReturnType> {
|
|
47
48
|
const { account, connector, ...rest } = parameters
|
|
48
49
|
const client = await getConnectorClient(config, { account, connector })
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
rest as unknown as viem_SignTypedDataParameters,
|
|
52
|
-
)
|
|
50
|
+
const action = getAction(client, viem_signTypedData, 'signTypedData')
|
|
51
|
+
return action(rest as unknown as viem_SignTypedDataParameters)
|
|
53
52
|
}
|
|
@@ -26,6 +26,7 @@ import type {
|
|
|
26
26
|
UnionEvaluate,
|
|
27
27
|
UnionOmit,
|
|
28
28
|
} from '../types/utils.js'
|
|
29
|
+
import { getAction } from '../utils/getAction.js'
|
|
29
30
|
import {
|
|
30
31
|
type GetConnectorClientErrorType,
|
|
31
32
|
getConnectorClient,
|
|
@@ -148,11 +149,8 @@ export async function simulateContract<
|
|
|
148
149
|
}
|
|
149
150
|
|
|
150
151
|
const client = config.getClient({ chainId })
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
abi,
|
|
154
|
-
account,
|
|
155
|
-
})
|
|
152
|
+
const action = getAction(client, viem_simulateContract, 'simulateContract')
|
|
153
|
+
const { result, request } = await action({ ...rest, abi, account })
|
|
156
154
|
|
|
157
155
|
return {
|
|
158
156
|
chainId: client.chain.id,
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
import { type Config } from '../createConfig.js'
|
|
9
9
|
import { type ChainIdParameter } from '../types/properties.js'
|
|
10
10
|
import { type Evaluate } from '../types/utils.js'
|
|
11
|
+
import { getAction } from '../utils/getAction.js'
|
|
11
12
|
|
|
12
13
|
export type VerifyMessageParameters<config extends Config = Config> = Evaluate<
|
|
13
14
|
viem_VerifyMessageParameters & ChainIdParameter<config>
|
|
@@ -24,5 +25,6 @@ export async function verifyMessage<config extends Config>(
|
|
|
24
25
|
): Promise<VerifyMessageReturnType> {
|
|
25
26
|
const { chainId, ...rest } = parameters
|
|
26
27
|
const client = config.getClient({ chainId })
|
|
27
|
-
|
|
28
|
+
const action = getAction(client, viem_verifyMessage, 'verifyMessage')
|
|
29
|
+
return action(rest)
|
|
28
30
|
}
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
import { type Config } from '../createConfig.js'
|
|
10
10
|
import { type ChainIdParameter } from '../types/properties.js'
|
|
11
11
|
import { type Evaluate } from '../types/utils.js'
|
|
12
|
+
import { getAction } from '../utils/getAction.js'
|
|
12
13
|
|
|
13
14
|
export type VerifyTypedDataParameters<
|
|
14
15
|
typedData extends TypedData | Record<string, unknown> = TypedData,
|
|
@@ -34,5 +35,6 @@ export async function verifyTypedData<
|
|
|
34
35
|
): Promise<VerifyTypedDataReturnType> {
|
|
35
36
|
const { chainId, ...rest } = parameters
|
|
36
37
|
const client = config.getClient({ chainId })
|
|
37
|
-
|
|
38
|
+
const action = getAction(client, viem_verifyTypedData, 'verifyTypedData')
|
|
39
|
+
return action(rest as viem_VerifyTypedDataParameters)
|
|
38
40
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { type Chain } from 'viem'
|
|
2
2
|
import { hexToString } from 'viem'
|
|
3
3
|
import {
|
|
4
4
|
type WaitForTransactionReceiptErrorType as viem_WaitForTransactionReceiptErrorType,
|
|
@@ -10,9 +10,10 @@ import {
|
|
|
10
10
|
} from 'viem/actions'
|
|
11
11
|
|
|
12
12
|
import { type Config } from '../createConfig.js'
|
|
13
|
-
import type
|
|
13
|
+
import { type SelectChains } from '../types/chain.js'
|
|
14
14
|
import { type ChainIdParameter } from '../types/properties.js'
|
|
15
15
|
import { type Evaluate, type IsNarrowable } from '../types/utils.js'
|
|
16
|
+
import { getAction } from '../utils/getAction.js'
|
|
16
17
|
|
|
17
18
|
export type WaitForTransactionReceiptParameters<
|
|
18
19
|
config extends Config = Config,
|
|
@@ -47,29 +48,31 @@ export async function waitForTransactionReceipt<
|
|
|
47
48
|
const { chainId, timeout = 0, ...rest } = parameters
|
|
48
49
|
|
|
49
50
|
const client = config.getClient({ chainId })
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
const action = getAction(
|
|
52
|
+
client,
|
|
53
|
+
viem_waitForTransactionReceipt,
|
|
54
|
+
'waitForTransactionReceipt',
|
|
55
|
+
)
|
|
56
|
+
const receipt = await action({ ...rest, timeout })
|
|
54
57
|
|
|
55
58
|
if (receipt.status === 'reverted') {
|
|
56
|
-
const
|
|
57
|
-
|
|
59
|
+
const action_getTransaction = getAction(
|
|
60
|
+
client,
|
|
61
|
+
getTransaction,
|
|
62
|
+
'getTransaction',
|
|
63
|
+
)
|
|
64
|
+
const txn = await action_getTransaction({ hash: receipt.transactionHash })
|
|
65
|
+
const action_call = getAction(client, call, 'call')
|
|
66
|
+
const code = (await action_call({
|
|
58
67
|
...txn,
|
|
59
68
|
gasPrice: txn.type !== 'eip1559' ? txn.gasPrice : undefined,
|
|
60
69
|
maxFeePerGas: txn.type === 'eip1559' ? txn.maxFeePerGas : undefined,
|
|
61
70
|
maxPriorityFeePerGas:
|
|
62
71
|
txn.type === 'eip1559' ? txn.maxPriorityFeePerGas : undefined,
|
|
63
|
-
}
|
|
72
|
+
})) as unknown as string
|
|
64
73
|
const reason = hexToString(`0x${code.substring(138)}`)
|
|
65
74
|
throw new Error(reason)
|
|
66
75
|
}
|
|
67
76
|
|
|
68
|
-
return {
|
|
69
|
-
...(receipt as unknown as WaitForTransactionReceiptReturnType<
|
|
70
|
-
config,
|
|
71
|
-
chainId
|
|
72
|
-
>),
|
|
73
|
-
chainId: client.chain.id,
|
|
74
|
-
}
|
|
77
|
+
return { ...receipt, chainId: client.chain.id }
|
|
75
78
|
}
|
|
@@ -12,6 +12,7 @@ import type {
|
|
|
12
12
|
SyncConnectedChainParameter,
|
|
13
13
|
} from '../types/properties.js'
|
|
14
14
|
import type { UnionEvaluate } from '../types/utils.js'
|
|
15
|
+
import { getAction } from '../utils/getAction.js'
|
|
15
16
|
|
|
16
17
|
export type WatchBlockNumberParameters<
|
|
17
18
|
config extends Config = Config,
|
|
@@ -51,10 +52,8 @@ export function watchBlockNumber<
|
|
|
51
52
|
if (unwatch) unwatch()
|
|
52
53
|
|
|
53
54
|
const client = config.getClient({ chainId })
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
rest as viem_WatchBlockNumberParameters,
|
|
57
|
-
)
|
|
55
|
+
const action = getAction(client, viem_watchBlockNumber, 'watchBlockNumber')
|
|
56
|
+
unwatch = action(rest as viem_WatchBlockNumberParameters)
|
|
58
57
|
return unwatch
|
|
59
58
|
}
|
|
60
59
|
|
|
@@ -12,6 +12,7 @@ import type {
|
|
|
12
12
|
SyncConnectedChainParameter,
|
|
13
13
|
} from '../types/properties.js'
|
|
14
14
|
import type { IsNarrowable, UnionEvaluate } from '../types/utils.js'
|
|
15
|
+
import { getAction } from '../utils/getAction.js'
|
|
15
16
|
|
|
16
17
|
export type WatchBlocksParameters<
|
|
17
18
|
includeTransactions extends boolean = false,
|
|
@@ -63,7 +64,8 @@ export function watchBlocks<
|
|
|
63
64
|
if (unwatch) unwatch()
|
|
64
65
|
|
|
65
66
|
const client = config.getClient({ chainId })
|
|
66
|
-
|
|
67
|
+
const action = getAction(client, viem_watchBlocks, 'watchBlocks')
|
|
68
|
+
unwatch = action(rest as viem_WatchBlocksParameters)
|
|
67
69
|
return unwatch
|
|
68
70
|
}
|
|
69
71
|
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
type SyncConnectedChainParameter,
|
|
19
19
|
} from '../types/properties.js'
|
|
20
20
|
import { type UnionEvaluate } from '../types/utils.js'
|
|
21
|
+
import { getAction } from '../utils/getAction.js'
|
|
21
22
|
|
|
22
23
|
export type WatchContractEventParameters<
|
|
23
24
|
abi extends Abi | readonly unknown[] = Abi,
|
|
@@ -72,10 +73,12 @@ export function watchContractEvent<
|
|
|
72
73
|
if (unwatch) unwatch()
|
|
73
74
|
|
|
74
75
|
const client = config.getClient({ chainId })
|
|
75
|
-
|
|
76
|
+
const action = getAction(
|
|
76
77
|
client,
|
|
77
|
-
|
|
78
|
+
viem_watchContractEvent,
|
|
79
|
+
'watchContractEvent',
|
|
78
80
|
)
|
|
81
|
+
unwatch = action(rest as unknown as viem_WatchContractEventParameters)
|
|
79
82
|
return unwatch
|
|
80
83
|
}
|
|
81
84
|
|
|
@@ -12,6 +12,7 @@ import type {
|
|
|
12
12
|
SyncConnectedChainParameter,
|
|
13
13
|
} from '../types/properties.js'
|
|
14
14
|
import type { UnionEvaluate } from '../types/utils.js'
|
|
15
|
+
import { getAction } from '../utils/getAction.js'
|
|
15
16
|
|
|
16
17
|
export type WatchPendingTransactionsParameters<
|
|
17
18
|
config extends Config = Config,
|
|
@@ -52,10 +53,12 @@ export function watchPendingTransactions<
|
|
|
52
53
|
if (unwatch) unwatch()
|
|
53
54
|
|
|
54
55
|
const client = config.getClient({ chainId })
|
|
55
|
-
|
|
56
|
+
const action = getAction(
|
|
56
57
|
client,
|
|
57
|
-
|
|
58
|
+
viem_watchPendingTransactions,
|
|
59
|
+
'watchPendingTransactions',
|
|
58
60
|
)
|
|
61
|
+
unwatch = action(rest as viem_WatchPendingTransactionsParameters)
|
|
59
62
|
return unwatch
|
|
60
63
|
}
|
|
61
64
|
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
type ConnectorParameter,
|
|
21
21
|
} from '../types/properties.js'
|
|
22
22
|
import type { Evaluate, UnionEvaluate, UnionOmit } from '../types/utils.js'
|
|
23
|
+
import { getAction } from '../utils/getAction.js'
|
|
23
24
|
import {
|
|
24
25
|
type GetConnectorClientErrorType,
|
|
25
26
|
getConnectorClient,
|
|
@@ -110,7 +111,8 @@ export async function writeContract<
|
|
|
110
111
|
request = simulateRequest
|
|
111
112
|
}
|
|
112
113
|
|
|
113
|
-
const
|
|
114
|
+
const action = getAction(client, viem_writeContract, 'writeContract')
|
|
115
|
+
const hash = await action({
|
|
114
116
|
...(request as any),
|
|
115
117
|
chain: chainId ? { id: chainId } : null,
|
|
116
118
|
})
|
|
@@ -157,7 +157,9 @@ export function injected(parameters: InjectedParameters = {}) {
|
|
|
157
157
|
method: 'wallet_requestPermissions',
|
|
158
158
|
params: [{ eth_accounts: {} }],
|
|
159
159
|
})
|
|
160
|
-
accounts = permissions[0]?.caveats?.[0]?.value?.map(
|
|
160
|
+
accounts = (permissions[0]?.caveats?.[0]?.value as string[])?.map(
|
|
161
|
+
(x) => getAddress(x),
|
|
162
|
+
)
|
|
161
163
|
} catch (err) {
|
|
162
164
|
const error = err as RpcError
|
|
163
165
|
// Not all injected providers support `wallet_requestPermissions` (e.g. MetaMask iOS).
|
|
@@ -174,7 +176,7 @@ export function injected(parameters: InjectedParameters = {}) {
|
|
|
174
176
|
const requestedAccounts = await provider.request({
|
|
175
177
|
method: 'eth_requestAccounts',
|
|
176
178
|
})
|
|
177
|
-
accounts = requestedAccounts.map(getAddress)
|
|
179
|
+
accounts = requestedAccounts.map((x) => getAddress(x))
|
|
178
180
|
}
|
|
179
181
|
|
|
180
182
|
provider.removeListener('connect', this.onConnect.bind(this))
|
|
@@ -233,7 +235,7 @@ export function injected(parameters: InjectedParameters = {}) {
|
|
|
233
235
|
const provider = await this.getProvider()
|
|
234
236
|
if (!provider) throw new ProviderNotFoundError()
|
|
235
237
|
const accounts = await provider.request({ method: 'eth_accounts' })
|
|
236
|
-
return accounts.map(getAddress)
|
|
238
|
+
return accounts.map((x) => getAddress(x))
|
|
237
239
|
},
|
|
238
240
|
async getChainId() {
|
|
239
241
|
const provider = await this.getProvider()
|
|
@@ -405,7 +407,10 @@ export function injected(parameters: InjectedParameters = {}) {
|
|
|
405
407
|
await config.storage?.removeItem(`${this.id}.disconnected`)
|
|
406
408
|
}
|
|
407
409
|
// Regular change event
|
|
408
|
-
else
|
|
410
|
+
else
|
|
411
|
+
config.emitter.emit('change', {
|
|
412
|
+
accounts: accounts.map((x) => getAddress(x)),
|
|
413
|
+
})
|
|
409
414
|
},
|
|
410
415
|
onChainChanged(chain) {
|
|
411
416
|
const chainId = normalizeChainId(chain)
|
package/src/connectors/mock.ts
CHANGED
|
@@ -80,7 +80,7 @@ export function mock(parameters: MockParameters) {
|
|
|
80
80
|
if (!connected) throw new ConnectorNotConnectedError()
|
|
81
81
|
const provider = await this.getProvider()
|
|
82
82
|
const accounts = await provider.request({ method: 'eth_accounts' })
|
|
83
|
-
return accounts.map(getAddress)
|
|
83
|
+
return accounts.map((x) => getAddress(x))
|
|
84
84
|
},
|
|
85
85
|
async getChainId() {
|
|
86
86
|
const provider = await this.getProvider()
|
|
@@ -106,7 +106,10 @@ export function mock(parameters: MockParameters) {
|
|
|
106
106
|
},
|
|
107
107
|
onAccountsChanged(accounts) {
|
|
108
108
|
if (accounts.length === 0) this.onDisconnect()
|
|
109
|
-
else
|
|
109
|
+
else
|
|
110
|
+
config.emitter.emit('change', {
|
|
111
|
+
accounts: accounts.map((x) => getAddress(x)),
|
|
112
|
+
})
|
|
110
113
|
},
|
|
111
114
|
onChainChanged(chain) {
|
|
112
115
|
const chainId = normalizeChainId(chain)
|
package/src/createConfig.ts
CHANGED
|
@@ -109,10 +109,9 @@ export function createConfig<
|
|
|
109
109
|
return connector
|
|
110
110
|
}
|
|
111
111
|
function providerDetailToConnector(providerDetail: EIP6963ProviderDetail) {
|
|
112
|
-
const { info
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
})
|
|
112
|
+
const { info } = providerDetail
|
|
113
|
+
const provider = providerDetail.provider as any
|
|
114
|
+
return injected({ target: { ...info, id: info.rdns, provider } })
|
|
116
115
|
}
|
|
117
116
|
|
|
118
117
|
const clients = new Map<number, Client<Transport, chains[number]>>()
|
|
@@ -122,6 +121,9 @@ export function createConfig<
|
|
|
122
121
|
const chainId = config.chainId ?? store.getState().chainId
|
|
123
122
|
const chain = chains.find((x) => x.id === chainId)
|
|
124
123
|
|
|
124
|
+
// chainId specified and not configured
|
|
125
|
+
if (config.chainId && !chain) throw new ChainNotConfiguredError()
|
|
126
|
+
|
|
125
127
|
// If the target chain is not configured, use the client of the current chain.
|
|
126
128
|
type Return = Client<Transport, Extract<chains[number], { id: chainId }>>
|
|
127
129
|
{
|
|
@@ -156,10 +158,7 @@ export function createConfig<
|
|
|
156
158
|
chain,
|
|
157
159
|
batch: properties.batch ?? { multicall: true },
|
|
158
160
|
transport: (parameters) =>
|
|
159
|
-
rest.transports[chainId]({
|
|
160
|
-
...parameters,
|
|
161
|
-
connectors,
|
|
162
|
-
}),
|
|
161
|
+
rest.transports[chainId]({ ...parameters, connectors }),
|
|
163
162
|
})
|
|
164
163
|
}
|
|
165
164
|
|
|
@@ -192,13 +191,8 @@ export function createConfig<
|
|
|
192
191
|
value: Array.from(state.connections.entries()).map(
|
|
193
192
|
([key, connection]) => {
|
|
194
193
|
const { id, name, type, uid } = connection.connector
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
{
|
|
198
|
-
...connection,
|
|
199
|
-
connector: { id, name, type, uid },
|
|
200
|
-
},
|
|
201
|
-
]
|
|
194
|
+
const connector = { id, name, type, uid }
|
|
195
|
+
return [key, { ...connection, connector }]
|
|
202
196
|
},
|
|
203
197
|
),
|
|
204
198
|
} as unknown as PartializedState['connections'],
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Account,
|
|
3
|
+
type Chain,
|
|
4
|
+
type Client,
|
|
5
|
+
type PublicActions,
|
|
6
|
+
type RpcSchema,
|
|
7
|
+
type Transport,
|
|
8
|
+
type WalletActions,
|
|
9
|
+
} from 'viem'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Retrieves and returns an action from the client (if exists), and falls
|
|
13
|
+
* back to the tree-shakable action.
|
|
14
|
+
*
|
|
15
|
+
* Useful for extracting overridden actions from a client (ie. if a consumer
|
|
16
|
+
* wants to override the `sendTransaction` implementation).
|
|
17
|
+
*/
|
|
18
|
+
export function getAction<
|
|
19
|
+
transport extends Transport,
|
|
20
|
+
chain extends Chain | undefined,
|
|
21
|
+
account extends Account | undefined,
|
|
22
|
+
rpcSchema extends RpcSchema | undefined,
|
|
23
|
+
extended extends { [key: string]: unknown },
|
|
24
|
+
client extends Client<transport, chain, account, rpcSchema, extended>,
|
|
25
|
+
parameters,
|
|
26
|
+
returnType,
|
|
27
|
+
>(
|
|
28
|
+
client: client,
|
|
29
|
+
actionFn: (_: any, parameters: parameters) => returnType,
|
|
30
|
+
// Some minifiers drop `Function.prototype.name`, meaning that `action.name`
|
|
31
|
+
// will not work. For that case, the consumer needs to pass the name explicitly.
|
|
32
|
+
name: keyof PublicActions | keyof WalletActions,
|
|
33
|
+
): (parameters: parameters) => returnType {
|
|
34
|
+
const action = client[actionFn.name ?? name]
|
|
35
|
+
if (typeof action === 'function')
|
|
36
|
+
return action as (params: parameters) => returnType
|
|
37
|
+
return (params) => actionFn(client, params)
|
|
38
|
+
}
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '2.
|
|
1
|
+
export const version = '2.6.1'
|