@wagmi/core 1.0.2-cjs → 1.0.3
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 +187 -187
- package/dist/{chunk-VEUO7GWU.js → chunk-5YWOYJSV.js} +233 -231
- package/dist/chunk-BVC4KGLQ.js +8 -8
- package/dist/chunk-EQOEZP46.js +5 -5
- package/dist/chunk-KFW652VN.js +6 -6
- package/dist/chunk-KX4UEHS5.js +0 -1
- package/dist/chunk-MQXBDTVK.js +7 -7
- package/dist/chunk-OL6OIPEP.js +188 -188
- 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 +36 -36
- 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
|
@@ -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,
|
|
@@ -245,13 +245,13 @@ function getSendTransactionParameters(args) {
|
|
|
245
245
|
}
|
|
246
246
|
|
|
247
247
|
// src/utils/getUnit.ts
|
|
248
|
-
|
|
248
|
+
import { weiUnits } from "viem";
|
|
249
249
|
function getUnit(unit) {
|
|
250
250
|
if (typeof unit === "number")
|
|
251
251
|
return unit;
|
|
252
252
|
if (unit === "wei")
|
|
253
253
|
return 0;
|
|
254
|
-
return Math.abs(
|
|
254
|
+
return Math.abs(weiUnits[unit]);
|
|
255
255
|
}
|
|
256
256
|
|
|
257
257
|
// src/utils/serialize.ts
|
|
@@ -305,15 +305,15 @@ function serialize(value, replacer, indent, circularReplacer) {
|
|
|
305
305
|
value,
|
|
306
306
|
createReplacer((key, value_) => {
|
|
307
307
|
const value2 = typeof value_ === "bigint" ? `#bigint.${value_.toString()}` : value_;
|
|
308
|
-
return
|
|
308
|
+
return replacer?.(key, value2) || value2;
|
|
309
309
|
}, circularReplacer),
|
|
310
|
-
|
|
310
|
+
indent ?? void 0
|
|
311
311
|
);
|
|
312
312
|
}
|
|
313
313
|
|
|
314
314
|
// src/config.ts
|
|
315
|
-
|
|
316
|
-
|
|
315
|
+
import { persist, subscribeWithSelector } from "zustand/middleware";
|
|
316
|
+
import { createStore } from "zustand/vanilla";
|
|
317
317
|
|
|
318
318
|
// src/storage.ts
|
|
319
319
|
var noopStorage = {
|
|
@@ -359,7 +359,7 @@ var _isAutoConnecting, _lastUsedConnector, _addEffects, addEffects_fn;
|
|
|
359
359
|
var Config = class {
|
|
360
360
|
constructor({
|
|
361
361
|
autoConnect = false,
|
|
362
|
-
connectors = [new
|
|
362
|
+
connectors = [new InjectedConnector()],
|
|
363
363
|
publicClient,
|
|
364
364
|
storage = createStorage({
|
|
365
365
|
storage: typeof window !== "undefined" ? window.localStorage : noopStorage
|
|
@@ -369,11 +369,11 @@ var Config = class {
|
|
|
369
369
|
},
|
|
370
370
|
webSocketPublicClient
|
|
371
371
|
}) {
|
|
372
|
-
|
|
372
|
+
__privateAdd(this, _addEffects);
|
|
373
373
|
this.publicClients = /* @__PURE__ */ new Map();
|
|
374
374
|
this.webSocketPublicClients = /* @__PURE__ */ new Map();
|
|
375
|
-
|
|
376
|
-
|
|
375
|
+
__privateAdd(this, _isAutoConnecting, void 0);
|
|
376
|
+
__privateAdd(this, _lastUsedConnector, void 0);
|
|
377
377
|
this.args = {
|
|
378
378
|
autoConnect,
|
|
379
379
|
connectors,
|
|
@@ -387,17 +387,17 @@ var Config = class {
|
|
|
387
387
|
if (autoConnect) {
|
|
388
388
|
try {
|
|
389
389
|
const rawState = storage.getItem(storeKey);
|
|
390
|
-
const data =
|
|
391
|
-
status =
|
|
392
|
-
chainId =
|
|
390
|
+
const data = rawState?.state?.data;
|
|
391
|
+
status = data?.account ? "reconnecting" : "connecting";
|
|
392
|
+
chainId = data?.chain?.id;
|
|
393
393
|
} catch (_error) {
|
|
394
394
|
}
|
|
395
395
|
}
|
|
396
396
|
const connectors_ = typeof connectors === "function" ? connectors() : connectors;
|
|
397
397
|
connectors_.forEach((connector) => connector.setStorage(storage));
|
|
398
|
-
this.store =
|
|
399
|
-
|
|
400
|
-
|
|
398
|
+
this.store = createStore(
|
|
399
|
+
subscribeWithSelector(
|
|
400
|
+
persist(
|
|
401
401
|
() => ({
|
|
402
402
|
connectors: connectors_,
|
|
403
403
|
publicClient: this.getPublicClient({ chainId }),
|
|
@@ -410,11 +410,11 @@ var Config = class {
|
|
|
410
410
|
partialize: (state) => ({
|
|
411
411
|
...autoConnect && {
|
|
412
412
|
data: {
|
|
413
|
-
account:
|
|
414
|
-
chain:
|
|
413
|
+
account: state?.data?.account,
|
|
414
|
+
chain: state?.data?.chain
|
|
415
415
|
}
|
|
416
416
|
},
|
|
417
|
-
chains:
|
|
417
|
+
chains: state?.chains
|
|
418
418
|
}),
|
|
419
419
|
version: 2
|
|
420
420
|
}
|
|
@@ -422,8 +422,8 @@ var Config = class {
|
|
|
422
422
|
)
|
|
423
423
|
);
|
|
424
424
|
this.storage = storage;
|
|
425
|
-
|
|
426
|
-
|
|
425
|
+
__privateSet(this, _lastUsedConnector, storage?.getItem("wallet"));
|
|
426
|
+
__privateMethod(this, _addEffects, addEffects_fn).call(this);
|
|
427
427
|
if (autoConnect && typeof window !== "undefined")
|
|
428
428
|
setTimeout(async () => await this.autoConnect(), 0);
|
|
429
429
|
}
|
|
@@ -443,7 +443,7 @@ var Config = class {
|
|
|
443
443
|
return this.store.getState().error;
|
|
444
444
|
}
|
|
445
445
|
get lastUsedChainId() {
|
|
446
|
-
return
|
|
446
|
+
return this.data?.chain?.id;
|
|
447
447
|
}
|
|
448
448
|
get publicClient() {
|
|
449
449
|
return this.store.getState().publicClient;
|
|
@@ -473,21 +473,21 @@ var Config = class {
|
|
|
473
473
|
}
|
|
474
474
|
async destroy() {
|
|
475
475
|
if (this.connector)
|
|
476
|
-
await
|
|
477
|
-
|
|
476
|
+
await this.connector.disconnect?.();
|
|
477
|
+
__privateSet(this, _isAutoConnecting, false);
|
|
478
478
|
this.clearState();
|
|
479
479
|
this.store.destroy();
|
|
480
480
|
}
|
|
481
481
|
async autoConnect() {
|
|
482
|
-
if (
|
|
482
|
+
if (__privateGet(this, _isAutoConnecting))
|
|
483
483
|
return;
|
|
484
|
-
|
|
484
|
+
__privateSet(this, _isAutoConnecting, true);
|
|
485
485
|
this.setState((x) => ({
|
|
486
486
|
...x,
|
|
487
|
-
status:
|
|
487
|
+
status: x.data?.account ? "reconnecting" : "connecting"
|
|
488
488
|
}));
|
|
489
|
-
const sorted =
|
|
490
|
-
(x) => x.id ===
|
|
489
|
+
const sorted = __privateGet(this, _lastUsedConnector) ? [...this.connectors].sort(
|
|
490
|
+
(x) => x.id === __privateGet(this, _lastUsedConnector) ? -1 : 1
|
|
491
491
|
) : this.connectors;
|
|
492
492
|
let connected = false;
|
|
493
493
|
for (const connector of sorted) {
|
|
@@ -500,7 +500,7 @@ var Config = class {
|
|
|
500
500
|
this.setState((x) => ({
|
|
501
501
|
...x,
|
|
502
502
|
connector,
|
|
503
|
-
chains:
|
|
503
|
+
chains: connector?.chains,
|
|
504
504
|
data,
|
|
505
505
|
status: "connected"
|
|
506
506
|
}));
|
|
@@ -513,7 +513,7 @@ var Config = class {
|
|
|
513
513
|
data: void 0,
|
|
514
514
|
status: "disconnected"
|
|
515
515
|
}));
|
|
516
|
-
|
|
516
|
+
__privateSet(this, _isAutoConnecting, false);
|
|
517
517
|
return this.data;
|
|
518
518
|
}
|
|
519
519
|
setConnectors(connectors) {
|
|
@@ -530,18 +530,18 @@ var Config = class {
|
|
|
530
530
|
}
|
|
531
531
|
getPublicClient({ chainId } = {}) {
|
|
532
532
|
let publicClient_ = this.publicClients.get(-1);
|
|
533
|
-
if (publicClient_ &&
|
|
533
|
+
if (publicClient_ && publicClient_?.chain.id === chainId)
|
|
534
534
|
return publicClient_;
|
|
535
|
-
publicClient_ = this.publicClients.get(
|
|
535
|
+
publicClient_ = this.publicClients.get(chainId ?? -1);
|
|
536
536
|
if (publicClient_)
|
|
537
537
|
return publicClient_;
|
|
538
538
|
const { publicClient } = this.args;
|
|
539
539
|
publicClient_ = typeof publicClient === "function" ? publicClient({ chainId }) : publicClient;
|
|
540
|
-
this.publicClients.set(
|
|
540
|
+
this.publicClients.set(chainId ?? -1, publicClient_);
|
|
541
541
|
return publicClient_;
|
|
542
542
|
}
|
|
543
543
|
setPublicClient(publicClient) {
|
|
544
|
-
const chainId =
|
|
544
|
+
const chainId = this.data?.chain?.id;
|
|
545
545
|
this.args = {
|
|
546
546
|
...this.args,
|
|
547
547
|
publicClient
|
|
@@ -554,19 +554,19 @@ var Config = class {
|
|
|
554
554
|
}
|
|
555
555
|
getWebSocketPublicClient({ chainId } = {}) {
|
|
556
556
|
let webSocketPublicClient_ = this.webSocketPublicClients.get(-1);
|
|
557
|
-
if (webSocketPublicClient_ &&
|
|
557
|
+
if (webSocketPublicClient_ && webSocketPublicClient_?.chain.id === chainId)
|
|
558
558
|
return webSocketPublicClient_;
|
|
559
|
-
webSocketPublicClient_ = this.webSocketPublicClients.get(
|
|
559
|
+
webSocketPublicClient_ = this.webSocketPublicClients.get(chainId ?? -1);
|
|
560
560
|
if (webSocketPublicClient_)
|
|
561
561
|
return webSocketPublicClient_;
|
|
562
562
|
const { webSocketPublicClient } = this.args;
|
|
563
563
|
webSocketPublicClient_ = typeof webSocketPublicClient === "function" ? webSocketPublicClient({ chainId }) : webSocketPublicClient;
|
|
564
564
|
if (webSocketPublicClient_)
|
|
565
|
-
this.webSocketPublicClients.set(
|
|
565
|
+
this.webSocketPublicClients.set(chainId ?? -1, webSocketPublicClient_);
|
|
566
566
|
return webSocketPublicClient_;
|
|
567
567
|
}
|
|
568
568
|
setWebSocketPublicClient(webSocketPublicClient) {
|
|
569
|
-
const chainId =
|
|
569
|
+
const chainId = this.data?.chain?.id;
|
|
570
570
|
this.args = {
|
|
571
571
|
...this.args,
|
|
572
572
|
webSocketPublicClient
|
|
@@ -580,7 +580,7 @@ var Config = class {
|
|
|
580
580
|
}));
|
|
581
581
|
}
|
|
582
582
|
setLastUsedConnector(lastUsedConnector = null) {
|
|
583
|
-
|
|
583
|
+
this.storage?.setItem("wallet", lastUsedConnector);
|
|
584
584
|
}
|
|
585
585
|
};
|
|
586
586
|
_isAutoConnecting = new WeakMap();
|
|
@@ -602,14 +602,14 @@ addEffects_fn = function() {
|
|
|
602
602
|
this.store.subscribe(
|
|
603
603
|
({ connector }) => connector,
|
|
604
604
|
(connector, prevConnector) => {
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
605
|
+
prevConnector?.off?.("change", onChange);
|
|
606
|
+
prevConnector?.off?.("disconnect", onDisconnect);
|
|
607
|
+
prevConnector?.off?.("error", onError);
|
|
608
608
|
if (!connector)
|
|
609
609
|
return;
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
610
|
+
connector.on?.("change", onChange);
|
|
611
|
+
connector.on?.("disconnect", onDisconnect);
|
|
612
|
+
connector.on?.("error", onError);
|
|
613
613
|
}
|
|
614
614
|
);
|
|
615
615
|
const { publicClient, webSocketPublicClient } = this.args;
|
|
@@ -617,7 +617,7 @@ addEffects_fn = function() {
|
|
|
617
617
|
const subscribeWebSocketPublicClient = typeof webSocketPublicClient === "function";
|
|
618
618
|
if (subscribePublicClient || subscribeWebSocketPublicClient)
|
|
619
619
|
this.store.subscribe(
|
|
620
|
-
({ data }) =>
|
|
620
|
+
({ data }) => data?.chain?.id,
|
|
621
621
|
(chainId) => {
|
|
622
622
|
this.setState((x) => ({
|
|
623
623
|
...x,
|
|
@@ -657,7 +657,7 @@ async function connect({ chainId, connector }) {
|
|
|
657
657
|
config2.setState((x) => ({
|
|
658
658
|
...x,
|
|
659
659
|
connector,
|
|
660
|
-
chains:
|
|
660
|
+
chains: connector?.chains,
|
|
661
661
|
data,
|
|
662
662
|
status: "connected"
|
|
663
663
|
}));
|
|
@@ -684,12 +684,12 @@ async function disconnect() {
|
|
|
684
684
|
}
|
|
685
685
|
|
|
686
686
|
// src/actions/accounts/fetchBalance.ts
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
687
|
+
import {
|
|
688
|
+
ContractFunctionExecutionError as ContractFunctionExecutionError3,
|
|
689
|
+
formatUnits as formatUnits2,
|
|
690
|
+
hexToString as hexToString2,
|
|
691
|
+
trim as trim2
|
|
692
|
+
} from "viem";
|
|
693
693
|
|
|
694
694
|
// src/constants/abis.ts
|
|
695
695
|
var erc20ABI = [
|
|
@@ -1920,12 +1920,12 @@ var erc4626ABI = [
|
|
|
1920
1920
|
];
|
|
1921
1921
|
|
|
1922
1922
|
// src/actions/contracts/fetchToken.ts
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1923
|
+
import {
|
|
1924
|
+
ContractFunctionExecutionError,
|
|
1925
|
+
formatUnits,
|
|
1926
|
+
hexToString,
|
|
1927
|
+
trim
|
|
1928
|
+
} from "viem";
|
|
1929
1929
|
async function fetchToken({
|
|
1930
1930
|
address,
|
|
1931
1931
|
chainId,
|
|
@@ -1948,7 +1948,7 @@ async function fetchToken({
|
|
|
1948
1948
|
name,
|
|
1949
1949
|
symbol,
|
|
1950
1950
|
totalSupply: {
|
|
1951
|
-
formatted:
|
|
1951
|
+
formatted: formatUnits(totalSupply, getUnit(unit)),
|
|
1952
1952
|
value: totalSupply
|
|
1953
1953
|
}
|
|
1954
1954
|
};
|
|
@@ -1956,13 +1956,13 @@ async function fetchToken({
|
|
|
1956
1956
|
try {
|
|
1957
1957
|
return await fetchToken_({ abi: erc20ABI });
|
|
1958
1958
|
} catch (err) {
|
|
1959
|
-
if (err instanceof
|
|
1959
|
+
if (err instanceof ContractFunctionExecutionError) {
|
|
1960
1960
|
const { name, symbol, ...rest } = await fetchToken_({
|
|
1961
1961
|
abi: erc20ABI_bytes32
|
|
1962
1962
|
});
|
|
1963
1963
|
return {
|
|
1964
|
-
name:
|
|
1965
|
-
symbol:
|
|
1964
|
+
name: hexToString(trim(name, { dir: "right" })),
|
|
1965
|
+
symbol: hexToString(trim(symbol, { dir: "right" })),
|
|
1966
1966
|
...rest
|
|
1967
1967
|
};
|
|
1968
1968
|
}
|
|
@@ -1983,7 +1983,7 @@ async function getWalletClient({
|
|
|
1983
1983
|
chainId
|
|
1984
1984
|
} = {}) {
|
|
1985
1985
|
const config2 = getConfig();
|
|
1986
|
-
const walletClient = await
|
|
1986
|
+
const walletClient = await config2.connector?.getWalletClient?.({ chainId }) || null;
|
|
1987
1987
|
return walletClient;
|
|
1988
1988
|
}
|
|
1989
1989
|
|
|
@@ -2009,10 +2009,12 @@ function watchPublicClient(args, callback) {
|
|
|
2009
2009
|
}
|
|
2010
2010
|
|
|
2011
2011
|
// src/actions/viem/watchWalletClient.ts
|
|
2012
|
-
|
|
2012
|
+
import { shallow } from "zustand/shallow";
|
|
2013
2013
|
function watchWalletClient({ chainId }, callback) {
|
|
2014
2014
|
const config2 = getConfig();
|
|
2015
|
-
const handleChange = async () => {
|
|
2015
|
+
const handleChange = async ({ chainId: chainId_ }) => {
|
|
2016
|
+
if (chainId && chainId_ && chainId !== chainId_)
|
|
2017
|
+
return;
|
|
2016
2018
|
const walletClient = await getWalletClient({ chainId });
|
|
2017
2019
|
if (!getConfig().connector)
|
|
2018
2020
|
return callback(null);
|
|
@@ -2020,13 +2022,13 @@ function watchWalletClient({ chainId }, callback) {
|
|
|
2020
2022
|
};
|
|
2021
2023
|
const unsubscribe = config2.subscribe(
|
|
2022
2024
|
({ data, connector }) => ({
|
|
2023
|
-
account:
|
|
2024
|
-
chainId:
|
|
2025
|
+
account: data?.account,
|
|
2026
|
+
chainId: data?.chain?.id,
|
|
2025
2027
|
connector
|
|
2026
2028
|
}),
|
|
2027
2029
|
handleChange,
|
|
2028
2030
|
{
|
|
2029
|
-
equalityFn:
|
|
2031
|
+
equalityFn: shallow
|
|
2030
2032
|
}
|
|
2031
2033
|
);
|
|
2032
2034
|
return unsubscribe;
|
|
@@ -2054,9 +2056,9 @@ async function prepareWriteContract({
|
|
|
2054
2056
|
...config2
|
|
2055
2057
|
}) {
|
|
2056
2058
|
const publicClient = getPublicClient({ chainId });
|
|
2057
|
-
const walletClient =
|
|
2059
|
+
const walletClient = walletClient_ ?? await getWalletClient({ chainId });
|
|
2058
2060
|
if (!walletClient)
|
|
2059
|
-
throw new
|
|
2061
|
+
throw new ConnectorNotFoundError();
|
|
2060
2062
|
if (chainId)
|
|
2061
2063
|
assertActiveChain({ chainId });
|
|
2062
2064
|
const {
|
|
@@ -2101,7 +2103,7 @@ async function prepareWriteContract({
|
|
|
2101
2103
|
}
|
|
2102
2104
|
|
|
2103
2105
|
// src/actions/contracts/getContract.ts
|
|
2104
|
-
|
|
2106
|
+
import { getContract as getContract_ } from "viem";
|
|
2105
2107
|
function getContract({
|
|
2106
2108
|
address,
|
|
2107
2109
|
abi,
|
|
@@ -2109,7 +2111,7 @@ function getContract({
|
|
|
2109
2111
|
walletClient
|
|
2110
2112
|
}) {
|
|
2111
2113
|
const publicClient = getPublicClient({ chainId });
|
|
2112
|
-
return
|
|
2114
|
+
return getContract_({
|
|
2113
2115
|
address,
|
|
2114
2116
|
abi,
|
|
2115
2117
|
publicClient,
|
|
@@ -2131,7 +2133,7 @@ async function multicall({
|
|
|
2131
2133
|
if (chainId && publicClient.chain.id !== chainId)
|
|
2132
2134
|
throw new ChainNotConfiguredError({ chainId });
|
|
2133
2135
|
return publicClient.multicall({
|
|
2134
|
-
allowFailure:
|
|
2136
|
+
allowFailure: args.allowFailure ?? true,
|
|
2135
2137
|
blockNumber,
|
|
2136
2138
|
blockTag,
|
|
2137
2139
|
contracts
|
|
@@ -2160,7 +2162,7 @@ async function readContract({
|
|
|
2160
2162
|
}
|
|
2161
2163
|
|
|
2162
2164
|
// src/actions/contracts/readContracts.ts
|
|
2163
|
-
|
|
2165
|
+
import { ContractFunctionExecutionError as ContractFunctionExecutionError2 } from "viem";
|
|
2164
2166
|
async function readContracts({
|
|
2165
2167
|
contracts,
|
|
2166
2168
|
blockNumber,
|
|
@@ -2171,7 +2173,7 @@ async function readContracts({
|
|
|
2171
2173
|
try {
|
|
2172
2174
|
const publicClient = getPublicClient();
|
|
2173
2175
|
const contractsByChainId = contracts.reduce((contracts2, contract, index) => {
|
|
2174
|
-
const chainId =
|
|
2176
|
+
const chainId = contract.chainId ?? publicClient.chain.id;
|
|
2175
2177
|
return {
|
|
2176
2178
|
...contracts2,
|
|
2177
2179
|
[chainId]: [...contracts2[chainId] || [], { contract, index }]
|
|
@@ -2198,7 +2200,7 @@ async function readContracts({
|
|
|
2198
2200
|
return results;
|
|
2199
2201
|
}, []);
|
|
2200
2202
|
} catch (err) {
|
|
2201
|
-
if (err instanceof
|
|
2203
|
+
if (err instanceof ContractFunctionExecutionError2)
|
|
2202
2204
|
throw err;
|
|
2203
2205
|
const promises = () => contracts.map(
|
|
2204
2206
|
(contract) => readContract({ ...contract, blockNumber, blockTag })
|
|
@@ -2214,7 +2216,7 @@ async function readContracts({
|
|
|
2214
2216
|
}
|
|
2215
2217
|
|
|
2216
2218
|
// src/actions/contracts/watchContractEvent.ts
|
|
2217
|
-
|
|
2219
|
+
import { shallow as shallow2 } from "zustand/shallow";
|
|
2218
2220
|
function watchContractEvent({
|
|
2219
2221
|
address,
|
|
2220
2222
|
abi,
|
|
@@ -2241,16 +2243,16 @@ function watchContractEvent({
|
|
|
2241
2243
|
webSocketPublicClient
|
|
2242
2244
|
}),
|
|
2243
2245
|
watchEvent,
|
|
2244
|
-
{ equalityFn:
|
|
2246
|
+
{ equalityFn: shallow2 }
|
|
2245
2247
|
);
|
|
2246
2248
|
return () => {
|
|
2247
|
-
|
|
2249
|
+
unwatch?.();
|
|
2248
2250
|
unsubscribe();
|
|
2249
2251
|
};
|
|
2250
2252
|
}
|
|
2251
2253
|
|
|
2252
2254
|
// src/actions/network-status/watchBlockNumber.ts
|
|
2253
|
-
|
|
2255
|
+
import { shallow as shallow3 } from "zustand/shallow";
|
|
2254
2256
|
function watchBlockNumber(args, callback) {
|
|
2255
2257
|
let unwatch;
|
|
2256
2258
|
const createListener = (publicClient) => {
|
|
@@ -2262,7 +2264,7 @@ function watchBlockNumber(args, callback) {
|
|
|
2262
2264
|
poll: true
|
|
2263
2265
|
});
|
|
2264
2266
|
};
|
|
2265
|
-
const publicClient_ =
|
|
2267
|
+
const publicClient_ = getWebSocketPublicClient({ chainId: args.chainId }) ?? getPublicClient({ chainId: args.chainId });
|
|
2266
2268
|
if (args.listen)
|
|
2267
2269
|
createListener(publicClient_);
|
|
2268
2270
|
const config2 = getConfig();
|
|
@@ -2272,18 +2274,18 @@ function watchBlockNumber(args, callback) {
|
|
|
2272
2274
|
webSocketPublicClient
|
|
2273
2275
|
}),
|
|
2274
2276
|
async ({ publicClient, webSocketPublicClient }) => {
|
|
2275
|
-
const publicClient_2 =
|
|
2277
|
+
const publicClient_2 = webSocketPublicClient ?? publicClient;
|
|
2276
2278
|
if (args.listen && !args.chainId && publicClient_2) {
|
|
2277
2279
|
createListener(publicClient_2);
|
|
2278
2280
|
}
|
|
2279
2281
|
},
|
|
2280
2282
|
{
|
|
2281
|
-
equalityFn:
|
|
2283
|
+
equalityFn: shallow3
|
|
2282
2284
|
}
|
|
2283
2285
|
);
|
|
2284
2286
|
return () => {
|
|
2285
2287
|
unsubscribe();
|
|
2286
|
-
|
|
2288
|
+
unwatch?.();
|
|
2287
2289
|
};
|
|
2288
2290
|
}
|
|
2289
2291
|
|
|
@@ -2298,7 +2300,7 @@ function watchMulticall(args, callback) {
|
|
|
2298
2300
|
);
|
|
2299
2301
|
return () => {
|
|
2300
2302
|
unsubscribe();
|
|
2301
|
-
|
|
2303
|
+
unwatch?.();
|
|
2302
2304
|
};
|
|
2303
2305
|
}
|
|
2304
2306
|
|
|
@@ -2313,7 +2315,7 @@ function watchReadContract(args, callback) {
|
|
|
2313
2315
|
);
|
|
2314
2316
|
return () => {
|
|
2315
2317
|
unsubscribe();
|
|
2316
|
-
|
|
2318
|
+
unwatch?.();
|
|
2317
2319
|
};
|
|
2318
2320
|
}
|
|
2319
2321
|
|
|
@@ -2328,7 +2330,7 @@ function watchReadContracts(args, callback) {
|
|
|
2328
2330
|
);
|
|
2329
2331
|
return () => {
|
|
2330
2332
|
unsubscribe();
|
|
2331
|
-
|
|
2333
|
+
unwatch?.();
|
|
2332
2334
|
};
|
|
2333
2335
|
}
|
|
2334
2336
|
|
|
@@ -2336,7 +2338,7 @@ function watchReadContracts(args, callback) {
|
|
|
2336
2338
|
async function writeContract(config2) {
|
|
2337
2339
|
const walletClient = await getWalletClient({ chainId: config2.chainId });
|
|
2338
2340
|
if (!walletClient)
|
|
2339
|
-
throw new
|
|
2341
|
+
throw new ConnectorNotFoundError();
|
|
2340
2342
|
if (config2.chainId)
|
|
2341
2343
|
assertActiveChain({ chainId: config2.chainId });
|
|
2342
2344
|
let request;
|
|
@@ -2380,7 +2382,7 @@ async function fetchBalance({
|
|
|
2380
2382
|
});
|
|
2381
2383
|
return {
|
|
2382
2384
|
decimals,
|
|
2383
|
-
formatted:
|
|
2385
|
+
formatted: formatUnits2(value2 ?? "0", getUnit(unit ?? decimals)),
|
|
2384
2386
|
symbol,
|
|
2385
2387
|
value: value2
|
|
2386
2388
|
};
|
|
@@ -2388,12 +2390,12 @@ async function fetchBalance({
|
|
|
2388
2390
|
try {
|
|
2389
2391
|
return await fetchContractBalance({ abi: erc20ABI });
|
|
2390
2392
|
} catch (err) {
|
|
2391
|
-
if (err instanceof
|
|
2393
|
+
if (err instanceof ContractFunctionExecutionError3) {
|
|
2392
2394
|
const { symbol, ...rest } = await fetchContractBalance({
|
|
2393
2395
|
abi: erc20ABI_bytes32
|
|
2394
2396
|
});
|
|
2395
2397
|
return {
|
|
2396
|
-
symbol:
|
|
2398
|
+
symbol: hexToString2(trim2(symbol, { dir: "right" })),
|
|
2397
2399
|
...rest
|
|
2398
2400
|
};
|
|
2399
2401
|
}
|
|
@@ -2402,14 +2404,14 @@ async function fetchBalance({
|
|
|
2402
2404
|
}
|
|
2403
2405
|
const chains = [
|
|
2404
2406
|
...config2.publicClient.chains || [],
|
|
2405
|
-
...
|
|
2407
|
+
...config2.chains ?? []
|
|
2406
2408
|
];
|
|
2407
2409
|
const value = await publicClient.getBalance({ address });
|
|
2408
2410
|
const chain = chains.find((x) => x.id === publicClient.chain.id);
|
|
2409
2411
|
return {
|
|
2410
|
-
decimals:
|
|
2411
|
-
formatted:
|
|
2412
|
-
symbol:
|
|
2412
|
+
decimals: chain?.nativeCurrency.decimals ?? 18,
|
|
2413
|
+
formatted: formatUnits2(value ?? "0", getUnit(unit ?? 18)),
|
|
2414
|
+
symbol: chain?.nativeCurrency.symbol ?? "ETH",
|
|
2413
2415
|
value
|
|
2414
2416
|
};
|
|
2415
2417
|
}
|
|
@@ -2420,7 +2422,7 @@ function getAccount() {
|
|
|
2420
2422
|
switch (status) {
|
|
2421
2423
|
case "connected":
|
|
2422
2424
|
return {
|
|
2423
|
-
address:
|
|
2425
|
+
address: data?.account,
|
|
2424
2426
|
connector,
|
|
2425
2427
|
isConnected: true,
|
|
2426
2428
|
isConnecting: false,
|
|
@@ -2430,9 +2432,9 @@ function getAccount() {
|
|
|
2430
2432
|
};
|
|
2431
2433
|
case "reconnecting":
|
|
2432
2434
|
return {
|
|
2433
|
-
address:
|
|
2435
|
+
address: data?.account,
|
|
2434
2436
|
connector,
|
|
2435
|
-
isConnected: !!
|
|
2437
|
+
isConnected: !!data?.account,
|
|
2436
2438
|
isConnecting: false,
|
|
2437
2439
|
isDisconnected: false,
|
|
2438
2440
|
isReconnecting: true,
|
|
@@ -2440,7 +2442,7 @@ function getAccount() {
|
|
|
2440
2442
|
};
|
|
2441
2443
|
case "connecting":
|
|
2442
2444
|
return {
|
|
2443
|
-
address:
|
|
2445
|
+
address: data?.account,
|
|
2444
2446
|
connector,
|
|
2445
2447
|
isConnected: false,
|
|
2446
2448
|
isConnecting: true,
|
|
@@ -2464,12 +2466,12 @@ function getAccount() {
|
|
|
2464
2466
|
// src/actions/accounts/getNetwork.ts
|
|
2465
2467
|
function getNetwork() {
|
|
2466
2468
|
const config2 = getConfig();
|
|
2467
|
-
const chainId =
|
|
2468
|
-
const activeChains =
|
|
2469
|
-
const activeChain =
|
|
2470
|
-
...
|
|
2469
|
+
const chainId = config2.data?.chain?.id;
|
|
2470
|
+
const activeChains = config2.chains ?? [];
|
|
2471
|
+
const activeChain = [
|
|
2472
|
+
...config2.publicClient?.chains || [],
|
|
2471
2473
|
...activeChains
|
|
2472
|
-
].find((x) => x.id === chainId)
|
|
2474
|
+
].find((x) => x.id === chainId) ?? {
|
|
2473
2475
|
id: chainId,
|
|
2474
2476
|
name: `Chain ${chainId}`,
|
|
2475
2477
|
network: `${chainId}`,
|
|
@@ -2478,11 +2480,11 @@ function getNetwork() {
|
|
|
2478
2480
|
default: { http: [""] },
|
|
2479
2481
|
public: { http: [""] }
|
|
2480
2482
|
}
|
|
2481
|
-
}
|
|
2483
|
+
};
|
|
2482
2484
|
return {
|
|
2483
2485
|
chain: chainId ? {
|
|
2484
2486
|
...activeChain,
|
|
2485
|
-
...
|
|
2487
|
+
...config2.data?.chain,
|
|
2486
2488
|
id: chainId
|
|
2487
2489
|
} : void 0,
|
|
2488
2490
|
chains: activeChains
|
|
@@ -2493,7 +2495,7 @@ function getNetwork() {
|
|
|
2493
2495
|
async function signMessage(args) {
|
|
2494
2496
|
const walletClient = await getWalletClient();
|
|
2495
2497
|
if (!walletClient)
|
|
2496
|
-
throw new
|
|
2498
|
+
throw new ConnectorNotFoundError();
|
|
2497
2499
|
return await walletClient.signMessage({
|
|
2498
2500
|
message: args.message
|
|
2499
2501
|
});
|
|
@@ -2508,7 +2510,7 @@ async function signTypedData({
|
|
|
2508
2510
|
}) {
|
|
2509
2511
|
const walletClient = await getWalletClient();
|
|
2510
2512
|
if (!walletClient)
|
|
2511
|
-
throw new
|
|
2513
|
+
throw new ConnectorNotFoundError();
|
|
2512
2514
|
const { chainId } = domain;
|
|
2513
2515
|
if (chainId)
|
|
2514
2516
|
assertActiveChain({ chainId });
|
|
@@ -2526,7 +2528,7 @@ async function switchNetwork({
|
|
|
2526
2528
|
}) {
|
|
2527
2529
|
const { connector } = getConfig();
|
|
2528
2530
|
if (!connector)
|
|
2529
|
-
throw new
|
|
2531
|
+
throw new ConnectorNotFoundError();
|
|
2530
2532
|
if (!connector.switchChain)
|
|
2531
2533
|
throw new SwitchChainNotSupportedError({
|
|
2532
2534
|
connector
|
|
@@ -2535,90 +2537,90 @@ async function switchNetwork({
|
|
|
2535
2537
|
}
|
|
2536
2538
|
|
|
2537
2539
|
// src/actions/accounts/watchAccount.ts
|
|
2538
|
-
|
|
2540
|
+
import { shallow as shallow4 } from "zustand/shallow";
|
|
2539
2541
|
function watchAccount(callback, { selector = (x) => x } = {}) {
|
|
2540
2542
|
const config2 = getConfig();
|
|
2541
2543
|
const handleChange = () => callback(getAccount());
|
|
2542
2544
|
const unsubscribe = config2.subscribe(
|
|
2543
2545
|
({ data, connector, status }) => selector({
|
|
2544
|
-
address:
|
|
2546
|
+
address: data?.account,
|
|
2545
2547
|
connector,
|
|
2546
2548
|
status
|
|
2547
2549
|
}),
|
|
2548
2550
|
handleChange,
|
|
2549
2551
|
{
|
|
2550
|
-
equalityFn:
|
|
2552
|
+
equalityFn: shallow4
|
|
2551
2553
|
}
|
|
2552
2554
|
);
|
|
2553
2555
|
return unsubscribe;
|
|
2554
2556
|
}
|
|
2555
2557
|
|
|
2556
2558
|
// src/actions/accounts/watchNetwork.ts
|
|
2557
|
-
|
|
2559
|
+
import { shallow as shallow5 } from "zustand/shallow";
|
|
2558
2560
|
function watchNetwork(callback, { selector = (x) => x } = {}) {
|
|
2559
2561
|
const config2 = getConfig();
|
|
2560
2562
|
const handleChange = () => callback(getNetwork());
|
|
2561
2563
|
const unsubscribe = config2.subscribe(
|
|
2562
|
-
({ data, chains }) => selector({ chainId:
|
|
2564
|
+
({ data, chains }) => selector({ chainId: data?.chain?.id, chains }),
|
|
2563
2565
|
handleChange,
|
|
2564
2566
|
{
|
|
2565
|
-
equalityFn:
|
|
2567
|
+
equalityFn: shallow5
|
|
2566
2568
|
}
|
|
2567
2569
|
);
|
|
2568
2570
|
return unsubscribe;
|
|
2569
2571
|
}
|
|
2570
2572
|
|
|
2571
2573
|
// src/actions/ens/fetchEnsAddress.ts
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
+
import { getAddress } from "viem";
|
|
2575
|
+
import { normalize } from "viem/ens";
|
|
2574
2576
|
async function fetchEnsAddress({
|
|
2575
2577
|
chainId,
|
|
2576
2578
|
name
|
|
2577
2579
|
}) {
|
|
2578
2580
|
const publicClient = getPublicClient({ chainId });
|
|
2579
2581
|
const address = await publicClient.getEnsAddress({
|
|
2580
|
-
name:
|
|
2582
|
+
name: normalize(name)
|
|
2581
2583
|
});
|
|
2582
2584
|
try {
|
|
2583
2585
|
if (address === "0x0000000000000000000000000000000000000000")
|
|
2584
2586
|
return null;
|
|
2585
|
-
return address ?
|
|
2587
|
+
return address ? getAddress(address) : null;
|
|
2586
2588
|
} catch (_error) {
|
|
2587
2589
|
return null;
|
|
2588
2590
|
}
|
|
2589
2591
|
}
|
|
2590
2592
|
|
|
2591
2593
|
// src/actions/ens/fetchEnsAvatar.ts
|
|
2592
|
-
|
|
2594
|
+
import { normalize as normalize2 } from "viem/ens";
|
|
2593
2595
|
async function fetchEnsAvatar({
|
|
2594
2596
|
name,
|
|
2595
2597
|
chainId
|
|
2596
2598
|
}) {
|
|
2597
2599
|
const publicClient = getPublicClient({ chainId });
|
|
2598
|
-
const avatar = await publicClient.getEnsAvatar({ name:
|
|
2600
|
+
const avatar = await publicClient.getEnsAvatar({ name: normalize2(name) });
|
|
2599
2601
|
return avatar;
|
|
2600
2602
|
}
|
|
2601
2603
|
|
|
2602
2604
|
// src/actions/ens/fetchEnsName.ts
|
|
2603
|
-
|
|
2605
|
+
import { getAddress as getAddress2 } from "viem";
|
|
2604
2606
|
async function fetchEnsName({
|
|
2605
2607
|
address,
|
|
2606
2608
|
chainId
|
|
2607
2609
|
}) {
|
|
2608
2610
|
const publicClient = getPublicClient({ chainId });
|
|
2609
2611
|
return publicClient.getEnsName({
|
|
2610
|
-
address:
|
|
2612
|
+
address: getAddress2(address)
|
|
2611
2613
|
});
|
|
2612
2614
|
}
|
|
2613
2615
|
|
|
2614
2616
|
// src/actions/ens/fetchEnsResolver.ts
|
|
2615
|
-
|
|
2617
|
+
import { normalize as normalize3 } from "viem/ens";
|
|
2616
2618
|
async function fetchEnsResolver({
|
|
2617
2619
|
chainId,
|
|
2618
2620
|
name
|
|
2619
2621
|
}) {
|
|
2620
2622
|
const publicClient = getPublicClient({ chainId });
|
|
2621
|
-
const resolver = await publicClient.getEnsResolver({ name:
|
|
2623
|
+
const resolver = await publicClient.getEnsResolver({ name: normalize3(name) });
|
|
2622
2624
|
return resolver;
|
|
2623
2625
|
}
|
|
2624
2626
|
|
|
@@ -2632,7 +2634,7 @@ async function fetchBlockNumber({
|
|
|
2632
2634
|
}
|
|
2633
2635
|
|
|
2634
2636
|
// src/actions/network-status/fetchFeeData.ts
|
|
2635
|
-
|
|
2637
|
+
import { formatUnits as formatUnits3, parseGwei } from "viem";
|
|
2636
2638
|
async function fetchFeeData({
|
|
2637
2639
|
chainId,
|
|
2638
2640
|
formatUnits: units = "gwei"
|
|
@@ -2642,21 +2644,21 @@ async function fetchFeeData({
|
|
|
2642
2644
|
let gasPrice = null;
|
|
2643
2645
|
try {
|
|
2644
2646
|
gasPrice = await publicClient.getGasPrice();
|
|
2645
|
-
} catch
|
|
2647
|
+
} catch {
|
|
2646
2648
|
}
|
|
2647
2649
|
let lastBaseFeePerGas = null;
|
|
2648
2650
|
let maxFeePerGas = null;
|
|
2649
2651
|
let maxPriorityFeePerGas = null;
|
|
2650
|
-
if (
|
|
2652
|
+
if (block?.baseFeePerGas) {
|
|
2651
2653
|
lastBaseFeePerGas = block.baseFeePerGas;
|
|
2652
|
-
maxPriorityFeePerGas =
|
|
2654
|
+
maxPriorityFeePerGas = parseGwei("1");
|
|
2653
2655
|
maxFeePerGas = block.baseFeePerGas * 2n + maxPriorityFeePerGas;
|
|
2654
2656
|
}
|
|
2655
2657
|
const unit = getUnit(units);
|
|
2656
2658
|
const formatted = {
|
|
2657
|
-
gasPrice: gasPrice ?
|
|
2658
|
-
maxFeePerGas: maxFeePerGas ?
|
|
2659
|
-
maxPriorityFeePerGas: maxPriorityFeePerGas ?
|
|
2659
|
+
gasPrice: gasPrice ? formatUnits3(gasPrice, unit) : null,
|
|
2660
|
+
maxFeePerGas: maxFeePerGas ? formatUnits3(maxFeePerGas, unit) : null,
|
|
2661
|
+
maxPriorityFeePerGas: maxPriorityFeePerGas ? formatUnits3(maxPriorityFeePerGas, unit) : null
|
|
2660
2662
|
};
|
|
2661
2663
|
return {
|
|
2662
2664
|
lastBaseFeePerGas,
|
|
@@ -2677,7 +2679,7 @@ async function fetchTransaction({
|
|
|
2677
2679
|
}
|
|
2678
2680
|
|
|
2679
2681
|
// src/actions/transactions/prepareSendTransaction.ts
|
|
2680
|
-
|
|
2682
|
+
import { isAddress } from "viem";
|
|
2681
2683
|
async function prepareSendTransaction({
|
|
2682
2684
|
accessList,
|
|
2683
2685
|
account,
|
|
@@ -2692,13 +2694,13 @@ async function prepareSendTransaction({
|
|
|
2692
2694
|
value,
|
|
2693
2695
|
walletClient: walletClient_
|
|
2694
2696
|
}) {
|
|
2695
|
-
const walletClient =
|
|
2697
|
+
const walletClient = walletClient_ ?? await getWalletClient({ chainId });
|
|
2696
2698
|
if (!walletClient)
|
|
2697
|
-
throw new
|
|
2699
|
+
throw new ConnectorNotFoundError();
|
|
2698
2700
|
if (chainId)
|
|
2699
2701
|
assertActiveChain({ chainId });
|
|
2700
|
-
const to = (to_ && !
|
|
2701
|
-
if (to && !
|
|
2702
|
+
const to = (to_ && !isAddress(to_) ? await fetchEnsAddress({ name: to_ }) : to_) || void 0;
|
|
2703
|
+
if (to && !isAddress(to))
|
|
2702
2704
|
throw new Error("Invalid address");
|
|
2703
2705
|
return {
|
|
2704
2706
|
accessList,
|
|
@@ -2733,7 +2735,7 @@ async function sendTransaction({
|
|
|
2733
2735
|
}) {
|
|
2734
2736
|
const walletClient = await getWalletClient({ chainId });
|
|
2735
2737
|
if (!walletClient)
|
|
2736
|
-
throw new
|
|
2738
|
+
throw new ConnectorNotFoundError();
|
|
2737
2739
|
if (chainId)
|
|
2738
2740
|
assertActiveChain({ chainId });
|
|
2739
2741
|
let args;
|
|
@@ -2771,7 +2773,7 @@ async function sendTransaction({
|
|
|
2771
2773
|
}
|
|
2772
2774
|
|
|
2773
2775
|
// src/actions/transactions/waitForTransaction.ts
|
|
2774
|
-
|
|
2776
|
+
import { hexToString as hexToString3 } from "viem";
|
|
2775
2777
|
async function waitForTransaction({
|
|
2776
2778
|
chainId,
|
|
2777
2779
|
confirmations = 1,
|
|
@@ -2796,14 +2798,14 @@ async function waitForTransaction({
|
|
|
2796
2798
|
maxFeePerGas: txn.type === "eip1559" ? txn.maxFeePerGas : void 0,
|
|
2797
2799
|
maxPriorityFeePerGas: txn.type === "eip1559" ? txn.maxPriorityFeePerGas : void 0
|
|
2798
2800
|
});
|
|
2799
|
-
const reason =
|
|
2801
|
+
const reason = hexToString3(`0x${code.substring(138)}`);
|
|
2800
2802
|
throw new Error(reason);
|
|
2801
2803
|
}
|
|
2802
2804
|
return receipt;
|
|
2803
2805
|
}
|
|
2804
2806
|
|
|
2805
2807
|
// src/actions/transactions/watchPendingTransactions.ts
|
|
2806
|
-
|
|
2808
|
+
import { shallow as shallow6 } from "zustand/shallow";
|
|
2807
2809
|
function watchPendingTransactions(args, callback) {
|
|
2808
2810
|
let unwatch;
|
|
2809
2811
|
const createListener = (publicClient) => {
|
|
@@ -2814,7 +2816,7 @@ function watchPendingTransactions(args, callback) {
|
|
|
2814
2816
|
poll: true
|
|
2815
2817
|
});
|
|
2816
2818
|
};
|
|
2817
|
-
const publicClient_ =
|
|
2819
|
+
const publicClient_ = getWebSocketPublicClient({ chainId: args.chainId }) ?? getPublicClient({ chainId: args.chainId });
|
|
2818
2820
|
createListener(publicClient_);
|
|
2819
2821
|
const config2 = getConfig();
|
|
2820
2822
|
const unsubscribe = config2.subscribe(
|
|
@@ -2823,92 +2825,92 @@ function watchPendingTransactions(args, callback) {
|
|
|
2823
2825
|
webSocketPublicClient
|
|
2824
2826
|
}),
|
|
2825
2827
|
async ({ publicClient, webSocketPublicClient }) => {
|
|
2826
|
-
const publicClient_2 =
|
|
2828
|
+
const publicClient_2 = webSocketPublicClient ?? publicClient;
|
|
2827
2829
|
if (!args.chainId && publicClient_2) {
|
|
2828
2830
|
createListener(publicClient_2);
|
|
2829
2831
|
}
|
|
2830
2832
|
},
|
|
2831
2833
|
{
|
|
2832
|
-
equalityFn:
|
|
2834
|
+
equalityFn: shallow6
|
|
2833
2835
|
}
|
|
2834
2836
|
);
|
|
2835
2837
|
return () => {
|
|
2836
2838
|
unsubscribe();
|
|
2837
|
-
|
|
2839
|
+
unwatch?.();
|
|
2838
2840
|
};
|
|
2839
2841
|
}
|
|
2840
2842
|
|
|
2841
2843
|
// src/utils/assertActiveChain.ts
|
|
2842
2844
|
function assertActiveChain({ chainId }) {
|
|
2843
2845
|
const { chain: activeChain, chains } = getNetwork();
|
|
2844
|
-
const activeChainId =
|
|
2846
|
+
const activeChainId = activeChain?.id;
|
|
2845
2847
|
if (activeChainId && chainId !== activeChainId) {
|
|
2846
2848
|
throw new ChainMismatchError({
|
|
2847
|
-
activeChain:
|
|
2848
|
-
targetChain:
|
|
2849
|
+
activeChain: chains.find((x) => x.id === activeChainId)?.name ?? `Chain ${activeChainId}`,
|
|
2850
|
+
targetChain: chains.find((x) => x.id === chainId)?.name ?? `Chain ${chainId}`
|
|
2849
2851
|
});
|
|
2850
2852
|
}
|
|
2851
2853
|
}
|
|
2852
2854
|
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
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
|
-
|
|
2855
|
+
export {
|
|
2856
|
+
configureChains,
|
|
2857
|
+
ChainMismatchError,
|
|
2858
|
+
ChainNotConfiguredError,
|
|
2859
|
+
ConnectorAlreadyConnectedError,
|
|
2860
|
+
ConfigChainsNotFound,
|
|
2861
|
+
SwitchChainNotSupportedError,
|
|
2862
|
+
ConnectorNotFoundError,
|
|
2863
|
+
deepEqual,
|
|
2864
|
+
deserialize,
|
|
2865
|
+
getCallParameters,
|
|
2866
|
+
getSendTransactionParameters,
|
|
2867
|
+
getUnit,
|
|
2868
|
+
serialize,
|
|
2869
|
+
noopStorage,
|
|
2870
|
+
createStorage,
|
|
2871
|
+
Config,
|
|
2872
|
+
createConfig,
|
|
2873
|
+
getConfig,
|
|
2874
|
+
connect,
|
|
2875
|
+
disconnect,
|
|
2876
|
+
erc20ABI,
|
|
2877
|
+
erc721ABI,
|
|
2878
|
+
erc4626ABI,
|
|
2879
|
+
fetchToken,
|
|
2880
|
+
getPublicClient,
|
|
2881
|
+
getWalletClient,
|
|
2882
|
+
getWebSocketPublicClient,
|
|
2883
|
+
watchPublicClient,
|
|
2884
|
+
watchWalletClient,
|
|
2885
|
+
watchWebSocketPublicClient,
|
|
2886
|
+
prepareWriteContract,
|
|
2887
|
+
getContract,
|
|
2888
|
+
multicall,
|
|
2889
|
+
readContract,
|
|
2890
|
+
readContracts,
|
|
2891
|
+
watchContractEvent,
|
|
2892
|
+
watchBlockNumber,
|
|
2893
|
+
watchMulticall,
|
|
2894
|
+
watchReadContract,
|
|
2895
|
+
watchReadContracts,
|
|
2896
|
+
writeContract,
|
|
2897
|
+
fetchBalance,
|
|
2898
|
+
getAccount,
|
|
2899
|
+
getNetwork,
|
|
2900
|
+
signMessage,
|
|
2901
|
+
signTypedData,
|
|
2902
|
+
switchNetwork,
|
|
2903
|
+
watchAccount,
|
|
2904
|
+
watchNetwork,
|
|
2905
|
+
fetchEnsAddress,
|
|
2906
|
+
fetchEnsAvatar,
|
|
2907
|
+
fetchEnsName,
|
|
2908
|
+
fetchEnsResolver,
|
|
2909
|
+
fetchBlockNumber,
|
|
2910
|
+
fetchFeeData,
|
|
2911
|
+
fetchTransaction,
|
|
2912
|
+
prepareSendTransaction,
|
|
2913
|
+
sendTransaction,
|
|
2914
|
+
waitForTransaction,
|
|
2915
|
+
watchPendingTransactions
|
|
2916
|
+
};
|