@wagmi/core 0.3.2 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/chains/dist/wagmi-core-chains.cjs.d.ts +1 -0
- package/chains/dist/wagmi-core-chains.cjs.dev.js +22 -0
- package/chains/dist/wagmi-core-chains.cjs.js +7 -0
- package/chains/dist/wagmi-core-chains.cjs.prod.js +22 -0
- package/chains/dist/wagmi-core-chains.esm.js +2 -0
- package/chains/package.json +4 -0
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.dev.js +4 -3
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.prod.js +4 -3
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.esm.js +2 -1
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.dev.js +3 -2
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.prod.js +3 -2
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.esm.js +3 -2
- package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.dev.js +4 -3
- package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.prod.js +4 -3
- package/connectors/mock/dist/wagmi-core-connectors-mock.esm.js +2 -1
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.dev.js +9 -6
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.prod.js +9 -6
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.esm.js +7 -4
- package/dist/base-321ac87a.cjs.dev.js +288 -0
- package/dist/base-41fb6637.esm.js +265 -0
- package/dist/base-6841ebe0.cjs.prod.js +288 -0
- package/dist/chains-0dd661ab.cjs.prod.js +349 -0
- package/dist/chains-98e2e613.cjs.dev.js +349 -0
- package/dist/chains-a0a80d94.esm.js +329 -0
- package/dist/{client-edc73358.cjs.prod.js → client-4172f963.cjs.dev.js} +4 -3
- package/dist/{client-1ab99bf8.esm.js → client-87c1ff8b.esm.js} +2 -1
- package/dist/{client-db513093.cjs.dev.js → client-a06c45f3.cjs.prod.js} +4 -3
- package/dist/declarations/src/actions/network-status/fetchFeeData.d.ts +3 -3
- package/dist/declarations/src/chains.d.ts +1 -0
- package/dist/declarations/src/constants/chains.d.ts +33 -2
- package/dist/declarations/src/index.d.ts +2 -3
- package/dist/declarations/src/types/index.d.ts +9 -2
- package/dist/declarations/src/{chains → utils}/configureChains.d.ts +0 -0
- package/dist/declarations/src/utils/index.d.ts +2 -0
- package/dist/wagmi-core.cjs.dev.js +121 -120
- package/dist/wagmi-core.cjs.prod.js +121 -120
- package/dist/wagmi-core.esm.js +111 -109
- package/package.json +12 -7
- package/dist/base-3a506159.cjs.dev.js +0 -602
- package/dist/base-997b4fec.esm.js +0 -573
- package/dist/base-cb4198f3.cjs.prod.js +0 -602
- package/dist/declarations/src/chains/index.d.ts +0 -2
package/dist/wagmi-core.esm.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { c as client, g as getClient } from './client-
|
|
2
|
-
export { C as Client, I as InjectedConnector, a as createClient, b as createStorage, n as noopStorage } from './client-
|
|
3
|
-
import { C as ConnectorAlreadyConnectedError, a as
|
|
4
|
-
export { A as AddChainError,
|
|
1
|
+
import { c as client, g as getClient } from './client-87c1ff8b.esm.js';
|
|
2
|
+
export { C as Client, I as InjectedConnector, a as createClient, b as createStorage, n as noopStorage } from './client-87c1ff8b.esm.js';
|
|
3
|
+
import { C as ConnectorAlreadyConnectedError, a as ConnectorNotFoundError, U as UserRejectedRequestError, S as SwitchChainNotSupportedError } from './base-41fb6637.esm.js';
|
|
4
|
+
export { A as AddChainError, c as ChainNotConfiguredError, b as Connector, C as ConnectorAlreadyConnectedError, a as ConnectorNotFoundError, P as ProviderRpcError, R as ResourceUnavailableError, d as RpcError, e as SwitchChainError, S as SwitchChainNotSupportedError, U as UserRejectedRequestError, n as normalizeChainId } from './base-41fb6637.esm.js';
|
|
5
5
|
import { Contract } from 'ethers/lib/ethers';
|
|
6
6
|
import { formatUnits, getAddress } from 'ethers/lib/utils';
|
|
7
|
-
import {
|
|
7
|
+
import { a as allChains } from './chains-a0a80d94.esm.js';
|
|
8
|
+
export { a as allChains, c as chain, b as chainId, d as defaultChains, e as defaultL2Chains, f as etherscanBlockExplorers } from './chains-a0a80d94.esm.js';
|
|
9
|
+
import { providers, Contract as Contract$1 } from 'ethers';
|
|
8
10
|
export { a as alchemyRpcUrls, i as infuraRpcUrls } from './rpcs-7cfbd91c.esm.js';
|
|
9
11
|
import 'zustand/vanilla';
|
|
10
12
|
import 'zustand/middleware';
|
|
@@ -18,6 +20,107 @@ const erc721ABI = ['event Approval(address indexed _owner, address indexed _appr
|
|
|
18
20
|
// https://github.com/ethers-io/ethers.js/blob/master/packages/units/src.ts/index.ts#L10-L18
|
|
19
21
|
const units = ['wei', 'kwei', 'mwei', 'gwei', 'szabo', 'finney', 'ether'];
|
|
20
22
|
|
|
23
|
+
function configureChains(defaultChains, providers) {
|
|
24
|
+
let {
|
|
25
|
+
minQuorum = 1,
|
|
26
|
+
targetQuorum = 1,
|
|
27
|
+
stallTimeout
|
|
28
|
+
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
29
|
+
if (targetQuorum < minQuorum) throw new Error('quorum cannot be lower than minQuorum');
|
|
30
|
+
let chains = [];
|
|
31
|
+
const providers_ = {};
|
|
32
|
+
const webSocketProviders_ = {};
|
|
33
|
+
|
|
34
|
+
for (const chain of defaultChains) {
|
|
35
|
+
let configExists = false;
|
|
36
|
+
|
|
37
|
+
for (const provider of providers) {
|
|
38
|
+
const apiConfig = provider(chain); // If no API configuration was found (ie. no RPC URL) for
|
|
39
|
+
// this provider, then we skip and check the next one.
|
|
40
|
+
|
|
41
|
+
if (!apiConfig) continue;
|
|
42
|
+
configExists = true;
|
|
43
|
+
|
|
44
|
+
if (!chains.some(_ref => {
|
|
45
|
+
let {
|
|
46
|
+
id
|
|
47
|
+
} = _ref;
|
|
48
|
+
return id === chain.id;
|
|
49
|
+
})) {
|
|
50
|
+
chains = [...chains, apiConfig.chain];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
providers_[chain.id] = [...(providers_[chain.id] || []), apiConfig.provider];
|
|
54
|
+
|
|
55
|
+
if (apiConfig.webSocketProvider) {
|
|
56
|
+
webSocketProviders_[chain.id] = [...(webSocketProviders_[chain.id] || []), apiConfig.webSocketProvider];
|
|
57
|
+
}
|
|
58
|
+
} // If no API configuration was found across the providers
|
|
59
|
+
// then we throw an error to the consumer.
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
if (!configExists) {
|
|
63
|
+
throw new Error(["Could not find valid provider configuration for chain \"".concat(chain.name, "\".\n"), "You may need to add `jsonRpcProvider` to `configureChains` with the chain's RPC URLs.", 'Read more: https://wagmi.sh/docs/providers/jsonRpc'].join('\n'));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
chains,
|
|
69
|
+
provider: _ref2 => {
|
|
70
|
+
let {
|
|
71
|
+
chainId
|
|
72
|
+
} = _ref2;
|
|
73
|
+
const chainProviders = providers_[chainId && chains.some(x => x.id === chainId) ? chainId : defaultChains[0].id];
|
|
74
|
+
if (chainProviders.length === 1) return chainProviders[0]();
|
|
75
|
+
return fallbackProvider(targetQuorum, minQuorum, chainProviders, {
|
|
76
|
+
stallTimeout
|
|
77
|
+
});
|
|
78
|
+
},
|
|
79
|
+
webSocketProvider: _ref3 => {
|
|
80
|
+
let {
|
|
81
|
+
chainId
|
|
82
|
+
} = _ref3;
|
|
83
|
+
const chainWebSocketProviders = webSocketProviders_[chainId && chains.some(x => x.id === chainId) ? chainId : defaultChains[0].id];
|
|
84
|
+
if (!chainWebSocketProviders) return undefined;
|
|
85
|
+
if (chainWebSocketProviders.length === 1) return chainWebSocketProviders[0](); // WebSockets do not work with `fallbackProvider`
|
|
86
|
+
// Default to first available
|
|
87
|
+
|
|
88
|
+
return chainWebSocketProviders[0]();
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function fallbackProvider(targetQuorum, minQuorum, providers_, _ref4) {
|
|
94
|
+
let {
|
|
95
|
+
stallTimeout
|
|
96
|
+
} = _ref4;
|
|
97
|
+
|
|
98
|
+
try {
|
|
99
|
+
return new providers.FallbackProvider(providers_.map((chainProvider, index) => {
|
|
100
|
+
var _provider$priority, _provider$stallTimeou;
|
|
101
|
+
|
|
102
|
+
const provider = chainProvider();
|
|
103
|
+
return {
|
|
104
|
+
provider,
|
|
105
|
+
priority: (_provider$priority = provider.priority) !== null && _provider$priority !== void 0 ? _provider$priority : index,
|
|
106
|
+
stallTimeout: (_provider$stallTimeou = provider.stallTimeout) !== null && _provider$stallTimeou !== void 0 ? _provider$stallTimeou : stallTimeout,
|
|
107
|
+
weight: provider.weight
|
|
108
|
+
};
|
|
109
|
+
}), targetQuorum);
|
|
110
|
+
} catch (error) {
|
|
111
|
+
var _error$message;
|
|
112
|
+
|
|
113
|
+
if (error !== null && error !== void 0 && (_error$message = error.message) !== null && _error$message !== void 0 && _error$message.includes('quorum will always fail; larger than total weight')) {
|
|
114
|
+
if (targetQuorum === minQuorum) throw error;
|
|
115
|
+
return fallbackProvider(targetQuorum - 1, minQuorum, providers_, {
|
|
116
|
+
stallTimeout
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
throw error;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
21
124
|
async function connect(_ref) {
|
|
22
125
|
let {
|
|
23
126
|
connector
|
|
@@ -523,9 +626,9 @@ async function fetchFeeData() {
|
|
|
523
626
|
});
|
|
524
627
|
const feeData = await provider.getFeeData();
|
|
525
628
|
const formatted = {
|
|
526
|
-
gasPrice: formatUnits(feeData.gasPrice, units),
|
|
527
|
-
maxFeePerGas: formatUnits(feeData.maxFeePerGas, units),
|
|
528
|
-
maxPriorityFeePerGas: formatUnits(feeData.maxPriorityFeePerGas, units)
|
|
629
|
+
gasPrice: feeData.gasPrice ? formatUnits(feeData.gasPrice, units) : null,
|
|
630
|
+
maxFeePerGas: feeData.maxFeePerGas ? formatUnits(feeData.maxFeePerGas, units) : null,
|
|
631
|
+
maxPriorityFeePerGas: feeData.maxPriorityFeePerGas ? formatUnits(feeData.maxPriorityFeePerGas, units) : null
|
|
529
632
|
};
|
|
530
633
|
return { ...feeData,
|
|
531
634
|
formatted
|
|
@@ -587,105 +690,4 @@ async function waitForTransaction(_ref) {
|
|
|
587
690
|
return await promise;
|
|
588
691
|
}
|
|
589
692
|
|
|
590
|
-
function configureChains(defaultChains, providers) {
|
|
591
|
-
let {
|
|
592
|
-
minQuorum = 1,
|
|
593
|
-
targetQuorum = 1,
|
|
594
|
-
stallTimeout
|
|
595
|
-
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
596
|
-
if (targetQuorum < minQuorum) throw new Error('quorum cannot be lower than minQuorum');
|
|
597
|
-
let chains = [];
|
|
598
|
-
const providers_ = {};
|
|
599
|
-
const webSocketProviders_ = {};
|
|
600
|
-
|
|
601
|
-
for (const chain of defaultChains) {
|
|
602
|
-
let configExists = false;
|
|
603
|
-
|
|
604
|
-
for (const provider of providers) {
|
|
605
|
-
const apiConfig = provider(chain); // If no API configuration was found (ie. no RPC URL) for
|
|
606
|
-
// this provider, then we skip and check the next one.
|
|
607
|
-
|
|
608
|
-
if (!apiConfig) continue;
|
|
609
|
-
configExists = true;
|
|
610
|
-
|
|
611
|
-
if (!chains.some(_ref => {
|
|
612
|
-
let {
|
|
613
|
-
id
|
|
614
|
-
} = _ref;
|
|
615
|
-
return id === chain.id;
|
|
616
|
-
})) {
|
|
617
|
-
chains = [...chains, apiConfig.chain];
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
providers_[chain.id] = [...(providers_[chain.id] || []), apiConfig.provider];
|
|
621
|
-
|
|
622
|
-
if (apiConfig.webSocketProvider) {
|
|
623
|
-
webSocketProviders_[chain.id] = [...(webSocketProviders_[chain.id] || []), apiConfig.webSocketProvider];
|
|
624
|
-
}
|
|
625
|
-
} // If no API configuration was found across the providers
|
|
626
|
-
// then we throw an error to the consumer.
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
if (!configExists) {
|
|
630
|
-
throw new Error(["Could not find valid provider configuration for chain \"".concat(chain.name, "\".\n"), "You may need to add `jsonRpcProvider` to `configureChains` with the chain's RPC URLs.", 'Read more: https://wagmi.sh/docs/providers/jsonRpc'].join('\n'));
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
return {
|
|
635
|
-
chains,
|
|
636
|
-
provider: _ref2 => {
|
|
637
|
-
let {
|
|
638
|
-
chainId
|
|
639
|
-
} = _ref2;
|
|
640
|
-
const chainProviders = providers_[chainId && chains.some(x => x.id === chainId) ? chainId : defaultChains[0].id];
|
|
641
|
-
if (chainProviders.length === 1) return chainProviders[0]();
|
|
642
|
-
return fallbackProvider(targetQuorum, minQuorum, chainProviders, {
|
|
643
|
-
stallTimeout
|
|
644
|
-
});
|
|
645
|
-
},
|
|
646
|
-
webSocketProvider: _ref3 => {
|
|
647
|
-
let {
|
|
648
|
-
chainId
|
|
649
|
-
} = _ref3;
|
|
650
|
-
const chainWebSocketProviders = webSocketProviders_[chainId && chains.some(x => x.id === chainId) ? chainId : defaultChains[0].id];
|
|
651
|
-
if (!chainWebSocketProviders) return undefined;
|
|
652
|
-
if (chainWebSocketProviders.length === 1) return chainWebSocketProviders[0](); // WebSockets do not work with `fallbackProvider`
|
|
653
|
-
// Default to first available
|
|
654
|
-
|
|
655
|
-
return chainWebSocketProviders[0]();
|
|
656
|
-
}
|
|
657
|
-
};
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
function fallbackProvider(targetQuorum, minQuorum, providers_, _ref4) {
|
|
661
|
-
let {
|
|
662
|
-
stallTimeout
|
|
663
|
-
} = _ref4;
|
|
664
|
-
|
|
665
|
-
try {
|
|
666
|
-
return new providers.FallbackProvider(providers_.map((chainProvider, index) => {
|
|
667
|
-
var _provider$priority, _provider$stallTimeou;
|
|
668
|
-
|
|
669
|
-
const provider = chainProvider();
|
|
670
|
-
return {
|
|
671
|
-
provider,
|
|
672
|
-
priority: (_provider$priority = provider.priority) !== null && _provider$priority !== void 0 ? _provider$priority : index,
|
|
673
|
-
stallTimeout: (_provider$stallTimeou = provider.stallTimeout) !== null && _provider$stallTimeou !== void 0 ? _provider$stallTimeou : stallTimeout,
|
|
674
|
-
weight: provider.weight
|
|
675
|
-
};
|
|
676
|
-
}), targetQuorum);
|
|
677
|
-
} catch (error) {
|
|
678
|
-
var _error$message;
|
|
679
|
-
|
|
680
|
-
if (error !== null && error !== void 0 && (_error$message = error.message) !== null && _error$message !== void 0 && _error$message.includes('quorum will always fail; larger than total weight')) {
|
|
681
|
-
if (targetQuorum === minQuorum) throw error;
|
|
682
|
-
return fallbackProvider(targetQuorum - 1, minQuorum, providers_, {
|
|
683
|
-
stallTimeout
|
|
684
|
-
});
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
throw error;
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
|
|
691
693
|
export { configureChains, connect, disconnect, erc20ABI, erc721ABI, fetchBalance, fetchBlockNumber, fetchEnsAddress, fetchEnsAvatar, fetchEnsName, fetchEnsResolver, fetchFeeData, fetchSigner, fetchToken, getAccount, getContract, getNetwork, getProvider, getWebSocketProvider, readContract, sendTransaction, signMessage, signTypedData, switchNetwork, units, waitForTransaction, watchAccount, watchBlockNumber, watchContractEvent, watchNetwork, watchProvider, watchReadContract, watchSigner, watchWebSocketProvider, writeContract };
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@wagmi/core",
|
|
3
3
|
"description": "Vanilla JS library for Ethereum",
|
|
4
4
|
"license": "WAGMIT",
|
|
5
|
-
"version": "0.3.
|
|
5
|
+
"version": "0.3.5",
|
|
6
6
|
"repository": "tmm/wagmi",
|
|
7
7
|
"author": "awkweb.eth",
|
|
8
8
|
"ethereum": "awkweb.eth",
|
|
@@ -15,6 +15,10 @@
|
|
|
15
15
|
"module": "./dist/wagmi-core.esm.js",
|
|
16
16
|
"default": "./dist/wagmi-core.cjs.js"
|
|
17
17
|
},
|
|
18
|
+
"./chains": {
|
|
19
|
+
"module": "./chains/dist/wagmi-core-chains.esm.js",
|
|
20
|
+
"default": "./chains/dist/wagmi-core-chains.cjs.js"
|
|
21
|
+
},
|
|
18
22
|
"./connectors/coinbaseWallet": {
|
|
19
23
|
"module": "./connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.esm.js",
|
|
20
24
|
"default": "./connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.js"
|
|
@@ -35,10 +39,6 @@
|
|
|
35
39
|
"module": "./providers/alchemy/dist/wagmi-core-providers-alchemy.esm.js",
|
|
36
40
|
"default": "./providers/alchemy/dist/wagmi-core-providers-alchemy.cjs.js"
|
|
37
41
|
},
|
|
38
|
-
"./providers/public": {
|
|
39
|
-
"module": "./providers/public/dist/wagmi-core-providers-public.esm.js",
|
|
40
|
-
"default": "./providers/public/dist/wagmi-core-providers-public.cjs.js"
|
|
41
|
-
},
|
|
42
42
|
"./providers/infura": {
|
|
43
43
|
"module": "./providers/infura/dist/wagmi-core-providers-infura.esm.js",
|
|
44
44
|
"default": "./providers/infura/dist/wagmi-core-providers-infura.cjs.js"
|
|
@@ -46,9 +46,14 @@
|
|
|
46
46
|
"./providers/jsonRpc": {
|
|
47
47
|
"module": "./providers/jsonRpc/dist/wagmi-core-providers-jsonRpc.esm.js",
|
|
48
48
|
"default": "./providers/jsonRpc/dist/wagmi-core-providers-jsonRpc.cjs.js"
|
|
49
|
+
},
|
|
50
|
+
"./providers/public": {
|
|
51
|
+
"module": "./providers/public/dist/wagmi-core-providers-public.esm.js",
|
|
52
|
+
"default": "./providers/public/dist/wagmi-core-providers-public.cjs.js"
|
|
49
53
|
}
|
|
50
54
|
},
|
|
51
55
|
"files": [
|
|
56
|
+
"/chains",
|
|
52
57
|
"/connectors",
|
|
53
58
|
"/providers",
|
|
54
59
|
"/dist"
|
|
@@ -56,6 +61,7 @@
|
|
|
56
61
|
"preconstruct": {
|
|
57
62
|
"entrypoints": [
|
|
58
63
|
"index.ts",
|
|
64
|
+
"chains.ts",
|
|
59
65
|
"connectors/coinbaseWallet.ts",
|
|
60
66
|
"connectors/metaMask.ts",
|
|
61
67
|
"connectors/walletConnect.ts",
|
|
@@ -94,6 +100,5 @@
|
|
|
94
100
|
"dapps",
|
|
95
101
|
"wallet",
|
|
96
102
|
"web3"
|
|
97
|
-
]
|
|
98
|
-
"readme": "# @wagmi/core\n\n## Documentation\n\nFor full documentation and examples, visit [wagmi.sh](https://wagmi.sh).\n\n## Installation\n\nInstall wagmi and its ethers peer dependency.\n\n```bash\nnpm install @wagmi/core ethers\n```\n\n## Community\n\nCheck out the following places for more wagmi-related content:\n\n- Join the [discussions on GitHub](https://github.com/tmm/wagmi/discussions)\n- Follow [@awkweb](https://twitter.com/awkweb) and [@wagmi_sh](https://twitter.com/wagmi_sh) on Twitter for project updates\n- Sign the [guestbook](https://github.com/tmm/wagmi/discussions/2)\n- Share [your project/organization](https://github.com/tmm/wagmi/discussions/201) using wagmi\n\n## Support\n\nIf you find wagmi useful, please consider supporting development. Thank you 🙏\n\n- [GitHub Sponsors](https://github.com/sponsors/tmm?metadata_campaign=readme_core)\n- [Gitcoin Grant](https://gitcoin.co/grants/4493/wagmi-react-hooks-library-for-ethereum)\n- [awkweb.eth](https://etherscan.io/enslookup-search?search=awkweb.eth)\n"
|
|
103
|
+
]
|
|
99
104
|
}
|