@wagmi/core 0.2.0-next.10 → 0.2.0-next.13
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/LICENSE +1 -1
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.dev.js +1 -1
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.prod.js +1 -1
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.esm.js +1 -1
- package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.dev.js +2 -2
- package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.prod.js +2 -2
- package/connectors/mock/dist/wagmi-core-connectors-mock.esm.js +2 -2
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.dev.js +2 -2
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.prod.js +2 -2
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.esm.js +2 -2
- package/dist/{base-85d1eb89.cjs.dev.js → base-83fd83c6.cjs.dev.js} +3 -3
- package/dist/{base-d3563329.cjs.prod.js → base-9b2942ee.cjs.prod.js} +3 -3
- package/dist/{base-37097073.esm.js → base-b052e615.esm.js} +3 -3
- package/dist/{classPrivateMethodGet-3f47cf74.cjs.dev.js → classPrivateMethodGet-45a38143.cjs.dev.js} +1 -1
- package/dist/{classPrivateMethodGet-b3ba7c1d.esm.js → classPrivateMethodGet-7c370e43.esm.js} +1 -1
- package/dist/{classPrivateMethodGet-a763c0df.cjs.prod.js → classPrivateMethodGet-a1e1a4aa.cjs.prod.js} +1 -1
- package/dist/declarations/src/actions/accounts/connect.d.ts +1 -1
- package/dist/declarations/src/actions/accounts/fetchBalance.d.ts +3 -1
- package/dist/declarations/src/actions/accounts/getAccount.d.ts +1 -1
- package/dist/declarations/src/actions/accounts/watchAccount.d.ts +1 -1
- package/dist/declarations/src/actions/contracts/readContract.d.ts +4 -1
- package/dist/declarations/src/actions/contracts/watchContractEvent.d.ts +3 -1
- package/dist/declarations/src/actions/ens/fetchEnsAddress.d.ts +3 -1
- package/dist/declarations/src/actions/ens/fetchEnsAvatar.d.ts +3 -1
- package/dist/declarations/src/actions/ens/fetchEnsName.d.ts +3 -1
- package/dist/declarations/src/actions/ens/fetchEnsResolver.d.ts +3 -1
- package/dist/declarations/src/actions/index.d.ts +2 -2
- package/dist/declarations/src/actions/network-status/fetchBlockNumber.d.ts +4 -1
- package/dist/declarations/src/actions/network-status/fetchFeeData.d.ts +3 -1
- package/dist/declarations/src/actions/network-status/index.d.ts +1 -1
- package/dist/declarations/src/actions/providers/getProvider.d.ts +5 -1
- package/dist/declarations/src/actions/providers/getWebSocketProvider.d.ts +5 -1
- package/dist/declarations/src/actions/providers/index.d.ts +2 -2
- package/dist/declarations/src/actions/providers/watchProvider.d.ts +1 -1
- package/dist/declarations/src/actions/tokens/fetchToken.d.ts +6 -10
- package/dist/declarations/src/client.d.ts +2 -2
- package/dist/declarations/src/connectors/injected.d.ts +2 -10
- package/dist/declarations/src/index.d.ts +1 -1
- package/dist/declarations/src/types/index.d.ts +65 -1
- package/dist/declarations/src/utils/getInjectedName.d.ts +1 -1
- package/dist/wagmi-core.cjs.dev.js +152 -71
- package/dist/wagmi-core.cjs.prod.js +152 -71
- package/dist/wagmi-core.esm.js +153 -72
- package/package.json +12 -4
- package/dist/declarations/src/types/declarations.d.ts +0 -52
package/dist/wagmi-core.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { _ as _classPrivateMethodInitSpec, a as _classPrivateMethodGet } from './classPrivateMethodGet-
|
|
2
|
-
import { C as Connector, _ as _defineProperty, a as _classPrivateFieldInitSpec, n as normalizeChainId, b as ConnectorNotFoundError, U as UserRejectedRequestError, c as _classPrivateFieldSet, d as _classPrivateFieldGet, e as allChains, f as ChainNotConfiguredError, A as AddChainError, S as SwitchChainError, g as ConnectorAlreadyConnectedError, h as SwitchChainNotSupportedError } from './base-
|
|
3
|
-
export { A as AddChainError, f as ChainNotConfiguredError, C as Connector, g as ConnectorAlreadyConnectedError, b as ConnectorNotFoundError, S as SwitchChainError, h as SwitchChainNotSupportedError, U as UserRejectedRequestError, i as alchemyRpcUrls, e as allChains, j as chain, k as chainId, l as defaultChains, m as defaultL2Chains, o as etherscanBlockExplorers, p as infuraRpcUrls, n as normalizeChainId } from './base-
|
|
1
|
+
import { _ as _classPrivateMethodInitSpec, a as _classPrivateMethodGet } from './classPrivateMethodGet-7c370e43.esm.js';
|
|
2
|
+
import { C as Connector, _ as _defineProperty, a as _classPrivateFieldInitSpec, n as normalizeChainId, b as ConnectorNotFoundError, U as UserRejectedRequestError, c as _classPrivateFieldSet, d as _classPrivateFieldGet, e as allChains, f as ChainNotConfiguredError, A as AddChainError, S as SwitchChainError, g as ConnectorAlreadyConnectedError, h as SwitchChainNotSupportedError } from './base-b052e615.esm.js';
|
|
3
|
+
export { A as AddChainError, f as ChainNotConfiguredError, C as Connector, g as ConnectorAlreadyConnectedError, b as ConnectorNotFoundError, S as SwitchChainError, h as SwitchChainNotSupportedError, U as UserRejectedRequestError, i as alchemyRpcUrls, e as allChains, j as chain, k as chainId, l as defaultChains, m as defaultL2Chains, o as etherscanBlockExplorers, p as infuraRpcUrls, n as normalizeChainId } from './base-b052e615.esm.js';
|
|
4
4
|
import { providers, getDefaultProvider } from 'ethers';
|
|
5
5
|
import create from 'zustand/vanilla';
|
|
6
6
|
import { subscribeWithSelector, persist } from 'zustand/middleware';
|
|
@@ -16,12 +16,22 @@ const erc721ABI = ['event Approval(address indexed _owner, address indexed _appr
|
|
|
16
16
|
// https://github.com/ethers-io/ethers.js/blob/master/packages/units/src.ts/index.ts#L10-L18
|
|
17
17
|
const units = ['wei', 'kwei', 'mwei', 'gwei', 'szabo', 'finney', 'ether'];
|
|
18
18
|
|
|
19
|
+
const injectedProvidersLookup = {
|
|
20
|
+
isMetaMask: 'MetaMask',
|
|
21
|
+
// Place other options below in alphabetical order
|
|
22
|
+
isBraveWallet: 'Brave Wallet',
|
|
23
|
+
isCoinbaseWallet: 'Coinbase Wallet',
|
|
24
|
+
isFrame: 'Frame',
|
|
25
|
+
isTally: 'Tally'
|
|
26
|
+
};
|
|
27
|
+
const injectedOptions = Object.entries(injectedProvidersLookup);
|
|
19
28
|
function getInjectedName(ethereum) {
|
|
20
29
|
if (!ethereum) return 'Injected';
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
30
|
+
|
|
31
|
+
for (const [key, val] of injectedOptions) {
|
|
32
|
+
if (ethereum[key]) return val;
|
|
33
|
+
}
|
|
34
|
+
|
|
25
35
|
return 'Injected';
|
|
26
36
|
}
|
|
27
37
|
|
|
@@ -67,10 +77,10 @@ class InjectedConnector extends Connector {
|
|
|
67
77
|
});
|
|
68
78
|
|
|
69
79
|
_defineProperty(this, "onDisconnect", () => {
|
|
70
|
-
var _this$options,
|
|
80
|
+
var _this$options, _getClient$storage;
|
|
71
81
|
|
|
72
82
|
this.emit('disconnect');
|
|
73
|
-
if ((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.shimDisconnect) (
|
|
83
|
+
if ((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.shimDisconnect) (_getClient$storage = getClient().storage) === null || _getClient$storage === void 0 ? void 0 : _getClient$storage.removeItem(shimKey);
|
|
74
84
|
});
|
|
75
85
|
|
|
76
86
|
let name = 'Injected';
|
|
@@ -80,7 +90,7 @@ class InjectedConnector extends Connector {
|
|
|
80
90
|
|
|
81
91
|
async connect() {
|
|
82
92
|
try {
|
|
83
|
-
var _this$options2,
|
|
93
|
+
var _this$options2, _getClient$storage2;
|
|
84
94
|
|
|
85
95
|
const provider = await this.getProvider();
|
|
86
96
|
if (!provider) throw new ConnectorNotFoundError();
|
|
@@ -97,7 +107,7 @@ class InjectedConnector extends Connector {
|
|
|
97
107
|
const account = await this.getAccount();
|
|
98
108
|
const id = await this.getChainId();
|
|
99
109
|
const unsupported = this.isChainUnsupported(id);
|
|
100
|
-
if ((_this$options2 = this.options) !== null && _this$options2 !== void 0 && _this$options2.shimDisconnect) (
|
|
110
|
+
if ((_this$options2 = this.options) !== null && _this$options2 !== void 0 && _this$options2.shimDisconnect) (_getClient$storage2 = getClient().storage) === null || _getClient$storage2 === void 0 ? void 0 : _getClient$storage2.setItem(shimKey, true);
|
|
101
111
|
return {
|
|
102
112
|
account,
|
|
103
113
|
chain: {
|
|
@@ -113,14 +123,14 @@ class InjectedConnector extends Connector {
|
|
|
113
123
|
}
|
|
114
124
|
|
|
115
125
|
async disconnect() {
|
|
116
|
-
var _this$options3,
|
|
126
|
+
var _this$options3, _getClient$storage3;
|
|
117
127
|
|
|
118
128
|
const provider = await this.getProvider();
|
|
119
129
|
if (!(provider !== null && provider !== void 0 && provider.removeListener)) return;
|
|
120
130
|
provider.removeListener('accountsChanged', this.onAccountsChanged);
|
|
121
131
|
provider.removeListener('chainChanged', this.onChainChanged);
|
|
122
132
|
provider.removeListener('disconnect', this.onDisconnect);
|
|
123
|
-
if ((_this$options3 = this.options) !== null && _this$options3 !== void 0 && _this$options3.shimDisconnect) (
|
|
133
|
+
if ((_this$options3 = this.options) !== null && _this$options3 !== void 0 && _this$options3.shimDisconnect) (_getClient$storage3 = getClient().storage) === null || _getClient$storage3 === void 0 ? void 0 : _getClient$storage3.removeItem(shimKey);
|
|
124
134
|
}
|
|
125
135
|
|
|
126
136
|
async getAccount() {
|
|
@@ -153,9 +163,9 @@ class InjectedConnector extends Connector {
|
|
|
153
163
|
|
|
154
164
|
async isAuthorized() {
|
|
155
165
|
try {
|
|
156
|
-
var _this$options4,
|
|
166
|
+
var _this$options4, _getClient$storage4;
|
|
157
167
|
|
|
158
|
-
if ((_this$options4 = this.options) !== null && _this$options4 !== void 0 && _this$options4.shimDisconnect && !((
|
|
168
|
+
if ((_this$options4 = this.options) !== null && _this$options4 !== void 0 && _this$options4.shimDisconnect && !((_getClient$storage4 = getClient().storage) !== null && _getClient$storage4 !== void 0 && _getClient$storage4.getItem(shimKey))) return false;
|
|
159
169
|
const provider = await this.getProvider();
|
|
160
170
|
if (!provider) throw new ConnectorNotFoundError();
|
|
161
171
|
const accounts = await provider.request({
|
|
@@ -307,7 +317,7 @@ class Client {
|
|
|
307
317
|
const _provider = (_config$provider = config.provider) !== null && _config$provider !== void 0 ? _config$provider : config => {
|
|
308
318
|
try {
|
|
309
319
|
return getDefaultProvider(config.chainId);
|
|
310
|
-
} catch
|
|
320
|
+
} catch {
|
|
311
321
|
return getDefaultProvider();
|
|
312
322
|
}
|
|
313
323
|
};
|
|
@@ -569,22 +579,50 @@ async function connect(_ref) {
|
|
|
569
579
|
}
|
|
570
580
|
|
|
571
581
|
async function disconnect() {
|
|
582
|
+
const client = getClient();
|
|
572
583
|
if (client.connector) await client.connector.disconnect();
|
|
573
584
|
client.clearState();
|
|
574
585
|
client.storage.removeItem('connected');
|
|
575
586
|
}
|
|
576
587
|
|
|
588
|
+
function getProvider() {
|
|
589
|
+
let {
|
|
590
|
+
chainId
|
|
591
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
592
|
+
const client = getClient();
|
|
593
|
+
if (chainId && typeof client.config.provider === 'function') return client.config.provider({
|
|
594
|
+
chainId
|
|
595
|
+
});
|
|
596
|
+
return client.provider;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
function getWebSocketProvider() {
|
|
600
|
+
let {
|
|
601
|
+
chainId
|
|
602
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
603
|
+
const client = getClient();
|
|
604
|
+
if (chainId && typeof client.config.webSocketProvider === 'function') return client.config.webSocketProvider({
|
|
605
|
+
chainId
|
|
606
|
+
});
|
|
607
|
+
return client.webSocketProvider;
|
|
608
|
+
}
|
|
609
|
+
|
|
577
610
|
async function fetchBalance(_ref) {
|
|
578
611
|
var _client$connector$cha, _client$connector, _chain$nativeCurrency, _chain$nativeCurrency2, _chain$nativeCurrency3, _chain$nativeCurrency4;
|
|
579
612
|
|
|
580
613
|
let {
|
|
581
614
|
addressOrName,
|
|
615
|
+
chainId,
|
|
582
616
|
formatUnits: unit = 'ether',
|
|
583
617
|
token
|
|
584
618
|
} = _ref;
|
|
619
|
+
const client = getClient();
|
|
620
|
+
const provider = getProvider({
|
|
621
|
+
chainId
|
|
622
|
+
});
|
|
585
623
|
|
|
586
624
|
if (token) {
|
|
587
|
-
const contract = new Contract(token, erc20ABI,
|
|
625
|
+
const contract = new Contract(token, erc20ABI, provider);
|
|
588
626
|
const [value, decimals, symbol] = await Promise.all([contract.balanceOf(addressOrName), contract.decimals(), contract.symbol()]);
|
|
589
627
|
return {
|
|
590
628
|
decimals,
|
|
@@ -596,8 +634,8 @@ async function fetchBalance(_ref) {
|
|
|
596
634
|
}
|
|
597
635
|
|
|
598
636
|
const chains = [...((_client$connector$cha = (_client$connector = client.connector) === null || _client$connector === void 0 ? void 0 : _client$connector.chains) !== null && _client$connector$cha !== void 0 ? _client$connector$cha : []), ...allChains];
|
|
599
|
-
const value = await
|
|
600
|
-
const chain = chains.find(x => x.id ===
|
|
637
|
+
const value = await provider.getBalance(addressOrName);
|
|
638
|
+
const chain = chains.find(x => x.id === provider.network.chainId);
|
|
601
639
|
return {
|
|
602
640
|
decimals: (_chain$nativeCurrency = chain === null || chain === void 0 ? void 0 : (_chain$nativeCurrency2 = chain.nativeCurrency) === null || _chain$nativeCurrency2 === void 0 ? void 0 : _chain$nativeCurrency2.decimals) !== null && _chain$nativeCurrency !== void 0 ? _chain$nativeCurrency : 18,
|
|
603
641
|
formatted: formatUnits(value, unit),
|
|
@@ -610,6 +648,7 @@ async function fetchBalance(_ref) {
|
|
|
610
648
|
async function fetchSigner() {
|
|
611
649
|
var _client$connector, _client$connector$get;
|
|
612
650
|
|
|
651
|
+
const client = getClient();
|
|
613
652
|
const signer = await ((_client$connector = client.connector) === null || _client$connector === void 0 ? void 0 : (_client$connector$get = _client$connector.getSigner) === null || _client$connector$get === void 0 ? void 0 : _client$connector$get.call(_client$connector));
|
|
614
653
|
return signer;
|
|
615
654
|
}
|
|
@@ -618,7 +657,7 @@ function getAccount() {
|
|
|
618
657
|
const {
|
|
619
658
|
data,
|
|
620
659
|
connector
|
|
621
|
-
} =
|
|
660
|
+
} = getClient();
|
|
622
661
|
return {
|
|
623
662
|
address: data === null || data === void 0 ? void 0 : data.account,
|
|
624
663
|
connector
|
|
@@ -626,15 +665,11 @@ function getAccount() {
|
|
|
626
665
|
}
|
|
627
666
|
|
|
628
667
|
function getNetwork() {
|
|
629
|
-
var
|
|
668
|
+
var _client$data, _client$data$chain, _client$chains, _find, _client$data2;
|
|
630
669
|
|
|
631
|
-
const
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
} = client;
|
|
635
|
-
const chainId = data === null || data === void 0 ? void 0 : (_data$chain = data.chain) === null || _data$chain === void 0 ? void 0 : _data$chain.id;
|
|
636
|
-
const unsupported = data === null || data === void 0 ? void 0 : (_data$chain2 = data.chain) === null || _data$chain2 === void 0 ? void 0 : _data$chain2.unsupported;
|
|
637
|
-
const activeChains = chains !== null && chains !== void 0 ? chains : [];
|
|
670
|
+
const client = getClient();
|
|
671
|
+
const chainId = (_client$data = client.data) === null || _client$data === void 0 ? void 0 : (_client$data$chain = _client$data.chain) === null || _client$data$chain === void 0 ? void 0 : _client$data$chain.id;
|
|
672
|
+
const activeChains = (_client$chains = client.chains) !== null && _client$chains !== void 0 ? _client$chains : [];
|
|
638
673
|
const activeChain = (_find = [...activeChains, ...allChains].find(x => x.id === chainId)) !== null && _find !== void 0 ? _find : {
|
|
639
674
|
id: chainId,
|
|
640
675
|
name: "Chain ".concat(chainId),
|
|
@@ -644,8 +679,8 @@ function getNetwork() {
|
|
|
644
679
|
};
|
|
645
680
|
return {
|
|
646
681
|
chain: chainId ? { ...activeChain,
|
|
647
|
-
|
|
648
|
-
|
|
682
|
+
...((_client$data2 = client.data) === null || _client$data2 === void 0 ? void 0 : _client$data2.chain),
|
|
683
|
+
id: chainId
|
|
649
684
|
} : undefined,
|
|
650
685
|
chains: activeChains
|
|
651
686
|
};
|
|
@@ -682,12 +717,15 @@ async function switchNetwork(_ref) {
|
|
|
682
717
|
let {
|
|
683
718
|
chainId
|
|
684
719
|
} = _ref;
|
|
720
|
+
const client = getClient();
|
|
685
721
|
if (!((_client$connector = client.connector) !== null && _client$connector !== void 0 && _client$connector.switchChain)) throw new SwitchChainNotSupportedError();
|
|
686
722
|
const chain = await client.connector.switchChain(chainId);
|
|
687
723
|
return chain;
|
|
688
724
|
}
|
|
689
725
|
|
|
690
726
|
function watchAccount(callback) {
|
|
727
|
+
const client = getClient();
|
|
728
|
+
|
|
691
729
|
const handleChange = () => callback(getAccount());
|
|
692
730
|
|
|
693
731
|
const unsubscribe = client.subscribe(_ref => {
|
|
@@ -706,6 +744,8 @@ function watchAccount(callback) {
|
|
|
706
744
|
}
|
|
707
745
|
|
|
708
746
|
function watchBalance(args, callback) {
|
|
747
|
+
const client = getClient();
|
|
748
|
+
|
|
709
749
|
const handleChange = async () => callback(await fetchBalance(args));
|
|
710
750
|
|
|
711
751
|
const unsubscribe = client.subscribe(_ref => {
|
|
@@ -725,6 +765,8 @@ function watchBalance(args, callback) {
|
|
|
725
765
|
}
|
|
726
766
|
|
|
727
767
|
function watchNetwork(callback) {
|
|
768
|
+
const client = getClient();
|
|
769
|
+
|
|
728
770
|
const handleChange = () => callback(getNetwork());
|
|
729
771
|
|
|
730
772
|
const unsubscribe = client.subscribe(_ref => {
|
|
@@ -745,6 +787,8 @@ function watchNetwork(callback) {
|
|
|
745
787
|
}
|
|
746
788
|
|
|
747
789
|
function watchSigner(callback) {
|
|
790
|
+
const client = getClient();
|
|
791
|
+
|
|
748
792
|
const handleChange = async () => callback(await fetchSigner());
|
|
749
793
|
|
|
750
794
|
const unsubscribe = client.subscribe(_ref => {
|
|
@@ -777,17 +821,20 @@ function getContract(_ref) {
|
|
|
777
821
|
async function readContract(contractConfig, functionName) {
|
|
778
822
|
let {
|
|
779
823
|
args,
|
|
824
|
+
chainId,
|
|
780
825
|
overrides
|
|
781
826
|
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
782
|
-
const {
|
|
783
|
-
|
|
784
|
-
}
|
|
827
|
+
const provider = getProvider({
|
|
828
|
+
chainId
|
|
829
|
+
});
|
|
785
830
|
const contract = getContract({
|
|
786
831
|
signerOrProvider: provider,
|
|
787
832
|
...contractConfig
|
|
788
833
|
});
|
|
789
834
|
const params = [...(Array.isArray(args) ? args : args ? [args] : []), ...(overrides ? [overrides] : [])];
|
|
790
|
-
const
|
|
835
|
+
const contractFunction = contract[functionName];
|
|
836
|
+
if (!contractFunction) console.warn("\"".concat(functionName, "\" does not in interface for contract \"").concat(contractConfig.addressOrName, "\""));
|
|
837
|
+
const response = await (contractFunction === null || contractFunction === void 0 ? void 0 : contractFunction(...params));
|
|
791
838
|
return response;
|
|
792
839
|
}
|
|
793
840
|
|
|
@@ -797,6 +844,7 @@ contractArgs,
|
|
|
797
844
|
/** Event name to listen to */
|
|
798
845
|
eventName, callback) {
|
|
799
846
|
let {
|
|
847
|
+
chainId,
|
|
800
848
|
once
|
|
801
849
|
} = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
802
850
|
let contract;
|
|
@@ -809,13 +857,18 @@ eventName, callback) {
|
|
|
809
857
|
}
|
|
810
858
|
|
|
811
859
|
contract = getContract({
|
|
812
|
-
signerOrProvider:
|
|
860
|
+
signerOrProvider: getWebSocketProvider({
|
|
861
|
+
chainId
|
|
862
|
+
}) || getProvider({
|
|
863
|
+
chainId
|
|
864
|
+
}),
|
|
813
865
|
...contractArgs
|
|
814
866
|
});
|
|
815
867
|
if (once) contract.once(eventName, callback);else contract.on(eventName, callback);
|
|
816
868
|
};
|
|
817
869
|
|
|
818
870
|
watchEvent();
|
|
871
|
+
const client = getClient();
|
|
819
872
|
const unsubscribe = client.subscribe(_ref => {
|
|
820
873
|
let {
|
|
821
874
|
provider,
|
|
@@ -837,11 +890,19 @@ eventName, callback) {
|
|
|
837
890
|
}
|
|
838
891
|
|
|
839
892
|
async function fetchBlockNumber() {
|
|
840
|
-
|
|
893
|
+
let {
|
|
894
|
+
chainId
|
|
895
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
896
|
+
const provider = getProvider({
|
|
897
|
+
chainId
|
|
898
|
+
});
|
|
899
|
+
const blockNumber = await provider.getBlockNumber();
|
|
841
900
|
return blockNumber;
|
|
842
901
|
}
|
|
843
902
|
|
|
844
903
|
function watchBlockNumber(args, callback) {
|
|
904
|
+
var _client$webSocketProv;
|
|
905
|
+
|
|
845
906
|
let prevProvider;
|
|
846
907
|
|
|
847
908
|
const createListener = provider => {
|
|
@@ -859,11 +920,8 @@ function watchBlockNumber(args, callback) {
|
|
|
859
920
|
prevProvider = provider;
|
|
860
921
|
};
|
|
861
922
|
|
|
862
|
-
const
|
|
863
|
-
|
|
864
|
-
webSocketProvider
|
|
865
|
-
} = client;
|
|
866
|
-
const provider_ = webSocketProvider !== null && webSocketProvider !== void 0 ? webSocketProvider : provider;
|
|
923
|
+
const client = getClient();
|
|
924
|
+
const provider_ = (_client$webSocketProv = client.webSocketProvider) !== null && _client$webSocketProv !== void 0 ? _client$webSocketProv : client.provider;
|
|
867
925
|
if (args.listen) createListener(provider_);
|
|
868
926
|
const unsubscribe = client.subscribe(_ref => {
|
|
869
927
|
let {
|
|
@@ -897,6 +955,7 @@ function watchReadContract(contractConfig, functionName) {
|
|
|
897
955
|
|
|
898
956
|
let config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
899
957
|
let callback = arguments.length > 3 ? arguments[3] : undefined;
|
|
958
|
+
const client = getClient();
|
|
900
959
|
|
|
901
960
|
const handleChange = async () => callback(await readContract(contractConfig, functionName, config));
|
|
902
961
|
|
|
@@ -920,17 +979,17 @@ async function writeContract(contractConfig, functionName) {
|
|
|
920
979
|
args,
|
|
921
980
|
overrides
|
|
922
981
|
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
923
|
-
const
|
|
924
|
-
|
|
925
|
-
} = client;
|
|
926
|
-
const contract = getContract(contractConfig);
|
|
927
|
-
if (!connector) throw new ConnectorNotFoundError();
|
|
982
|
+
const client = getClient();
|
|
983
|
+
if (!client.connector) throw new ConnectorNotFoundError();
|
|
928
984
|
const params = [...(Array.isArray(args) ? args : args ? [args] : []), ...(overrides ? [overrides] : [])];
|
|
929
985
|
|
|
930
986
|
try {
|
|
931
|
-
const signer = await connector.getSigner();
|
|
932
|
-
const
|
|
933
|
-
const
|
|
987
|
+
const signer = await client.connector.getSigner();
|
|
988
|
+
const contract = getContract(contractConfig);
|
|
989
|
+
const contractWithSigner = contract.connect(signer);
|
|
990
|
+
const contractFunction = contractWithSigner[functionName];
|
|
991
|
+
if (!contractFunction) console.warn("\"".concat(functionName, "\" does not in interface for contract \"").concat(contractConfig.addressOrName, "\""));
|
|
992
|
+
const response = await contractFunction(...params);
|
|
934
993
|
return response;
|
|
935
994
|
} catch (error_) {
|
|
936
995
|
let error = error_;
|
|
@@ -941,9 +1000,13 @@ async function writeContract(contractConfig, functionName) {
|
|
|
941
1000
|
|
|
942
1001
|
async function fetchEnsAddress(_ref) {
|
|
943
1002
|
let {
|
|
1003
|
+
chainId,
|
|
944
1004
|
name
|
|
945
1005
|
} = _ref;
|
|
946
|
-
const
|
|
1006
|
+
const provider = getProvider({
|
|
1007
|
+
chainId
|
|
1008
|
+
});
|
|
1009
|
+
const address = await provider.resolveName(name);
|
|
947
1010
|
|
|
948
1011
|
try {
|
|
949
1012
|
return address ? getAddress(address) : null;
|
|
@@ -954,31 +1017,45 @@ async function fetchEnsAddress(_ref) {
|
|
|
954
1017
|
|
|
955
1018
|
async function fetchEnsAvatar(_ref) {
|
|
956
1019
|
let {
|
|
957
|
-
addressOrName
|
|
1020
|
+
addressOrName,
|
|
1021
|
+
chainId
|
|
958
1022
|
} = _ref;
|
|
959
|
-
|
|
1023
|
+
const provider = getProvider({
|
|
1024
|
+
chainId
|
|
1025
|
+
}); // TODO: Update with more advanced logic
|
|
960
1026
|
// https://github.com/ensdomains/ens-avatar
|
|
961
|
-
|
|
1027
|
+
|
|
1028
|
+
const avatar = await provider.getAvatar(addressOrName);
|
|
962
1029
|
return avatar;
|
|
963
1030
|
}
|
|
964
1031
|
|
|
965
1032
|
async function fetchEnsName(_ref) {
|
|
966
1033
|
let {
|
|
967
|
-
address
|
|
1034
|
+
address,
|
|
1035
|
+
chainId
|
|
968
1036
|
} = _ref;
|
|
969
|
-
const
|
|
1037
|
+
const provider = getProvider({
|
|
1038
|
+
chainId
|
|
1039
|
+
});
|
|
1040
|
+
const ensName = await provider.lookupAddress(address);
|
|
970
1041
|
return ensName;
|
|
971
1042
|
}
|
|
972
1043
|
|
|
973
1044
|
async function fetchEnsResolver(_ref) {
|
|
974
1045
|
let {
|
|
1046
|
+
chainId,
|
|
975
1047
|
name
|
|
976
1048
|
} = _ref;
|
|
977
|
-
const
|
|
1049
|
+
const provider = getProvider({
|
|
1050
|
+
chainId
|
|
1051
|
+
});
|
|
1052
|
+
const resolver = await provider.getResolver(name);
|
|
978
1053
|
return resolver;
|
|
979
1054
|
}
|
|
980
1055
|
|
|
981
1056
|
function watchEnsAddress(args, callback) {
|
|
1057
|
+
const client = getClient();
|
|
1058
|
+
|
|
982
1059
|
const handleChange = async () => callback(await fetchEnsAddress(args));
|
|
983
1060
|
|
|
984
1061
|
const unsubscribe = client.subscribe(_ref => {
|
|
@@ -991,6 +1068,8 @@ function watchEnsAddress(args, callback) {
|
|
|
991
1068
|
}
|
|
992
1069
|
|
|
993
1070
|
function watchEnsAvatar(args, callback) {
|
|
1071
|
+
const client = getClient();
|
|
1072
|
+
|
|
994
1073
|
const handleChange = async () => callback(await fetchEnsAvatar(args));
|
|
995
1074
|
|
|
996
1075
|
const unsubscribe = client.subscribe(_ref => {
|
|
@@ -1003,6 +1082,8 @@ function watchEnsAvatar(args, callback) {
|
|
|
1003
1082
|
}
|
|
1004
1083
|
|
|
1005
1084
|
function watchEnsName(args, callback) {
|
|
1085
|
+
const client = getClient();
|
|
1086
|
+
|
|
1006
1087
|
const handleChange = async () => callback(await fetchEnsName(args));
|
|
1007
1088
|
|
|
1008
1089
|
const unsubscribe = client.subscribe(_ref => {
|
|
@@ -1015,6 +1096,8 @@ function watchEnsName(args, callback) {
|
|
|
1015
1096
|
}
|
|
1016
1097
|
|
|
1017
1098
|
function watchEnsResolver(args, callback) {
|
|
1099
|
+
const client = getClient();
|
|
1100
|
+
|
|
1018
1101
|
const handleChange = async () => callback(await fetchEnsResolver(args));
|
|
1019
1102
|
|
|
1020
1103
|
const unsubscribe = client.subscribe(_ref => {
|
|
@@ -1028,9 +1111,13 @@ function watchEnsResolver(args, callback) {
|
|
|
1028
1111
|
|
|
1029
1112
|
async function fetchFeeData() {
|
|
1030
1113
|
let {
|
|
1114
|
+
chainId,
|
|
1031
1115
|
formatUnits: units = 'wei'
|
|
1032
1116
|
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1033
|
-
const
|
|
1117
|
+
const provider = getProvider({
|
|
1118
|
+
chainId
|
|
1119
|
+
});
|
|
1120
|
+
const feeData = await provider.getFeeData();
|
|
1034
1121
|
const formatted = {
|
|
1035
1122
|
gasPrice: formatUnits(feeData.gasPrice, units),
|
|
1036
1123
|
maxFeePerGas: formatUnits(feeData.maxFeePerGas, units),
|
|
@@ -1042,6 +1129,8 @@ async function fetchFeeData() {
|
|
|
1042
1129
|
}
|
|
1043
1130
|
|
|
1044
1131
|
function watchFeeData(args, callback) {
|
|
1132
|
+
const client = getClient();
|
|
1133
|
+
|
|
1045
1134
|
const handleChange = async () => callback(await fetchFeeData(args));
|
|
1046
1135
|
|
|
1047
1136
|
const unwatch = args.listenToBlock ? watchBlockNumber({
|
|
@@ -1059,23 +1148,15 @@ function watchFeeData(args, callback) {
|
|
|
1059
1148
|
};
|
|
1060
1149
|
}
|
|
1061
1150
|
|
|
1062
|
-
function getProvider() {
|
|
1063
|
-
return getClient().provider;
|
|
1064
|
-
}
|
|
1065
|
-
|
|
1066
|
-
function getWebSocketProvider() {
|
|
1067
|
-
return getClient().provider;
|
|
1068
|
-
}
|
|
1069
|
-
|
|
1070
1151
|
async function fetchToken(_ref) {
|
|
1071
1152
|
let {
|
|
1072
1153
|
address,
|
|
1154
|
+
chainId,
|
|
1073
1155
|
formatUnits: units = 'ether'
|
|
1074
1156
|
} = _ref;
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
} = client;
|
|
1157
|
+
const provider = getProvider({
|
|
1158
|
+
chainId
|
|
1159
|
+
});
|
|
1079
1160
|
const contract = new Contract(address, erc20ABI, provider);
|
|
1080
1161
|
const [symbol, decimals, totalSupply] = await Promise.all([contract.symbol(), contract.decimals(), contract.totalSupply()]);
|
|
1081
1162
|
const token = {
|
|
@@ -1091,6 +1172,8 @@ async function fetchToken(_ref) {
|
|
|
1091
1172
|
}
|
|
1092
1173
|
|
|
1093
1174
|
function watchToken(args, callback) {
|
|
1175
|
+
const client = getClient();
|
|
1176
|
+
|
|
1094
1177
|
const handleChange = async () => callback(await fetchToken(args));
|
|
1095
1178
|
|
|
1096
1179
|
const unsubscribe = client.subscribe(_ref => {
|
|
@@ -1116,9 +1199,7 @@ async function sendTransaction(args) {
|
|
|
1116
1199
|
}
|
|
1117
1200
|
|
|
1118
1201
|
async function waitForTransaction(args) {
|
|
1119
|
-
const
|
|
1120
|
-
provider
|
|
1121
|
-
} = client;
|
|
1202
|
+
const provider = getProvider();
|
|
1122
1203
|
let promise; // eslint-disable-next-line testing-library/await-async-utils
|
|
1123
1204
|
|
|
1124
1205
|
if (args.wait) promise = args.wait(args.confirmations);else if (args.hash) promise = provider.waitForTransaction(args.hash, args.confirmations, args.timeout);else throw new Error('hash or wait is required');
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wagmi/core",
|
|
3
|
-
"description": "Vanilla JS
|
|
4
|
-
"license": "
|
|
5
|
-
"version": "0.2.0-next.
|
|
3
|
+
"description": "Vanilla JS library for Ethereum",
|
|
4
|
+
"license": "WAGMIT",
|
|
5
|
+
"version": "0.2.0-next.13",
|
|
6
|
+
"author": "awkweb.eth",
|
|
6
7
|
"ethereum": "awkweb.eth",
|
|
7
8
|
"repository": "tmm/wagmi",
|
|
8
9
|
"sideEffects": false,
|
|
@@ -62,5 +63,12 @@
|
|
|
62
63
|
"@coinbase/wallet-sdk": "^3.0.1",
|
|
63
64
|
"@walletconnect/ethereum-provider": "1.7.5",
|
|
64
65
|
"ethers": "^5.5.1"
|
|
65
|
-
}
|
|
66
|
+
},
|
|
67
|
+
"keywords": [
|
|
68
|
+
"eth",
|
|
69
|
+
"ethereum",
|
|
70
|
+
"dapps",
|
|
71
|
+
"wallet",
|
|
72
|
+
"web3"
|
|
73
|
+
]
|
|
66
74
|
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
type AddEthereumChainParameter = {
|
|
2
|
-
chainId: string // A 0x-prefixed hexadecimal string
|
|
3
|
-
chainName: string
|
|
4
|
-
nativeCurrency?: {
|
|
5
|
-
name: string
|
|
6
|
-
symbol: string // 2-6 characters long
|
|
7
|
-
decimals: 18
|
|
8
|
-
}
|
|
9
|
-
rpcUrls: string[]
|
|
10
|
-
blockExplorerUrls?: string[]
|
|
11
|
-
iconUrls?: string[] // Currently ignored.
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
type WatchAssetParams = {
|
|
15
|
-
type: 'ERC20' // In the future, other standards will be supported
|
|
16
|
-
options: {
|
|
17
|
-
address: string // The address of the token contract
|
|
18
|
-
decimals: number // The number of token decimals
|
|
19
|
-
image?: string // A string url of the token logo
|
|
20
|
-
symbol: string // A ticker symbol or shorthand, up to 5 characters
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
type RequestArguments =
|
|
25
|
-
| { method: 'eth_accounts' }
|
|
26
|
-
| { method: 'eth_chainId' }
|
|
27
|
-
| { method: 'eth_requestAccounts' }
|
|
28
|
-
| { method: 'personal_sign'; params: [string, string] }
|
|
29
|
-
| { method: 'wallet_addEthereumChain'; params: AddEthereumChainParameter[] }
|
|
30
|
-
| { method: 'wallet_switchEthereumChain'; params: [{ chainId: string }] }
|
|
31
|
-
| { method: 'wallet_watchAsset'; params: WatchAssetParams }
|
|
32
|
-
|
|
33
|
-
type InjectedProviders = {
|
|
34
|
-
isCoinbaseWallet?: true
|
|
35
|
-
isFrame?: true
|
|
36
|
-
isMetaMask?: true
|
|
37
|
-
isTally?: true
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
interface Window {
|
|
41
|
-
ethereum?: InjectedProviders & {
|
|
42
|
-
on?: (...args: any[]) => void
|
|
43
|
-
removeListener?: (...args: any[]) => void
|
|
44
|
-
request<T = any>(args: RequestArguments): Promise<T>
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
interface ProviderRpcError extends Error {
|
|
49
|
-
code: 4001 | 4902
|
|
50
|
-
data?: unknown
|
|
51
|
-
message: string
|
|
52
|
-
}
|