@wagmi/core 1.3.2-cjs → 1.3.2
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/chains.js +203 -203
- package/dist/chunk-BVC4KGLQ.js +8 -8
- package/dist/chunk-D7TYCC3T.js +204 -204
- package/dist/chunk-EQOEZP46.js +5 -5
- package/dist/chunk-KFW652VN.js +6 -6
- package/dist/chunk-KX4UEHS5.js +0 -1
- package/dist/chunk-LAFZBYO7.js +231 -231
- package/dist/chunk-MQXBDTVK.js +7 -7
- package/dist/connectors/coinbaseWallet.js +5 -5
- package/dist/connectors/index.js +9 -9
- package/dist/connectors/injected.js +7 -7
- package/dist/connectors/ledger.js +5 -5
- package/dist/connectors/metaMask.js +5 -5
- package/dist/connectors/mock.js +9 -9
- package/dist/connectors/safe.js +5 -5
- package/dist/connectors/walletConnect.js +5 -5
- package/dist/connectors/walletConnectLegacy.js +5 -5
- package/dist/index.js +136 -136
- package/dist/internal/index.js +10 -10
- package/dist/internal/test.js +38 -38
- package/dist/providers/alchemy.js +6 -6
- package/dist/providers/infura.js +6 -6
- package/dist/providers/jsonRpc.js +4 -4
- package/dist/providers/public.js +4 -4
- package/dist/window.js +0 -1
- package/package.json +5 -4
package/dist/chunk-LAFZBYO7.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import {
|
|
2
|
+
InjectedConnector
|
|
3
|
+
} from "./chunk-BVC4KGLQ.js";
|
|
4
|
+
import {
|
|
5
|
+
__privateAdd,
|
|
6
|
+
__privateGet,
|
|
7
|
+
__privateMethod,
|
|
8
|
+
__privateSet
|
|
9
|
+
} from "./chunk-MQXBDTVK.js";
|
|
10
10
|
|
|
11
11
|
// src/utils/configureChains.ts
|
|
12
|
-
|
|
12
|
+
import { createPublicClient, fallback, http, webSocket } from "viem";
|
|
13
13
|
function configureChains(defaultChains, providers, {
|
|
14
14
|
batch = { multicall: { wait: 32 } },
|
|
15
15
|
pollingInterval = 4e3,
|
|
@@ -58,15 +58,15 @@ function configureChains(defaultChains, providers, {
|
|
|
58
58
|
return {
|
|
59
59
|
chains,
|
|
60
60
|
publicClient: ({ chainId }) => {
|
|
61
|
-
const activeChain =
|
|
61
|
+
const activeChain = chains.find((x) => x.id === chainId) ?? defaultChains[0];
|
|
62
62
|
const chainHttpUrls = httpUrls[activeChain.id];
|
|
63
63
|
if (!chainHttpUrls || !chainHttpUrls[0])
|
|
64
64
|
throw new Error(`No providers configured for chain "${activeChain.id}"`);
|
|
65
|
-
const publicClient =
|
|
65
|
+
const publicClient = createPublicClient({
|
|
66
66
|
batch,
|
|
67
67
|
chain: activeChain,
|
|
68
|
-
transport:
|
|
69
|
-
chainHttpUrls.map((url) =>
|
|
68
|
+
transport: fallback(
|
|
69
|
+
chainHttpUrls.map((url) => http(url, { timeout: stallTimeout })),
|
|
70
70
|
{ rank, retryCount, retryDelay }
|
|
71
71
|
),
|
|
72
72
|
pollingInterval
|
|
@@ -76,15 +76,15 @@ function configureChains(defaultChains, providers, {
|
|
|
76
76
|
});
|
|
77
77
|
},
|
|
78
78
|
webSocketPublicClient: ({ chainId }) => {
|
|
79
|
-
const activeChain =
|
|
79
|
+
const activeChain = chains.find((x) => x.id === chainId) ?? defaultChains[0];
|
|
80
80
|
const chainWsUrls = wsUrls[activeChain.id];
|
|
81
81
|
if (!chainWsUrls || !chainWsUrls[0])
|
|
82
82
|
return void 0;
|
|
83
|
-
const publicClient =
|
|
83
|
+
const publicClient = createPublicClient({
|
|
84
84
|
batch,
|
|
85
85
|
chain: activeChain,
|
|
86
|
-
transport:
|
|
87
|
-
chainWsUrls.map((url) =>
|
|
86
|
+
transport: fallback(
|
|
87
|
+
chainWsUrls.map((url) => webSocket(url, { timeout: stallTimeout })),
|
|
88
88
|
{ rank, retryCount, retryDelay }
|
|
89
89
|
),
|
|
90
90
|
pollingInterval
|
|
@@ -97,7 +97,7 @@ function configureChains(defaultChains, providers, {
|
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
// src/errors.ts
|
|
100
|
-
|
|
100
|
+
import { ConnectorNotFoundError } from "@wagmi/connectors";
|
|
101
101
|
var ChainMismatchError = class extends Error {
|
|
102
102
|
constructor({
|
|
103
103
|
activeChain,
|
|
@@ -247,13 +247,13 @@ function getSendTransactionParameters(args) {
|
|
|
247
247
|
}
|
|
248
248
|
|
|
249
249
|
// src/utils/getUnit.ts
|
|
250
|
-
|
|
250
|
+
import { weiUnits } from "viem";
|
|
251
251
|
function getUnit(unit) {
|
|
252
252
|
if (typeof unit === "number")
|
|
253
253
|
return unit;
|
|
254
254
|
if (unit === "wei")
|
|
255
255
|
return 0;
|
|
256
|
-
return Math.abs(
|
|
256
|
+
return Math.abs(weiUnits[unit]);
|
|
257
257
|
}
|
|
258
258
|
|
|
259
259
|
// src/utils/serialize.ts
|
|
@@ -307,15 +307,15 @@ function serialize(value, replacer, indent, circularReplacer) {
|
|
|
307
307
|
value,
|
|
308
308
|
createReplacer((key, value_) => {
|
|
309
309
|
const value2 = typeof value_ === "bigint" ? `#bigint.${value_.toString()}` : value_;
|
|
310
|
-
return
|
|
310
|
+
return replacer?.(key, value2) || value2;
|
|
311
311
|
}, circularReplacer),
|
|
312
|
-
|
|
312
|
+
indent ?? void 0
|
|
313
313
|
);
|
|
314
314
|
}
|
|
315
315
|
|
|
316
316
|
// src/config.ts
|
|
317
|
-
|
|
318
|
-
|
|
317
|
+
import { persist, subscribeWithSelector } from "zustand/middleware";
|
|
318
|
+
import { createStore } from "zustand/vanilla";
|
|
319
319
|
|
|
320
320
|
// src/storage.ts
|
|
321
321
|
var noopStorage = {
|
|
@@ -361,7 +361,7 @@ var _isAutoConnecting, _lastUsedConnector, _addEffects, addEffects_fn;
|
|
|
361
361
|
var Config = class {
|
|
362
362
|
constructor({
|
|
363
363
|
autoConnect = false,
|
|
364
|
-
connectors = [new
|
|
364
|
+
connectors = [new InjectedConnector()],
|
|
365
365
|
publicClient,
|
|
366
366
|
storage = createStorage({
|
|
367
367
|
storage: typeof window !== "undefined" ? window.localStorage : noopStorage
|
|
@@ -371,11 +371,11 @@ var Config = class {
|
|
|
371
371
|
},
|
|
372
372
|
webSocketPublicClient
|
|
373
373
|
}) {
|
|
374
|
-
|
|
374
|
+
__privateAdd(this, _addEffects);
|
|
375
375
|
this.publicClients = /* @__PURE__ */ new Map();
|
|
376
376
|
this.webSocketPublicClients = /* @__PURE__ */ new Map();
|
|
377
|
-
|
|
378
|
-
|
|
377
|
+
__privateAdd(this, _isAutoConnecting, void 0);
|
|
378
|
+
__privateAdd(this, _lastUsedConnector, void 0);
|
|
379
379
|
this.args = {
|
|
380
380
|
autoConnect,
|
|
381
381
|
connectors,
|
|
@@ -389,17 +389,17 @@ var Config = class {
|
|
|
389
389
|
if (autoConnect) {
|
|
390
390
|
try {
|
|
391
391
|
const rawState = storage.getItem(storeKey);
|
|
392
|
-
const data =
|
|
393
|
-
status =
|
|
394
|
-
chainId =
|
|
392
|
+
const data = rawState?.state?.data;
|
|
393
|
+
status = data?.account ? "reconnecting" : "connecting";
|
|
394
|
+
chainId = data?.chain?.id;
|
|
395
395
|
} catch (_error) {
|
|
396
396
|
}
|
|
397
397
|
}
|
|
398
398
|
const connectors_ = typeof connectors === "function" ? connectors() : connectors;
|
|
399
399
|
connectors_.forEach((connector) => connector.setStorage(storage));
|
|
400
|
-
this.store =
|
|
401
|
-
|
|
402
|
-
|
|
400
|
+
this.store = createStore(
|
|
401
|
+
subscribeWithSelector(
|
|
402
|
+
persist(
|
|
403
403
|
() => ({
|
|
404
404
|
connectors: connectors_,
|
|
405
405
|
publicClient: this.getPublicClient({ chainId }),
|
|
@@ -412,11 +412,11 @@ var Config = class {
|
|
|
412
412
|
partialize: (state) => ({
|
|
413
413
|
...autoConnect && {
|
|
414
414
|
data: {
|
|
415
|
-
account:
|
|
416
|
-
chain:
|
|
415
|
+
account: state?.data?.account,
|
|
416
|
+
chain: state?.data?.chain
|
|
417
417
|
}
|
|
418
418
|
},
|
|
419
|
-
chains:
|
|
419
|
+
chains: state?.chains
|
|
420
420
|
}),
|
|
421
421
|
version: 2
|
|
422
422
|
}
|
|
@@ -424,8 +424,8 @@ var Config = class {
|
|
|
424
424
|
)
|
|
425
425
|
);
|
|
426
426
|
this.storage = storage;
|
|
427
|
-
|
|
428
|
-
|
|
427
|
+
__privateSet(this, _lastUsedConnector, storage?.getItem("wallet"));
|
|
428
|
+
__privateMethod(this, _addEffects, addEffects_fn).call(this);
|
|
429
429
|
if (autoConnect && typeof window !== "undefined")
|
|
430
430
|
setTimeout(async () => await this.autoConnect(), 0);
|
|
431
431
|
}
|
|
@@ -445,7 +445,7 @@ var Config = class {
|
|
|
445
445
|
return this.store.getState().error;
|
|
446
446
|
}
|
|
447
447
|
get lastUsedChainId() {
|
|
448
|
-
return
|
|
448
|
+
return this.data?.chain?.id;
|
|
449
449
|
}
|
|
450
450
|
get publicClient() {
|
|
451
451
|
return this.store.getState().publicClient;
|
|
@@ -475,21 +475,21 @@ var Config = class {
|
|
|
475
475
|
}
|
|
476
476
|
async destroy() {
|
|
477
477
|
if (this.connector)
|
|
478
|
-
await
|
|
479
|
-
|
|
478
|
+
await this.connector.disconnect?.();
|
|
479
|
+
__privateSet(this, _isAutoConnecting, false);
|
|
480
480
|
this.clearState();
|
|
481
481
|
this.store.destroy();
|
|
482
482
|
}
|
|
483
483
|
async autoConnect() {
|
|
484
|
-
if (
|
|
484
|
+
if (__privateGet(this, _isAutoConnecting))
|
|
485
485
|
return;
|
|
486
|
-
|
|
486
|
+
__privateSet(this, _isAutoConnecting, true);
|
|
487
487
|
this.setState((x) => ({
|
|
488
488
|
...x,
|
|
489
|
-
status:
|
|
489
|
+
status: x.data?.account ? "reconnecting" : "connecting"
|
|
490
490
|
}));
|
|
491
|
-
const sorted =
|
|
492
|
-
(x) => x.id ===
|
|
491
|
+
const sorted = __privateGet(this, _lastUsedConnector) ? [...this.connectors].sort(
|
|
492
|
+
(x) => x.id === __privateGet(this, _lastUsedConnector) ? -1 : 1
|
|
493
493
|
) : this.connectors;
|
|
494
494
|
let connected = false;
|
|
495
495
|
for (const connector of sorted) {
|
|
@@ -502,7 +502,7 @@ var Config = class {
|
|
|
502
502
|
this.setState((x) => ({
|
|
503
503
|
...x,
|
|
504
504
|
connector,
|
|
505
|
-
chains:
|
|
505
|
+
chains: connector?.chains,
|
|
506
506
|
data,
|
|
507
507
|
status: "connected"
|
|
508
508
|
}));
|
|
@@ -515,7 +515,7 @@ var Config = class {
|
|
|
515
515
|
data: void 0,
|
|
516
516
|
status: "disconnected"
|
|
517
517
|
}));
|
|
518
|
-
|
|
518
|
+
__privateSet(this, _isAutoConnecting, false);
|
|
519
519
|
return this.data;
|
|
520
520
|
}
|
|
521
521
|
setConnectors(connectors) {
|
|
@@ -532,18 +532,18 @@ var Config = class {
|
|
|
532
532
|
}
|
|
533
533
|
getPublicClient({ chainId } = {}) {
|
|
534
534
|
let publicClient_ = this.publicClients.get(-1);
|
|
535
|
-
if (publicClient_ &&
|
|
535
|
+
if (publicClient_ && publicClient_?.chain.id === chainId)
|
|
536
536
|
return publicClient_;
|
|
537
|
-
publicClient_ = this.publicClients.get(
|
|
537
|
+
publicClient_ = this.publicClients.get(chainId ?? -1);
|
|
538
538
|
if (publicClient_)
|
|
539
539
|
return publicClient_;
|
|
540
540
|
const { publicClient } = this.args;
|
|
541
541
|
publicClient_ = typeof publicClient === "function" ? publicClient({ chainId }) : publicClient;
|
|
542
|
-
this.publicClients.set(
|
|
542
|
+
this.publicClients.set(chainId ?? -1, publicClient_);
|
|
543
543
|
return publicClient_;
|
|
544
544
|
}
|
|
545
545
|
setPublicClient(publicClient) {
|
|
546
|
-
const chainId =
|
|
546
|
+
const chainId = this.data?.chain?.id;
|
|
547
547
|
this.args = {
|
|
548
548
|
...this.args,
|
|
549
549
|
publicClient
|
|
@@ -556,19 +556,19 @@ var Config = class {
|
|
|
556
556
|
}
|
|
557
557
|
getWebSocketPublicClient({ chainId } = {}) {
|
|
558
558
|
let webSocketPublicClient_ = this.webSocketPublicClients.get(-1);
|
|
559
|
-
if (webSocketPublicClient_ &&
|
|
559
|
+
if (webSocketPublicClient_ && webSocketPublicClient_?.chain.id === chainId)
|
|
560
560
|
return webSocketPublicClient_;
|
|
561
|
-
webSocketPublicClient_ = this.webSocketPublicClients.get(
|
|
561
|
+
webSocketPublicClient_ = this.webSocketPublicClients.get(chainId ?? -1);
|
|
562
562
|
if (webSocketPublicClient_)
|
|
563
563
|
return webSocketPublicClient_;
|
|
564
564
|
const { webSocketPublicClient } = this.args;
|
|
565
565
|
webSocketPublicClient_ = typeof webSocketPublicClient === "function" ? webSocketPublicClient({ chainId }) : webSocketPublicClient;
|
|
566
566
|
if (webSocketPublicClient_)
|
|
567
|
-
this.webSocketPublicClients.set(
|
|
567
|
+
this.webSocketPublicClients.set(chainId ?? -1, webSocketPublicClient_);
|
|
568
568
|
return webSocketPublicClient_;
|
|
569
569
|
}
|
|
570
570
|
setWebSocketPublicClient(webSocketPublicClient) {
|
|
571
|
-
const chainId =
|
|
571
|
+
const chainId = this.data?.chain?.id;
|
|
572
572
|
this.args = {
|
|
573
573
|
...this.args,
|
|
574
574
|
webSocketPublicClient
|
|
@@ -582,7 +582,7 @@ var Config = class {
|
|
|
582
582
|
}));
|
|
583
583
|
}
|
|
584
584
|
setLastUsedConnector(lastUsedConnector = null) {
|
|
585
|
-
|
|
585
|
+
this.storage?.setItem("wallet", lastUsedConnector);
|
|
586
586
|
}
|
|
587
587
|
};
|
|
588
588
|
_isAutoConnecting = new WeakMap();
|
|
@@ -604,14 +604,14 @@ addEffects_fn = function() {
|
|
|
604
604
|
this.store.subscribe(
|
|
605
605
|
({ connector }) => connector,
|
|
606
606
|
(connector, prevConnector) => {
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
607
|
+
prevConnector?.off?.("change", onChange);
|
|
608
|
+
prevConnector?.off?.("disconnect", onDisconnect);
|
|
609
|
+
prevConnector?.off?.("error", onError);
|
|
610
610
|
if (!connector)
|
|
611
611
|
return;
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
612
|
+
connector.on?.("change", onChange);
|
|
613
|
+
connector.on?.("disconnect", onDisconnect);
|
|
614
|
+
connector.on?.("error", onError);
|
|
615
615
|
}
|
|
616
616
|
);
|
|
617
617
|
const { publicClient, webSocketPublicClient } = this.args;
|
|
@@ -619,7 +619,7 @@ addEffects_fn = function() {
|
|
|
619
619
|
const subscribeWebSocketPublicClient = typeof webSocketPublicClient === "function";
|
|
620
620
|
if (subscribePublicClient || subscribeWebSocketPublicClient)
|
|
621
621
|
this.store.subscribe(
|
|
622
|
-
({ data }) =>
|
|
622
|
+
({ data }) => data?.chain?.id,
|
|
623
623
|
(chainId) => {
|
|
624
624
|
this.setState((x) => ({
|
|
625
625
|
...x,
|
|
@@ -659,7 +659,7 @@ async function connect({ chainId, connector }) {
|
|
|
659
659
|
config2.setState((x) => ({
|
|
660
660
|
...x,
|
|
661
661
|
connector,
|
|
662
|
-
chains:
|
|
662
|
+
chains: connector?.chains,
|
|
663
663
|
data,
|
|
664
664
|
status: "connected"
|
|
665
665
|
}));
|
|
@@ -686,12 +686,12 @@ async function disconnect() {
|
|
|
686
686
|
}
|
|
687
687
|
|
|
688
688
|
// src/actions/accounts/fetchBalance.ts
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
689
|
+
import {
|
|
690
|
+
ContractFunctionExecutionError as ContractFunctionExecutionError3,
|
|
691
|
+
formatUnits as formatUnits2,
|
|
692
|
+
hexToString as hexToString2,
|
|
693
|
+
trim as trim2
|
|
694
|
+
} from "viem";
|
|
695
695
|
|
|
696
696
|
// src/constants/abis.ts
|
|
697
697
|
var erc20ABI = [
|
|
@@ -1922,12 +1922,12 @@ var erc4626ABI = [
|
|
|
1922
1922
|
];
|
|
1923
1923
|
|
|
1924
1924
|
// src/actions/contracts/fetchToken.ts
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1925
|
+
import {
|
|
1926
|
+
ContractFunctionExecutionError,
|
|
1927
|
+
formatUnits,
|
|
1928
|
+
hexToString,
|
|
1929
|
+
trim
|
|
1930
|
+
} from "viem";
|
|
1931
1931
|
async function fetchToken({
|
|
1932
1932
|
address,
|
|
1933
1933
|
chainId,
|
|
@@ -1950,7 +1950,7 @@ async function fetchToken({
|
|
|
1950
1950
|
name,
|
|
1951
1951
|
symbol,
|
|
1952
1952
|
totalSupply: {
|
|
1953
|
-
formatted:
|
|
1953
|
+
formatted: formatUnits(totalSupply, getUnit(unit)),
|
|
1954
1954
|
value: totalSupply
|
|
1955
1955
|
}
|
|
1956
1956
|
};
|
|
@@ -1958,13 +1958,13 @@ async function fetchToken({
|
|
|
1958
1958
|
try {
|
|
1959
1959
|
return await fetchToken_({ abi: erc20ABI });
|
|
1960
1960
|
} catch (err) {
|
|
1961
|
-
if (err instanceof
|
|
1961
|
+
if (err instanceof ContractFunctionExecutionError) {
|
|
1962
1962
|
const { name, symbol, ...rest } = await fetchToken_({
|
|
1963
1963
|
abi: erc20ABI_bytes32
|
|
1964
1964
|
});
|
|
1965
1965
|
return {
|
|
1966
|
-
name:
|
|
1967
|
-
symbol:
|
|
1966
|
+
name: hexToString(trim(name, { dir: "right" })),
|
|
1967
|
+
symbol: hexToString(trim(symbol, { dir: "right" })),
|
|
1968
1968
|
...rest
|
|
1969
1969
|
};
|
|
1970
1970
|
}
|
|
@@ -1985,7 +1985,7 @@ async function getWalletClient({
|
|
|
1985
1985
|
chainId
|
|
1986
1986
|
} = {}) {
|
|
1987
1987
|
const config2 = getConfig();
|
|
1988
|
-
const walletClient = await
|
|
1988
|
+
const walletClient = await config2.connector?.getWalletClient?.({ chainId }) || null;
|
|
1989
1989
|
return walletClient;
|
|
1990
1990
|
}
|
|
1991
1991
|
|
|
@@ -2011,7 +2011,7 @@ function watchPublicClient(args, callback) {
|
|
|
2011
2011
|
}
|
|
2012
2012
|
|
|
2013
2013
|
// src/actions/viem/watchWalletClient.ts
|
|
2014
|
-
|
|
2014
|
+
import { shallow } from "zustand/shallow";
|
|
2015
2015
|
function watchWalletClient({ chainId }, callback) {
|
|
2016
2016
|
const config2 = getConfig();
|
|
2017
2017
|
const handleChange = async ({ chainId: chainId_ }) => {
|
|
@@ -2024,13 +2024,13 @@ function watchWalletClient({ chainId }, callback) {
|
|
|
2024
2024
|
};
|
|
2025
2025
|
const unsubscribe = config2.subscribe(
|
|
2026
2026
|
({ data, connector }) => ({
|
|
2027
|
-
account:
|
|
2028
|
-
chainId:
|
|
2027
|
+
account: data?.account,
|
|
2028
|
+
chainId: data?.chain?.id,
|
|
2029
2029
|
connector
|
|
2030
2030
|
}),
|
|
2031
2031
|
handleChange,
|
|
2032
2032
|
{
|
|
2033
|
-
equalityFn:
|
|
2033
|
+
equalityFn: shallow
|
|
2034
2034
|
}
|
|
2035
2035
|
);
|
|
2036
2036
|
return unsubscribe;
|
|
@@ -2058,9 +2058,9 @@ async function prepareWriteContract({
|
|
|
2058
2058
|
...config2
|
|
2059
2059
|
}) {
|
|
2060
2060
|
const publicClient = getPublicClient({ chainId });
|
|
2061
|
-
const walletClient =
|
|
2061
|
+
const walletClient = walletClient_ ?? await getWalletClient({ chainId });
|
|
2062
2062
|
if (!walletClient)
|
|
2063
|
-
throw new
|
|
2063
|
+
throw new ConnectorNotFoundError();
|
|
2064
2064
|
if (chainId)
|
|
2065
2065
|
assertActiveChain({ chainId });
|
|
2066
2066
|
const {
|
|
@@ -2106,7 +2106,7 @@ async function prepareWriteContract({
|
|
|
2106
2106
|
}
|
|
2107
2107
|
|
|
2108
2108
|
// src/actions/contracts/getContract.ts
|
|
2109
|
-
|
|
2109
|
+
import { getContract as getContract_ } from "viem";
|
|
2110
2110
|
function getContract({
|
|
2111
2111
|
address,
|
|
2112
2112
|
abi,
|
|
@@ -2114,7 +2114,7 @@ function getContract({
|
|
|
2114
2114
|
walletClient
|
|
2115
2115
|
}) {
|
|
2116
2116
|
const publicClient = getPublicClient({ chainId });
|
|
2117
|
-
return
|
|
2117
|
+
return getContract_({
|
|
2118
2118
|
address,
|
|
2119
2119
|
abi,
|
|
2120
2120
|
publicClient,
|
|
@@ -2136,7 +2136,7 @@ async function multicall({
|
|
|
2136
2136
|
if (chainId && publicClient.chain.id !== chainId)
|
|
2137
2137
|
throw new ChainNotConfiguredError({ chainId });
|
|
2138
2138
|
return publicClient.multicall({
|
|
2139
|
-
allowFailure:
|
|
2139
|
+
allowFailure: args.allowFailure ?? true,
|
|
2140
2140
|
blockNumber,
|
|
2141
2141
|
blockTag,
|
|
2142
2142
|
contracts
|
|
@@ -2167,7 +2167,7 @@ async function readContract({
|
|
|
2167
2167
|
}
|
|
2168
2168
|
|
|
2169
2169
|
// src/actions/contracts/readContracts.ts
|
|
2170
|
-
|
|
2170
|
+
import { ContractFunctionExecutionError as ContractFunctionExecutionError2 } from "viem";
|
|
2171
2171
|
async function readContracts({
|
|
2172
2172
|
contracts,
|
|
2173
2173
|
blockNumber,
|
|
@@ -2178,7 +2178,7 @@ async function readContracts({
|
|
|
2178
2178
|
try {
|
|
2179
2179
|
const publicClient = getPublicClient();
|
|
2180
2180
|
const contractsByChainId = contracts.reduce((contracts2, contract, index) => {
|
|
2181
|
-
const chainId =
|
|
2181
|
+
const chainId = contract.chainId ?? publicClient.chain.id;
|
|
2182
2182
|
return {
|
|
2183
2183
|
...contracts2,
|
|
2184
2184
|
[chainId]: [...contracts2[chainId] || [], { contract, index }]
|
|
@@ -2205,7 +2205,7 @@ async function readContracts({
|
|
|
2205
2205
|
return results;
|
|
2206
2206
|
}, []);
|
|
2207
2207
|
} catch (err) {
|
|
2208
|
-
if (err instanceof
|
|
2208
|
+
if (err instanceof ContractFunctionExecutionError2)
|
|
2209
2209
|
throw err;
|
|
2210
2210
|
const promises = () => contracts.map(
|
|
2211
2211
|
(contract) => readContract({ ...contract, blockNumber, blockTag })
|
|
@@ -2221,7 +2221,7 @@ async function readContracts({
|
|
|
2221
2221
|
}
|
|
2222
2222
|
|
|
2223
2223
|
// src/actions/contracts/watchContractEvent.ts
|
|
2224
|
-
|
|
2224
|
+
import { shallow as shallow2 } from "zustand/shallow";
|
|
2225
2225
|
function watchContractEvent({
|
|
2226
2226
|
address,
|
|
2227
2227
|
abi,
|
|
@@ -2248,16 +2248,16 @@ function watchContractEvent({
|
|
|
2248
2248
|
webSocketPublicClient
|
|
2249
2249
|
}),
|
|
2250
2250
|
watchEvent,
|
|
2251
|
-
{ equalityFn:
|
|
2251
|
+
{ equalityFn: shallow2 }
|
|
2252
2252
|
);
|
|
2253
2253
|
return () => {
|
|
2254
|
-
|
|
2254
|
+
unwatch?.();
|
|
2255
2255
|
unsubscribe();
|
|
2256
2256
|
};
|
|
2257
2257
|
}
|
|
2258
2258
|
|
|
2259
2259
|
// src/actions/network-status/watchBlockNumber.ts
|
|
2260
|
-
|
|
2260
|
+
import { shallow as shallow3 } from "zustand/shallow";
|
|
2261
2261
|
function watchBlockNumber(args, callback) {
|
|
2262
2262
|
let unwatch;
|
|
2263
2263
|
const createListener = (publicClient) => {
|
|
@@ -2269,7 +2269,7 @@ function watchBlockNumber(args, callback) {
|
|
|
2269
2269
|
poll: true
|
|
2270
2270
|
});
|
|
2271
2271
|
};
|
|
2272
|
-
const publicClient_ =
|
|
2272
|
+
const publicClient_ = getWebSocketPublicClient({ chainId: args.chainId }) ?? getPublicClient({ chainId: args.chainId });
|
|
2273
2273
|
if (args.listen)
|
|
2274
2274
|
createListener(publicClient_);
|
|
2275
2275
|
const config2 = getConfig();
|
|
@@ -2279,18 +2279,18 @@ function watchBlockNumber(args, callback) {
|
|
|
2279
2279
|
webSocketPublicClient
|
|
2280
2280
|
}),
|
|
2281
2281
|
async ({ publicClient, webSocketPublicClient }) => {
|
|
2282
|
-
const publicClient_2 =
|
|
2282
|
+
const publicClient_2 = webSocketPublicClient ?? publicClient;
|
|
2283
2283
|
if (args.listen && !args.chainId && publicClient_2) {
|
|
2284
2284
|
createListener(publicClient_2);
|
|
2285
2285
|
}
|
|
2286
2286
|
},
|
|
2287
2287
|
{
|
|
2288
|
-
equalityFn:
|
|
2288
|
+
equalityFn: shallow3
|
|
2289
2289
|
}
|
|
2290
2290
|
);
|
|
2291
2291
|
return () => {
|
|
2292
2292
|
unsubscribe();
|
|
2293
|
-
|
|
2293
|
+
unwatch?.();
|
|
2294
2294
|
};
|
|
2295
2295
|
}
|
|
2296
2296
|
|
|
@@ -2305,7 +2305,7 @@ function watchMulticall(args, callback) {
|
|
|
2305
2305
|
);
|
|
2306
2306
|
return () => {
|
|
2307
2307
|
unsubscribe();
|
|
2308
|
-
|
|
2308
|
+
unwatch?.();
|
|
2309
2309
|
};
|
|
2310
2310
|
}
|
|
2311
2311
|
|
|
@@ -2320,7 +2320,7 @@ function watchReadContract(args, callback) {
|
|
|
2320
2320
|
);
|
|
2321
2321
|
return () => {
|
|
2322
2322
|
unsubscribe();
|
|
2323
|
-
|
|
2323
|
+
unwatch?.();
|
|
2324
2324
|
};
|
|
2325
2325
|
}
|
|
2326
2326
|
|
|
@@ -2335,7 +2335,7 @@ function watchReadContracts(args, callback) {
|
|
|
2335
2335
|
);
|
|
2336
2336
|
return () => {
|
|
2337
2337
|
unsubscribe();
|
|
2338
|
-
|
|
2338
|
+
unwatch?.();
|
|
2339
2339
|
};
|
|
2340
2340
|
}
|
|
2341
2341
|
|
|
@@ -2343,7 +2343,7 @@ function watchReadContracts(args, callback) {
|
|
|
2343
2343
|
async function writeContract(config2) {
|
|
2344
2344
|
const walletClient = await getWalletClient({ chainId: config2.chainId });
|
|
2345
2345
|
if (!walletClient)
|
|
2346
|
-
throw new
|
|
2346
|
+
throw new ConnectorNotFoundError();
|
|
2347
2347
|
if (config2.chainId)
|
|
2348
2348
|
assertActiveChain({ chainId: config2.chainId });
|
|
2349
2349
|
let request;
|
|
@@ -2387,7 +2387,7 @@ async function fetchBalance({
|
|
|
2387
2387
|
});
|
|
2388
2388
|
return {
|
|
2389
2389
|
decimals,
|
|
2390
|
-
formatted:
|
|
2390
|
+
formatted: formatUnits2(value2 ?? "0", getUnit(unit ?? decimals)),
|
|
2391
2391
|
symbol,
|
|
2392
2392
|
value: value2
|
|
2393
2393
|
};
|
|
@@ -2395,12 +2395,12 @@ async function fetchBalance({
|
|
|
2395
2395
|
try {
|
|
2396
2396
|
return await fetchContractBalance({ abi: erc20ABI });
|
|
2397
2397
|
} catch (err) {
|
|
2398
|
-
if (err instanceof
|
|
2398
|
+
if (err instanceof ContractFunctionExecutionError3) {
|
|
2399
2399
|
const { symbol, ...rest } = await fetchContractBalance({
|
|
2400
2400
|
abi: erc20ABI_bytes32
|
|
2401
2401
|
});
|
|
2402
2402
|
return {
|
|
2403
|
-
symbol:
|
|
2403
|
+
symbol: hexToString2(trim2(symbol, { dir: "right" })),
|
|
2404
2404
|
...rest
|
|
2405
2405
|
};
|
|
2406
2406
|
}
|
|
@@ -2409,14 +2409,14 @@ async function fetchBalance({
|
|
|
2409
2409
|
}
|
|
2410
2410
|
const chains = [
|
|
2411
2411
|
...config2.publicClient.chains || [],
|
|
2412
|
-
...
|
|
2412
|
+
...config2.chains ?? []
|
|
2413
2413
|
];
|
|
2414
2414
|
const value = await publicClient.getBalance({ address });
|
|
2415
2415
|
const chain = chains.find((x) => x.id === publicClient.chain.id);
|
|
2416
2416
|
return {
|
|
2417
|
-
decimals:
|
|
2418
|
-
formatted:
|
|
2419
|
-
symbol:
|
|
2417
|
+
decimals: chain?.nativeCurrency.decimals ?? 18,
|
|
2418
|
+
formatted: formatUnits2(value ?? "0", getUnit(unit ?? 18)),
|
|
2419
|
+
symbol: chain?.nativeCurrency.symbol ?? "ETH",
|
|
2420
2420
|
value
|
|
2421
2421
|
};
|
|
2422
2422
|
}
|
|
@@ -2427,7 +2427,7 @@ function getAccount() {
|
|
|
2427
2427
|
switch (status) {
|
|
2428
2428
|
case "connected":
|
|
2429
2429
|
return {
|
|
2430
|
-
address:
|
|
2430
|
+
address: data?.account,
|
|
2431
2431
|
connector,
|
|
2432
2432
|
isConnected: true,
|
|
2433
2433
|
isConnecting: false,
|
|
@@ -2437,9 +2437,9 @@ function getAccount() {
|
|
|
2437
2437
|
};
|
|
2438
2438
|
case "reconnecting":
|
|
2439
2439
|
return {
|
|
2440
|
-
address:
|
|
2440
|
+
address: data?.account,
|
|
2441
2441
|
connector,
|
|
2442
|
-
isConnected: !!
|
|
2442
|
+
isConnected: !!data?.account,
|
|
2443
2443
|
isConnecting: false,
|
|
2444
2444
|
isDisconnected: false,
|
|
2445
2445
|
isReconnecting: true,
|
|
@@ -2447,7 +2447,7 @@ function getAccount() {
|
|
|
2447
2447
|
};
|
|
2448
2448
|
case "connecting":
|
|
2449
2449
|
return {
|
|
2450
|
-
address:
|
|
2450
|
+
address: data?.account,
|
|
2451
2451
|
connector,
|
|
2452
2452
|
isConnected: false,
|
|
2453
2453
|
isConnecting: true,
|
|
@@ -2471,12 +2471,12 @@ function getAccount() {
|
|
|
2471
2471
|
// src/actions/accounts/getNetwork.ts
|
|
2472
2472
|
function getNetwork() {
|
|
2473
2473
|
const config2 = getConfig();
|
|
2474
|
-
const chainId =
|
|
2475
|
-
const activeChains =
|
|
2476
|
-
const activeChain =
|
|
2477
|
-
...
|
|
2474
|
+
const chainId = config2.data?.chain?.id;
|
|
2475
|
+
const activeChains = config2.chains ?? [];
|
|
2476
|
+
const activeChain = [
|
|
2477
|
+
...config2.publicClient?.chains || [],
|
|
2478
2478
|
...activeChains
|
|
2479
|
-
].find((x) => x.id === chainId)
|
|
2479
|
+
].find((x) => x.id === chainId) ?? {
|
|
2480
2480
|
id: chainId,
|
|
2481
2481
|
name: `Chain ${chainId}`,
|
|
2482
2482
|
network: `${chainId}`,
|
|
@@ -2485,11 +2485,11 @@ function getNetwork() {
|
|
|
2485
2485
|
default: { http: [""] },
|
|
2486
2486
|
public: { http: [""] }
|
|
2487
2487
|
}
|
|
2488
|
-
}
|
|
2488
|
+
};
|
|
2489
2489
|
return {
|
|
2490
2490
|
chain: chainId ? {
|
|
2491
2491
|
...activeChain,
|
|
2492
|
-
...
|
|
2492
|
+
...config2.data?.chain,
|
|
2493
2493
|
id: chainId
|
|
2494
2494
|
} : void 0,
|
|
2495
2495
|
chains: activeChains
|
|
@@ -2500,7 +2500,7 @@ function getNetwork() {
|
|
|
2500
2500
|
async function signMessage(args) {
|
|
2501
2501
|
const walletClient = await getWalletClient();
|
|
2502
2502
|
if (!walletClient)
|
|
2503
|
-
throw new
|
|
2503
|
+
throw new ConnectorNotFoundError();
|
|
2504
2504
|
return await walletClient.signMessage({
|
|
2505
2505
|
message: args.message
|
|
2506
2506
|
});
|
|
@@ -2515,7 +2515,7 @@ async function signTypedData({
|
|
|
2515
2515
|
}) {
|
|
2516
2516
|
const walletClient = await getWalletClient();
|
|
2517
2517
|
if (!walletClient)
|
|
2518
|
-
throw new
|
|
2518
|
+
throw new ConnectorNotFoundError();
|
|
2519
2519
|
const { chainId } = domain;
|
|
2520
2520
|
if (chainId)
|
|
2521
2521
|
assertActiveChain({ chainId });
|
|
@@ -2533,7 +2533,7 @@ async function switchNetwork({
|
|
|
2533
2533
|
}) {
|
|
2534
2534
|
const { connector } = getConfig();
|
|
2535
2535
|
if (!connector)
|
|
2536
|
-
throw new
|
|
2536
|
+
throw new ConnectorNotFoundError();
|
|
2537
2537
|
if (!connector.switchChain)
|
|
2538
2538
|
throw new SwitchChainNotSupportedError({
|
|
2539
2539
|
connector
|
|
@@ -2542,90 +2542,90 @@ async function switchNetwork({
|
|
|
2542
2542
|
}
|
|
2543
2543
|
|
|
2544
2544
|
// src/actions/accounts/watchAccount.ts
|
|
2545
|
-
|
|
2545
|
+
import { shallow as shallow4 } from "zustand/shallow";
|
|
2546
2546
|
function watchAccount(callback, { selector = (x) => x } = {}) {
|
|
2547
2547
|
const config2 = getConfig();
|
|
2548
2548
|
const handleChange = () => callback(getAccount());
|
|
2549
2549
|
const unsubscribe = config2.subscribe(
|
|
2550
2550
|
({ data, connector, status }) => selector({
|
|
2551
|
-
address:
|
|
2551
|
+
address: data?.account,
|
|
2552
2552
|
connector,
|
|
2553
2553
|
status
|
|
2554
2554
|
}),
|
|
2555
2555
|
handleChange,
|
|
2556
2556
|
{
|
|
2557
|
-
equalityFn:
|
|
2557
|
+
equalityFn: shallow4
|
|
2558
2558
|
}
|
|
2559
2559
|
);
|
|
2560
2560
|
return unsubscribe;
|
|
2561
2561
|
}
|
|
2562
2562
|
|
|
2563
2563
|
// src/actions/accounts/watchNetwork.ts
|
|
2564
|
-
|
|
2564
|
+
import { shallow as shallow5 } from "zustand/shallow";
|
|
2565
2565
|
function watchNetwork(callback, { selector = (x) => x } = {}) {
|
|
2566
2566
|
const config2 = getConfig();
|
|
2567
2567
|
const handleChange = () => callback(getNetwork());
|
|
2568
2568
|
const unsubscribe = config2.subscribe(
|
|
2569
|
-
({ data, chains }) => selector({ chainId:
|
|
2569
|
+
({ data, chains }) => selector({ chainId: data?.chain?.id, chains }),
|
|
2570
2570
|
handleChange,
|
|
2571
2571
|
{
|
|
2572
|
-
equalityFn:
|
|
2572
|
+
equalityFn: shallow5
|
|
2573
2573
|
}
|
|
2574
2574
|
);
|
|
2575
2575
|
return unsubscribe;
|
|
2576
2576
|
}
|
|
2577
2577
|
|
|
2578
2578
|
// src/actions/ens/fetchEnsAddress.ts
|
|
2579
|
-
|
|
2580
|
-
|
|
2579
|
+
import { getAddress } from "viem";
|
|
2580
|
+
import { normalize } from "viem/ens";
|
|
2581
2581
|
async function fetchEnsAddress({
|
|
2582
2582
|
chainId,
|
|
2583
2583
|
name
|
|
2584
2584
|
}) {
|
|
2585
2585
|
const publicClient = getPublicClient({ chainId });
|
|
2586
2586
|
const address = await publicClient.getEnsAddress({
|
|
2587
|
-
name:
|
|
2587
|
+
name: normalize(name)
|
|
2588
2588
|
});
|
|
2589
2589
|
try {
|
|
2590
2590
|
if (address === "0x0000000000000000000000000000000000000000")
|
|
2591
2591
|
return null;
|
|
2592
|
-
return address ?
|
|
2592
|
+
return address ? getAddress(address) : null;
|
|
2593
2593
|
} catch (_error) {
|
|
2594
2594
|
return null;
|
|
2595
2595
|
}
|
|
2596
2596
|
}
|
|
2597
2597
|
|
|
2598
2598
|
// src/actions/ens/fetchEnsAvatar.ts
|
|
2599
|
-
|
|
2599
|
+
import { normalize as normalize2 } from "viem/ens";
|
|
2600
2600
|
async function fetchEnsAvatar({
|
|
2601
2601
|
name,
|
|
2602
2602
|
chainId
|
|
2603
2603
|
}) {
|
|
2604
2604
|
const publicClient = getPublicClient({ chainId });
|
|
2605
|
-
const avatar = await publicClient.getEnsAvatar({ name:
|
|
2605
|
+
const avatar = await publicClient.getEnsAvatar({ name: normalize2(name) });
|
|
2606
2606
|
return avatar;
|
|
2607
2607
|
}
|
|
2608
2608
|
|
|
2609
2609
|
// src/actions/ens/fetchEnsName.ts
|
|
2610
|
-
|
|
2610
|
+
import { getAddress as getAddress2 } from "viem";
|
|
2611
2611
|
async function fetchEnsName({
|
|
2612
2612
|
address,
|
|
2613
2613
|
chainId
|
|
2614
2614
|
}) {
|
|
2615
2615
|
const publicClient = getPublicClient({ chainId });
|
|
2616
2616
|
return publicClient.getEnsName({
|
|
2617
|
-
address:
|
|
2617
|
+
address: getAddress2(address)
|
|
2618
2618
|
});
|
|
2619
2619
|
}
|
|
2620
2620
|
|
|
2621
2621
|
// src/actions/ens/fetchEnsResolver.ts
|
|
2622
|
-
|
|
2622
|
+
import { normalize as normalize3 } from "viem/ens";
|
|
2623
2623
|
async function fetchEnsResolver({
|
|
2624
2624
|
chainId,
|
|
2625
2625
|
name
|
|
2626
2626
|
}) {
|
|
2627
2627
|
const publicClient = getPublicClient({ chainId });
|
|
2628
|
-
const resolver = await publicClient.getEnsResolver({ name:
|
|
2628
|
+
const resolver = await publicClient.getEnsResolver({ name: normalize3(name) });
|
|
2629
2629
|
return resolver;
|
|
2630
2630
|
}
|
|
2631
2631
|
|
|
@@ -2639,7 +2639,7 @@ async function fetchBlockNumber({
|
|
|
2639
2639
|
}
|
|
2640
2640
|
|
|
2641
2641
|
// src/actions/network-status/fetchFeeData.ts
|
|
2642
|
-
|
|
2642
|
+
import { formatUnits as formatUnits3, parseGwei } from "viem";
|
|
2643
2643
|
async function fetchFeeData({
|
|
2644
2644
|
chainId,
|
|
2645
2645
|
formatUnits: units = "gwei"
|
|
@@ -2649,21 +2649,21 @@ async function fetchFeeData({
|
|
|
2649
2649
|
let gasPrice = null;
|
|
2650
2650
|
try {
|
|
2651
2651
|
gasPrice = await publicClient.getGasPrice();
|
|
2652
|
-
} catch
|
|
2652
|
+
} catch {
|
|
2653
2653
|
}
|
|
2654
2654
|
let lastBaseFeePerGas = null;
|
|
2655
2655
|
let maxFeePerGas = null;
|
|
2656
2656
|
let maxPriorityFeePerGas = null;
|
|
2657
|
-
if (
|
|
2657
|
+
if (block?.baseFeePerGas) {
|
|
2658
2658
|
lastBaseFeePerGas = block.baseFeePerGas;
|
|
2659
|
-
maxPriorityFeePerGas =
|
|
2659
|
+
maxPriorityFeePerGas = parseGwei("1");
|
|
2660
2660
|
maxFeePerGas = block.baseFeePerGas * 2n + maxPriorityFeePerGas;
|
|
2661
2661
|
}
|
|
2662
2662
|
const unit = getUnit(units);
|
|
2663
2663
|
const formatted = {
|
|
2664
|
-
gasPrice: gasPrice ?
|
|
2665
|
-
maxFeePerGas: maxFeePerGas ?
|
|
2666
|
-
maxPriorityFeePerGas: maxPriorityFeePerGas ?
|
|
2664
|
+
gasPrice: gasPrice ? formatUnits3(gasPrice, unit) : null,
|
|
2665
|
+
maxFeePerGas: maxFeePerGas ? formatUnits3(maxFeePerGas, unit) : null,
|
|
2666
|
+
maxPriorityFeePerGas: maxPriorityFeePerGas ? formatUnits3(maxPriorityFeePerGas, unit) : null
|
|
2667
2667
|
};
|
|
2668
2668
|
return {
|
|
2669
2669
|
lastBaseFeePerGas,
|
|
@@ -2684,7 +2684,7 @@ async function fetchTransaction({
|
|
|
2684
2684
|
}
|
|
2685
2685
|
|
|
2686
2686
|
// src/actions/transactions/prepareSendTransaction.ts
|
|
2687
|
-
|
|
2687
|
+
import { isAddress } from "viem";
|
|
2688
2688
|
async function prepareSendTransaction({
|
|
2689
2689
|
accessList,
|
|
2690
2690
|
account,
|
|
@@ -2700,19 +2700,19 @@ async function prepareSendTransaction({
|
|
|
2700
2700
|
walletClient: walletClient_
|
|
2701
2701
|
}) {
|
|
2702
2702
|
const publicClient = getPublicClient({ chainId });
|
|
2703
|
-
const walletClient =
|
|
2703
|
+
const walletClient = walletClient_ ?? await getWalletClient({ chainId });
|
|
2704
2704
|
if (!walletClient)
|
|
2705
|
-
throw new
|
|
2705
|
+
throw new ConnectorNotFoundError();
|
|
2706
2706
|
if (chainId)
|
|
2707
2707
|
assertActiveChain({ chainId });
|
|
2708
|
-
const to = (to_ && !
|
|
2709
|
-
if (to && !
|
|
2708
|
+
const to = (to_ && !isAddress(to_) ? await fetchEnsAddress({ name: to_ }) : to_) || void 0;
|
|
2709
|
+
if (to && !isAddress(to))
|
|
2710
2710
|
throw new Error("Invalid address");
|
|
2711
2711
|
const gas = typeof gas_ === "undefined" ? await publicClient.estimateGas({
|
|
2712
2712
|
accessList,
|
|
2713
2713
|
account: walletClient.account,
|
|
2714
2714
|
data,
|
|
2715
|
-
gas:
|
|
2715
|
+
gas: gas_ ?? void 0,
|
|
2716
2716
|
gasPrice,
|
|
2717
2717
|
maxFeePerGas,
|
|
2718
2718
|
maxPriorityFeePerGas,
|
|
@@ -2753,7 +2753,7 @@ async function sendTransaction({
|
|
|
2753
2753
|
}) {
|
|
2754
2754
|
const walletClient = await getWalletClient({ chainId });
|
|
2755
2755
|
if (!walletClient)
|
|
2756
|
-
throw new
|
|
2756
|
+
throw new ConnectorNotFoundError();
|
|
2757
2757
|
if (chainId)
|
|
2758
2758
|
assertActiveChain({ chainId });
|
|
2759
2759
|
let args;
|
|
@@ -2791,7 +2791,7 @@ async function sendTransaction({
|
|
|
2791
2791
|
}
|
|
2792
2792
|
|
|
2793
2793
|
// src/actions/transactions/waitForTransaction.ts
|
|
2794
|
-
|
|
2794
|
+
import { hexToString as hexToString3 } from "viem";
|
|
2795
2795
|
async function waitForTransaction({
|
|
2796
2796
|
chainId,
|
|
2797
2797
|
confirmations = 1,
|
|
@@ -2816,14 +2816,14 @@ async function waitForTransaction({
|
|
|
2816
2816
|
maxFeePerGas: txn.type === "eip1559" ? txn.maxFeePerGas : void 0,
|
|
2817
2817
|
maxPriorityFeePerGas: txn.type === "eip1559" ? txn.maxPriorityFeePerGas : void 0
|
|
2818
2818
|
});
|
|
2819
|
-
const reason =
|
|
2819
|
+
const reason = hexToString3(`0x${code.substring(138)}`);
|
|
2820
2820
|
throw new Error(reason);
|
|
2821
2821
|
}
|
|
2822
2822
|
return receipt;
|
|
2823
2823
|
}
|
|
2824
2824
|
|
|
2825
2825
|
// src/actions/transactions/watchPendingTransactions.ts
|
|
2826
|
-
|
|
2826
|
+
import { shallow as shallow6 } from "zustand/shallow";
|
|
2827
2827
|
function watchPendingTransactions(args, callback) {
|
|
2828
2828
|
let unwatch;
|
|
2829
2829
|
const createListener = (publicClient) => {
|
|
@@ -2834,7 +2834,7 @@ function watchPendingTransactions(args, callback) {
|
|
|
2834
2834
|
poll: true
|
|
2835
2835
|
});
|
|
2836
2836
|
};
|
|
2837
|
-
const publicClient_ =
|
|
2837
|
+
const publicClient_ = getWebSocketPublicClient({ chainId: args.chainId }) ?? getPublicClient({ chainId: args.chainId });
|
|
2838
2838
|
createListener(publicClient_);
|
|
2839
2839
|
const config2 = getConfig();
|
|
2840
2840
|
const unsubscribe = config2.subscribe(
|
|
@@ -2843,92 +2843,92 @@ function watchPendingTransactions(args, callback) {
|
|
|
2843
2843
|
webSocketPublicClient
|
|
2844
2844
|
}),
|
|
2845
2845
|
async ({ publicClient, webSocketPublicClient }) => {
|
|
2846
|
-
const publicClient_2 =
|
|
2846
|
+
const publicClient_2 = webSocketPublicClient ?? publicClient;
|
|
2847
2847
|
if (!args.chainId && publicClient_2) {
|
|
2848
2848
|
createListener(publicClient_2);
|
|
2849
2849
|
}
|
|
2850
2850
|
},
|
|
2851
2851
|
{
|
|
2852
|
-
equalityFn:
|
|
2852
|
+
equalityFn: shallow6
|
|
2853
2853
|
}
|
|
2854
2854
|
);
|
|
2855
2855
|
return () => {
|
|
2856
2856
|
unsubscribe();
|
|
2857
|
-
|
|
2857
|
+
unwatch?.();
|
|
2858
2858
|
};
|
|
2859
2859
|
}
|
|
2860
2860
|
|
|
2861
2861
|
// src/utils/assertActiveChain.ts
|
|
2862
2862
|
function assertActiveChain({ chainId }) {
|
|
2863
2863
|
const { chain: activeChain, chains } = getNetwork();
|
|
2864
|
-
const activeChainId =
|
|
2864
|
+
const activeChainId = activeChain?.id;
|
|
2865
2865
|
if (activeChainId && chainId !== activeChainId) {
|
|
2866
2866
|
throw new ChainMismatchError({
|
|
2867
|
-
activeChain:
|
|
2868
|
-
targetChain:
|
|
2867
|
+
activeChain: chains.find((x) => x.id === activeChainId)?.name ?? `Chain ${activeChainId}`,
|
|
2868
|
+
targetChain: chains.find((x) => x.id === chainId)?.name ?? `Chain ${chainId}`
|
|
2869
2869
|
});
|
|
2870
2870
|
}
|
|
2871
2871
|
}
|
|
2872
2872
|
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2873
|
+
export {
|
|
2874
|
+
configureChains,
|
|
2875
|
+
ChainMismatchError,
|
|
2876
|
+
ChainNotConfiguredError,
|
|
2877
|
+
ConnectorAlreadyConnectedError,
|
|
2878
|
+
ConfigChainsNotFound,
|
|
2879
|
+
SwitchChainNotSupportedError,
|
|
2880
|
+
ConnectorNotFoundError,
|
|
2881
|
+
deepEqual,
|
|
2882
|
+
deserialize,
|
|
2883
|
+
getCallParameters,
|
|
2884
|
+
getSendTransactionParameters,
|
|
2885
|
+
getUnit,
|
|
2886
|
+
serialize,
|
|
2887
|
+
noopStorage,
|
|
2888
|
+
createStorage,
|
|
2889
|
+
Config,
|
|
2890
|
+
createConfig,
|
|
2891
|
+
getConfig,
|
|
2892
|
+
connect,
|
|
2893
|
+
disconnect,
|
|
2894
|
+
erc20ABI,
|
|
2895
|
+
erc721ABI,
|
|
2896
|
+
erc4626ABI,
|
|
2897
|
+
fetchToken,
|
|
2898
|
+
getPublicClient,
|
|
2899
|
+
getWalletClient,
|
|
2900
|
+
getWebSocketPublicClient,
|
|
2901
|
+
watchPublicClient,
|
|
2902
|
+
watchWalletClient,
|
|
2903
|
+
watchWebSocketPublicClient,
|
|
2904
|
+
prepareWriteContract,
|
|
2905
|
+
getContract,
|
|
2906
|
+
multicall,
|
|
2907
|
+
readContract,
|
|
2908
|
+
readContracts,
|
|
2909
|
+
watchContractEvent,
|
|
2910
|
+
watchBlockNumber,
|
|
2911
|
+
watchMulticall,
|
|
2912
|
+
watchReadContract,
|
|
2913
|
+
watchReadContracts,
|
|
2914
|
+
writeContract,
|
|
2915
|
+
fetchBalance,
|
|
2916
|
+
getAccount,
|
|
2917
|
+
getNetwork,
|
|
2918
|
+
signMessage,
|
|
2919
|
+
signTypedData,
|
|
2920
|
+
switchNetwork,
|
|
2921
|
+
watchAccount,
|
|
2922
|
+
watchNetwork,
|
|
2923
|
+
fetchEnsAddress,
|
|
2924
|
+
fetchEnsAvatar,
|
|
2925
|
+
fetchEnsName,
|
|
2926
|
+
fetchEnsResolver,
|
|
2927
|
+
fetchBlockNumber,
|
|
2928
|
+
fetchFeeData,
|
|
2929
|
+
fetchTransaction,
|
|
2930
|
+
prepareSendTransaction,
|
|
2931
|
+
sendTransaction,
|
|
2932
|
+
waitForTransaction,
|
|
2933
|
+
watchPendingTransactions
|
|
2934
|
+
};
|