@wagmi/core 0.2.0-next.11 → 0.2.0-next.12
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/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 +3 -3
- 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 +7 -5
- package/dist/declarations/src/utils/getInjectedName.d.ts +1 -1
- package/dist/wagmi-core.cjs.dev.js +149 -69
- package/dist/wagmi-core.cjs.prod.js +149 -69
- package/dist/wagmi-core.esm.js +149 -69
- package/package.json +2 -2
package/dist/wagmi-core.esm.js
CHANGED
|
@@ -16,13 +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
|
-
|
|
25
|
-
|
|
30
|
+
|
|
31
|
+
for (const [key, val] of injectedOptions) {
|
|
32
|
+
if (ethereum[key]) return val;
|
|
33
|
+
}
|
|
34
|
+
|
|
26
35
|
return 'Injected';
|
|
27
36
|
}
|
|
28
37
|
|
|
@@ -68,10 +77,10 @@ class InjectedConnector extends Connector {
|
|
|
68
77
|
});
|
|
69
78
|
|
|
70
79
|
_defineProperty(this, "onDisconnect", () => {
|
|
71
|
-
var _this$options,
|
|
80
|
+
var _this$options, _getClient$storage;
|
|
72
81
|
|
|
73
82
|
this.emit('disconnect');
|
|
74
|
-
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);
|
|
75
84
|
});
|
|
76
85
|
|
|
77
86
|
let name = 'Injected';
|
|
@@ -81,7 +90,7 @@ class InjectedConnector extends Connector {
|
|
|
81
90
|
|
|
82
91
|
async connect() {
|
|
83
92
|
try {
|
|
84
|
-
var _this$options2,
|
|
93
|
+
var _this$options2, _getClient$storage2;
|
|
85
94
|
|
|
86
95
|
const provider = await this.getProvider();
|
|
87
96
|
if (!provider) throw new ConnectorNotFoundError();
|
|
@@ -98,7 +107,7 @@ class InjectedConnector extends Connector {
|
|
|
98
107
|
const account = await this.getAccount();
|
|
99
108
|
const id = await this.getChainId();
|
|
100
109
|
const unsupported = this.isChainUnsupported(id);
|
|
101
|
-
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);
|
|
102
111
|
return {
|
|
103
112
|
account,
|
|
104
113
|
chain: {
|
|
@@ -114,14 +123,14 @@ class InjectedConnector extends Connector {
|
|
|
114
123
|
}
|
|
115
124
|
|
|
116
125
|
async disconnect() {
|
|
117
|
-
var _this$options3,
|
|
126
|
+
var _this$options3, _getClient$storage3;
|
|
118
127
|
|
|
119
128
|
const provider = await this.getProvider();
|
|
120
129
|
if (!(provider !== null && provider !== void 0 && provider.removeListener)) return;
|
|
121
130
|
provider.removeListener('accountsChanged', this.onAccountsChanged);
|
|
122
131
|
provider.removeListener('chainChanged', this.onChainChanged);
|
|
123
132
|
provider.removeListener('disconnect', this.onDisconnect);
|
|
124
|
-
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);
|
|
125
134
|
}
|
|
126
135
|
|
|
127
136
|
async getAccount() {
|
|
@@ -154,9 +163,9 @@ class InjectedConnector extends Connector {
|
|
|
154
163
|
|
|
155
164
|
async isAuthorized() {
|
|
156
165
|
try {
|
|
157
|
-
var _this$options4,
|
|
166
|
+
var _this$options4, _getClient$storage4;
|
|
158
167
|
|
|
159
|
-
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;
|
|
160
169
|
const provider = await this.getProvider();
|
|
161
170
|
if (!provider) throw new ConnectorNotFoundError();
|
|
162
171
|
const accounts = await provider.request({
|
|
@@ -570,22 +579,50 @@ async function connect(_ref) {
|
|
|
570
579
|
}
|
|
571
580
|
|
|
572
581
|
async function disconnect() {
|
|
582
|
+
const client = getClient();
|
|
573
583
|
if (client.connector) await client.connector.disconnect();
|
|
574
584
|
client.clearState();
|
|
575
585
|
client.storage.removeItem('connected');
|
|
576
586
|
}
|
|
577
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
|
+
|
|
578
610
|
async function fetchBalance(_ref) {
|
|
579
611
|
var _client$connector$cha, _client$connector, _chain$nativeCurrency, _chain$nativeCurrency2, _chain$nativeCurrency3, _chain$nativeCurrency4;
|
|
580
612
|
|
|
581
613
|
let {
|
|
582
614
|
addressOrName,
|
|
615
|
+
chainId,
|
|
583
616
|
formatUnits: unit = 'ether',
|
|
584
617
|
token
|
|
585
618
|
} = _ref;
|
|
619
|
+
const client = getClient();
|
|
620
|
+
const provider = getProvider({
|
|
621
|
+
chainId
|
|
622
|
+
});
|
|
586
623
|
|
|
587
624
|
if (token) {
|
|
588
|
-
const contract = new Contract(token, erc20ABI,
|
|
625
|
+
const contract = new Contract(token, erc20ABI, provider);
|
|
589
626
|
const [value, decimals, symbol] = await Promise.all([contract.balanceOf(addressOrName), contract.decimals(), contract.symbol()]);
|
|
590
627
|
return {
|
|
591
628
|
decimals,
|
|
@@ -597,8 +634,8 @@ async function fetchBalance(_ref) {
|
|
|
597
634
|
}
|
|
598
635
|
|
|
599
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];
|
|
600
|
-
const value = await
|
|
601
|
-
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);
|
|
602
639
|
return {
|
|
603
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,
|
|
604
641
|
formatted: formatUnits(value, unit),
|
|
@@ -611,6 +648,7 @@ async function fetchBalance(_ref) {
|
|
|
611
648
|
async function fetchSigner() {
|
|
612
649
|
var _client$connector, _client$connector$get;
|
|
613
650
|
|
|
651
|
+
const client = getClient();
|
|
614
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));
|
|
615
653
|
return signer;
|
|
616
654
|
}
|
|
@@ -619,7 +657,7 @@ function getAccount() {
|
|
|
619
657
|
const {
|
|
620
658
|
data,
|
|
621
659
|
connector
|
|
622
|
-
} =
|
|
660
|
+
} = getClient();
|
|
623
661
|
return {
|
|
624
662
|
address: data === null || data === void 0 ? void 0 : data.account,
|
|
625
663
|
connector
|
|
@@ -627,15 +665,11 @@ function getAccount() {
|
|
|
627
665
|
}
|
|
628
666
|
|
|
629
667
|
function getNetwork() {
|
|
630
|
-
var
|
|
668
|
+
var _client$data, _client$data$chain, _client$chains, _find, _client$data2;
|
|
631
669
|
|
|
632
|
-
const
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
} = client;
|
|
636
|
-
const chainId = data === null || data === void 0 ? void 0 : (_data$chain = data.chain) === null || _data$chain === void 0 ? void 0 : _data$chain.id;
|
|
637
|
-
const unsupported = data === null || data === void 0 ? void 0 : (_data$chain2 = data.chain) === null || _data$chain2 === void 0 ? void 0 : _data$chain2.unsupported;
|
|
638
|
-
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 : [];
|
|
639
673
|
const activeChain = (_find = [...activeChains, ...allChains].find(x => x.id === chainId)) !== null && _find !== void 0 ? _find : {
|
|
640
674
|
id: chainId,
|
|
641
675
|
name: "Chain ".concat(chainId),
|
|
@@ -645,8 +679,8 @@ function getNetwork() {
|
|
|
645
679
|
};
|
|
646
680
|
return {
|
|
647
681
|
chain: chainId ? { ...activeChain,
|
|
648
|
-
|
|
649
|
-
|
|
682
|
+
...((_client$data2 = client.data) === null || _client$data2 === void 0 ? void 0 : _client$data2.chain),
|
|
683
|
+
id: chainId
|
|
650
684
|
} : undefined,
|
|
651
685
|
chains: activeChains
|
|
652
686
|
};
|
|
@@ -683,12 +717,15 @@ async function switchNetwork(_ref) {
|
|
|
683
717
|
let {
|
|
684
718
|
chainId
|
|
685
719
|
} = _ref;
|
|
720
|
+
const client = getClient();
|
|
686
721
|
if (!((_client$connector = client.connector) !== null && _client$connector !== void 0 && _client$connector.switchChain)) throw new SwitchChainNotSupportedError();
|
|
687
722
|
const chain = await client.connector.switchChain(chainId);
|
|
688
723
|
return chain;
|
|
689
724
|
}
|
|
690
725
|
|
|
691
726
|
function watchAccount(callback) {
|
|
727
|
+
const client = getClient();
|
|
728
|
+
|
|
692
729
|
const handleChange = () => callback(getAccount());
|
|
693
730
|
|
|
694
731
|
const unsubscribe = client.subscribe(_ref => {
|
|
@@ -707,6 +744,8 @@ function watchAccount(callback) {
|
|
|
707
744
|
}
|
|
708
745
|
|
|
709
746
|
function watchBalance(args, callback) {
|
|
747
|
+
const client = getClient();
|
|
748
|
+
|
|
710
749
|
const handleChange = async () => callback(await fetchBalance(args));
|
|
711
750
|
|
|
712
751
|
const unsubscribe = client.subscribe(_ref => {
|
|
@@ -726,6 +765,8 @@ function watchBalance(args, callback) {
|
|
|
726
765
|
}
|
|
727
766
|
|
|
728
767
|
function watchNetwork(callback) {
|
|
768
|
+
const client = getClient();
|
|
769
|
+
|
|
729
770
|
const handleChange = () => callback(getNetwork());
|
|
730
771
|
|
|
731
772
|
const unsubscribe = client.subscribe(_ref => {
|
|
@@ -746,6 +787,8 @@ function watchNetwork(callback) {
|
|
|
746
787
|
}
|
|
747
788
|
|
|
748
789
|
function watchSigner(callback) {
|
|
790
|
+
const client = getClient();
|
|
791
|
+
|
|
749
792
|
const handleChange = async () => callback(await fetchSigner());
|
|
750
793
|
|
|
751
794
|
const unsubscribe = client.subscribe(_ref => {
|
|
@@ -778,17 +821,20 @@ function getContract(_ref) {
|
|
|
778
821
|
async function readContract(contractConfig, functionName) {
|
|
779
822
|
let {
|
|
780
823
|
args,
|
|
824
|
+
chainId,
|
|
781
825
|
overrides
|
|
782
826
|
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
783
|
-
const {
|
|
784
|
-
|
|
785
|
-
}
|
|
827
|
+
const provider = getProvider({
|
|
828
|
+
chainId
|
|
829
|
+
});
|
|
786
830
|
const contract = getContract({
|
|
787
831
|
signerOrProvider: provider,
|
|
788
832
|
...contractConfig
|
|
789
833
|
});
|
|
790
834
|
const params = [...(Array.isArray(args) ? args : args ? [args] : []), ...(overrides ? [overrides] : [])];
|
|
791
|
-
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));
|
|
792
838
|
return response;
|
|
793
839
|
}
|
|
794
840
|
|
|
@@ -798,6 +844,7 @@ contractArgs,
|
|
|
798
844
|
/** Event name to listen to */
|
|
799
845
|
eventName, callback) {
|
|
800
846
|
let {
|
|
847
|
+
chainId,
|
|
801
848
|
once
|
|
802
849
|
} = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
803
850
|
let contract;
|
|
@@ -810,13 +857,18 @@ eventName, callback) {
|
|
|
810
857
|
}
|
|
811
858
|
|
|
812
859
|
contract = getContract({
|
|
813
|
-
signerOrProvider:
|
|
860
|
+
signerOrProvider: getWebSocketProvider({
|
|
861
|
+
chainId
|
|
862
|
+
}) || getProvider({
|
|
863
|
+
chainId
|
|
864
|
+
}),
|
|
814
865
|
...contractArgs
|
|
815
866
|
});
|
|
816
867
|
if (once) contract.once(eventName, callback);else contract.on(eventName, callback);
|
|
817
868
|
};
|
|
818
869
|
|
|
819
870
|
watchEvent();
|
|
871
|
+
const client = getClient();
|
|
820
872
|
const unsubscribe = client.subscribe(_ref => {
|
|
821
873
|
let {
|
|
822
874
|
provider,
|
|
@@ -838,11 +890,19 @@ eventName, callback) {
|
|
|
838
890
|
}
|
|
839
891
|
|
|
840
892
|
async function fetchBlockNumber() {
|
|
841
|
-
|
|
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();
|
|
842
900
|
return blockNumber;
|
|
843
901
|
}
|
|
844
902
|
|
|
845
903
|
function watchBlockNumber(args, callback) {
|
|
904
|
+
var _client$webSocketProv;
|
|
905
|
+
|
|
846
906
|
let prevProvider;
|
|
847
907
|
|
|
848
908
|
const createListener = provider => {
|
|
@@ -860,11 +920,8 @@ function watchBlockNumber(args, callback) {
|
|
|
860
920
|
prevProvider = provider;
|
|
861
921
|
};
|
|
862
922
|
|
|
863
|
-
const
|
|
864
|
-
|
|
865
|
-
webSocketProvider
|
|
866
|
-
} = client;
|
|
867
|
-
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;
|
|
868
925
|
if (args.listen) createListener(provider_);
|
|
869
926
|
const unsubscribe = client.subscribe(_ref => {
|
|
870
927
|
let {
|
|
@@ -898,6 +955,7 @@ function watchReadContract(contractConfig, functionName) {
|
|
|
898
955
|
|
|
899
956
|
let config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
900
957
|
let callback = arguments.length > 3 ? arguments[3] : undefined;
|
|
958
|
+
const client = getClient();
|
|
901
959
|
|
|
902
960
|
const handleChange = async () => callback(await readContract(contractConfig, functionName, config));
|
|
903
961
|
|
|
@@ -921,17 +979,17 @@ async function writeContract(contractConfig, functionName) {
|
|
|
921
979
|
args,
|
|
922
980
|
overrides
|
|
923
981
|
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
924
|
-
const
|
|
925
|
-
|
|
926
|
-
} = client;
|
|
927
|
-
const contract = getContract(contractConfig);
|
|
928
|
-
if (!connector) throw new ConnectorNotFoundError();
|
|
982
|
+
const client = getClient();
|
|
983
|
+
if (!client.connector) throw new ConnectorNotFoundError();
|
|
929
984
|
const params = [...(Array.isArray(args) ? args : args ? [args] : []), ...(overrides ? [overrides] : [])];
|
|
930
985
|
|
|
931
986
|
try {
|
|
932
|
-
const signer = await connector.getSigner();
|
|
933
|
-
const
|
|
934
|
-
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);
|
|
935
993
|
return response;
|
|
936
994
|
} catch (error_) {
|
|
937
995
|
let error = error_;
|
|
@@ -942,9 +1000,13 @@ async function writeContract(contractConfig, functionName) {
|
|
|
942
1000
|
|
|
943
1001
|
async function fetchEnsAddress(_ref) {
|
|
944
1002
|
let {
|
|
1003
|
+
chainId,
|
|
945
1004
|
name
|
|
946
1005
|
} = _ref;
|
|
947
|
-
const
|
|
1006
|
+
const provider = getProvider({
|
|
1007
|
+
chainId
|
|
1008
|
+
});
|
|
1009
|
+
const address = await provider.resolveName(name);
|
|
948
1010
|
|
|
949
1011
|
try {
|
|
950
1012
|
return address ? getAddress(address) : null;
|
|
@@ -955,31 +1017,45 @@ async function fetchEnsAddress(_ref) {
|
|
|
955
1017
|
|
|
956
1018
|
async function fetchEnsAvatar(_ref) {
|
|
957
1019
|
let {
|
|
958
|
-
addressOrName
|
|
1020
|
+
addressOrName,
|
|
1021
|
+
chainId
|
|
959
1022
|
} = _ref;
|
|
960
|
-
|
|
1023
|
+
const provider = getProvider({
|
|
1024
|
+
chainId
|
|
1025
|
+
}); // TODO: Update with more advanced logic
|
|
961
1026
|
// https://github.com/ensdomains/ens-avatar
|
|
962
|
-
|
|
1027
|
+
|
|
1028
|
+
const avatar = await provider.getAvatar(addressOrName);
|
|
963
1029
|
return avatar;
|
|
964
1030
|
}
|
|
965
1031
|
|
|
966
1032
|
async function fetchEnsName(_ref) {
|
|
967
1033
|
let {
|
|
968
|
-
address
|
|
1034
|
+
address,
|
|
1035
|
+
chainId
|
|
969
1036
|
} = _ref;
|
|
970
|
-
const
|
|
1037
|
+
const provider = getProvider({
|
|
1038
|
+
chainId
|
|
1039
|
+
});
|
|
1040
|
+
const ensName = await provider.lookupAddress(address);
|
|
971
1041
|
return ensName;
|
|
972
1042
|
}
|
|
973
1043
|
|
|
974
1044
|
async function fetchEnsResolver(_ref) {
|
|
975
1045
|
let {
|
|
1046
|
+
chainId,
|
|
976
1047
|
name
|
|
977
1048
|
} = _ref;
|
|
978
|
-
const
|
|
1049
|
+
const provider = getProvider({
|
|
1050
|
+
chainId
|
|
1051
|
+
});
|
|
1052
|
+
const resolver = await provider.getResolver(name);
|
|
979
1053
|
return resolver;
|
|
980
1054
|
}
|
|
981
1055
|
|
|
982
1056
|
function watchEnsAddress(args, callback) {
|
|
1057
|
+
const client = getClient();
|
|
1058
|
+
|
|
983
1059
|
const handleChange = async () => callback(await fetchEnsAddress(args));
|
|
984
1060
|
|
|
985
1061
|
const unsubscribe = client.subscribe(_ref => {
|
|
@@ -992,6 +1068,8 @@ function watchEnsAddress(args, callback) {
|
|
|
992
1068
|
}
|
|
993
1069
|
|
|
994
1070
|
function watchEnsAvatar(args, callback) {
|
|
1071
|
+
const client = getClient();
|
|
1072
|
+
|
|
995
1073
|
const handleChange = async () => callback(await fetchEnsAvatar(args));
|
|
996
1074
|
|
|
997
1075
|
const unsubscribe = client.subscribe(_ref => {
|
|
@@ -1004,6 +1082,8 @@ function watchEnsAvatar(args, callback) {
|
|
|
1004
1082
|
}
|
|
1005
1083
|
|
|
1006
1084
|
function watchEnsName(args, callback) {
|
|
1085
|
+
const client = getClient();
|
|
1086
|
+
|
|
1007
1087
|
const handleChange = async () => callback(await fetchEnsName(args));
|
|
1008
1088
|
|
|
1009
1089
|
const unsubscribe = client.subscribe(_ref => {
|
|
@@ -1016,6 +1096,8 @@ function watchEnsName(args, callback) {
|
|
|
1016
1096
|
}
|
|
1017
1097
|
|
|
1018
1098
|
function watchEnsResolver(args, callback) {
|
|
1099
|
+
const client = getClient();
|
|
1100
|
+
|
|
1019
1101
|
const handleChange = async () => callback(await fetchEnsResolver(args));
|
|
1020
1102
|
|
|
1021
1103
|
const unsubscribe = client.subscribe(_ref => {
|
|
@@ -1029,9 +1111,13 @@ function watchEnsResolver(args, callback) {
|
|
|
1029
1111
|
|
|
1030
1112
|
async function fetchFeeData() {
|
|
1031
1113
|
let {
|
|
1114
|
+
chainId,
|
|
1032
1115
|
formatUnits: units = 'wei'
|
|
1033
1116
|
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1034
|
-
const
|
|
1117
|
+
const provider = getProvider({
|
|
1118
|
+
chainId
|
|
1119
|
+
});
|
|
1120
|
+
const feeData = await provider.getFeeData();
|
|
1035
1121
|
const formatted = {
|
|
1036
1122
|
gasPrice: formatUnits(feeData.gasPrice, units),
|
|
1037
1123
|
maxFeePerGas: formatUnits(feeData.maxFeePerGas, units),
|
|
@@ -1043,6 +1129,8 @@ async function fetchFeeData() {
|
|
|
1043
1129
|
}
|
|
1044
1130
|
|
|
1045
1131
|
function watchFeeData(args, callback) {
|
|
1132
|
+
const client = getClient();
|
|
1133
|
+
|
|
1046
1134
|
const handleChange = async () => callback(await fetchFeeData(args));
|
|
1047
1135
|
|
|
1048
1136
|
const unwatch = args.listenToBlock ? watchBlockNumber({
|
|
@@ -1060,23 +1148,15 @@ function watchFeeData(args, callback) {
|
|
|
1060
1148
|
};
|
|
1061
1149
|
}
|
|
1062
1150
|
|
|
1063
|
-
function getProvider() {
|
|
1064
|
-
return getClient().provider;
|
|
1065
|
-
}
|
|
1066
|
-
|
|
1067
|
-
function getWebSocketProvider() {
|
|
1068
|
-
return getClient().webSocketProvider;
|
|
1069
|
-
}
|
|
1070
|
-
|
|
1071
1151
|
async function fetchToken(_ref) {
|
|
1072
1152
|
let {
|
|
1073
1153
|
address,
|
|
1154
|
+
chainId,
|
|
1074
1155
|
formatUnits: units = 'ether'
|
|
1075
1156
|
} = _ref;
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
} = client;
|
|
1157
|
+
const provider = getProvider({
|
|
1158
|
+
chainId
|
|
1159
|
+
});
|
|
1080
1160
|
const contract = new Contract(address, erc20ABI, provider);
|
|
1081
1161
|
const [symbol, decimals, totalSupply] = await Promise.all([contract.symbol(), contract.decimals(), contract.totalSupply()]);
|
|
1082
1162
|
const token = {
|
|
@@ -1092,6 +1172,8 @@ async function fetchToken(_ref) {
|
|
|
1092
1172
|
}
|
|
1093
1173
|
|
|
1094
1174
|
function watchToken(args, callback) {
|
|
1175
|
+
const client = getClient();
|
|
1176
|
+
|
|
1095
1177
|
const handleChange = async () => callback(await fetchToken(args));
|
|
1096
1178
|
|
|
1097
1179
|
const unsubscribe = client.subscribe(_ref => {
|
|
@@ -1117,9 +1199,7 @@ async function sendTransaction(args) {
|
|
|
1117
1199
|
}
|
|
1118
1200
|
|
|
1119
1201
|
async function waitForTransaction(args) {
|
|
1120
|
-
const
|
|
1121
|
-
provider
|
|
1122
|
-
} = client;
|
|
1202
|
+
const provider = getProvider();
|
|
1123
1203
|
let promise; // eslint-disable-next-line testing-library/await-async-utils
|
|
1124
1204
|
|
|
1125
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