@wagmi/core 0.4.2 → 0.4.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/README.md +1 -1
- package/chains/dist/wagmi-core-chains.cjs.dev.js +1 -1
- package/chains/dist/wagmi-core-chains.cjs.prod.js +1 -1
- package/chains/dist/wagmi-core-chains.esm.js +1 -1
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.dev.js +2 -2
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.prod.js +2 -2
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.esm.js +2 -2
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.dev.js +74 -3
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.prod.js +74 -3
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.esm.js +74 -3
- 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 +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 +9 -6
- package/dist/{base-e71ae4b2.cjs.dev.js → base-797ad073.cjs.prod.js} +17 -3
- package/dist/{base-2d484f6c.cjs.prod.js → base-90b7f3e4.cjs.dev.js} +17 -3
- package/dist/{base-e66f9622.esm.js → base-b565d5d4.esm.js} +17 -4
- package/dist/{chains-d970ee8d.cjs.dev.js → chains-7e6dc59c.cjs.dev.js} +1 -1
- package/dist/{chains-865492ea.cjs.prod.js → chains-f7bb3211.cjs.prod.js} +1 -1
- package/dist/{chains-c389721d.esm.js → chains-fd2c546c.esm.js} +1 -1
- package/dist/{client-53f2119c.cjs.dev.js → client-71ece661.cjs.dev.js} +24 -23
- package/dist/{client-ffba0e25.esm.js → client-a05fd511.esm.js} +20 -20
- package/dist/{client-1feb9121.cjs.prod.js → client-a6e61429.cjs.prod.js} +24 -23
- package/dist/declarations/src/connectors/injected.d.ts +2 -0
- package/dist/declarations/src/connectors/metaMask.d.ts +16 -1
- package/dist/declarations/src/connectors/walletConnect.d.ts +2 -1
- package/dist/declarations/src/errors.d.ts +9 -0
- package/dist/declarations/src/index.d.ts +1 -1
- package/dist/declarations/src/types/index.d.ts +24 -0
- package/dist/wagmi-core.cjs.dev.js +36 -13
- package/dist/wagmi-core.cjs.prod.js +36 -13
- package/dist/wagmi-core.esm.js +31 -9
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import EventEmitter from 'eventemitter3';
|
|
2
|
-
import { d as defaultChains } from './chains-
|
|
2
|
+
import { d as defaultChains } from './chains-fd2c546c.esm.js';
|
|
3
3
|
|
|
4
4
|
function _checkPrivateRedeclaration(obj, privateCollection) {
|
|
5
5
|
if (privateCollection.has(obj)) {
|
|
@@ -205,6 +205,19 @@ class ConnectorNotFoundError extends Error {
|
|
|
205
205
|
_defineProperty(this, "message", 'Connector not found');
|
|
206
206
|
}
|
|
207
207
|
|
|
208
|
+
}
|
|
209
|
+
class ContractMethodNoResultError extends Error {
|
|
210
|
+
constructor(_ref3) {
|
|
211
|
+
let {
|
|
212
|
+
addressOrName,
|
|
213
|
+
blockExplorer,
|
|
214
|
+
functionName
|
|
215
|
+
} = _ref3;
|
|
216
|
+
super(["Function \"".concat(functionName, "\" on contract \"").concat(addressOrName, "\" returned an empty response."), '', "Are you sure the function \"".concat(functionName, "\" exists on this contract?"), ...(blockExplorer ? ['', "".concat(blockExplorer === null || blockExplorer === void 0 ? void 0 : blockExplorer.name, ": ").concat(blockExplorer === null || blockExplorer === void 0 ? void 0 : blockExplorer.url, "/address/").concat(addressOrName, "#readContract")] : [])].join('\n'));
|
|
217
|
+
|
|
218
|
+
_defineProperty(this, "name", 'ContractMethodNoResultError');
|
|
219
|
+
}
|
|
220
|
+
|
|
208
221
|
}
|
|
209
222
|
class ProviderChainsNotFound extends Error {
|
|
210
223
|
constructor() {
|
|
@@ -233,10 +246,10 @@ class SwitchChainError extends ProviderRpcError {
|
|
|
233
246
|
|
|
234
247
|
}
|
|
235
248
|
class SwitchChainNotSupportedError extends Error {
|
|
236
|
-
constructor(
|
|
249
|
+
constructor(_ref4) {
|
|
237
250
|
let {
|
|
238
251
|
connector
|
|
239
|
-
} =
|
|
252
|
+
} = _ref4;
|
|
240
253
|
super("\"".concat(connector.name, "\" does not support programmatic chain switching."));
|
|
241
254
|
|
|
242
255
|
_defineProperty(this, "name", 'SwitchChainNotSupportedError');
|
|
@@ -300,4 +313,4 @@ class Connector extends EventEmitter {
|
|
|
300
313
|
|
|
301
314
|
}
|
|
302
315
|
|
|
303
|
-
export { AddChainError as A, ConnectorAlreadyConnectedError as C, ProviderChainsNotFound as P, ResourceUnavailableError as R, SwitchChainNotSupportedError as S, UserRejectedRequestError as U,
|
|
316
|
+
export { AddChainError as A, ConnectorAlreadyConnectedError as C, ProviderChainsNotFound as P, ResourceUnavailableError as R, SwitchChainNotSupportedError as S, UserRejectedRequestError as U, _defineProperty as _, ChainDoesNotSupportMulticallError as a, ContractMethodNoResultError as b, ConnectorNotFoundError as c, ChainMismatchError as d, Connector as e, ChainNotConfiguredError as f, ProviderRpcError as g, RpcError as h, SwitchChainError as i, _classPrivateFieldInitSpec as j, _classPrivateFieldGet as k, _classPrivateFieldSet as l, _classPrivateMethodInitSpec as m, normalizeChainId as n, _classPrivateMethodGet as o };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var base = require('./base-
|
|
3
|
+
var base = require('./base-90b7f3e4.cjs.dev.js');
|
|
4
4
|
var create = require('zustand/vanilla');
|
|
5
5
|
var middleware = require('zustand/middleware');
|
|
6
6
|
var ethers = require('ethers');
|
|
@@ -56,14 +56,12 @@ function getInjectedName(ethereum) {
|
|
|
56
56
|
return (_getName = getName(ethereum)) !== null && _getName !== void 0 ? _getName : 'Injected';
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
const
|
|
59
|
+
const shimDisconnectKey = 'injected.shimDisconnect';
|
|
60
60
|
|
|
61
61
|
var _provider = /*#__PURE__*/new WeakMap();
|
|
62
62
|
|
|
63
63
|
var _switchingChains = /*#__PURE__*/new WeakMap();
|
|
64
64
|
|
|
65
|
-
var _isUserRejectedRequestError = /*#__PURE__*/new WeakSet();
|
|
66
|
-
|
|
67
65
|
class InjectedConnector extends base.Connector {
|
|
68
66
|
constructor() {
|
|
69
67
|
let {
|
|
@@ -77,8 +75,6 @@ class InjectedConnector extends base.Connector {
|
|
|
77
75
|
options
|
|
78
76
|
});
|
|
79
77
|
|
|
80
|
-
base._classPrivateMethodInitSpec(this, _isUserRejectedRequestError);
|
|
81
|
-
|
|
82
78
|
base._defineProperty(this, "id", void 0);
|
|
83
79
|
|
|
84
80
|
base._defineProperty(this, "name", void 0);
|
|
@@ -124,8 +120,9 @@ class InjectedConnector extends base.Connector {
|
|
|
124
120
|
return;
|
|
125
121
|
}
|
|
126
122
|
|
|
127
|
-
this.emit('disconnect');
|
|
128
|
-
|
|
123
|
+
this.emit('disconnect'); // Remove shim signalling wallet is disconnected
|
|
124
|
+
|
|
125
|
+
if ((_this$options2 = this.options) !== null && _this$options2 !== void 0 && _this$options2.shimDisconnect) (_getClient$storage = getClient().storage) === null || _getClient$storage === void 0 ? void 0 : _getClient$storage.removeItem(shimDisconnectKey);
|
|
129
126
|
});
|
|
130
127
|
|
|
131
128
|
let name = 'Injected';
|
|
@@ -169,9 +166,10 @@ class InjectedConnector extends base.Connector {
|
|
|
169
166
|
const chain = await this.switchChain(chainId);
|
|
170
167
|
id = chain.id;
|
|
171
168
|
unsupported = this.isChainUnsupported(id);
|
|
172
|
-
}
|
|
169
|
+
} // Add shim to storage signalling wallet is connected
|
|
173
170
|
|
|
174
|
-
|
|
171
|
+
|
|
172
|
+
if ((_this$options3 = this.options) !== null && _this$options3 !== void 0 && _this$options3.shimDisconnect) (_getClient$storage2 = getClient().storage) === null || _getClient$storage2 === void 0 ? void 0 : _getClient$storage2.setItem(shimDisconnectKey, true);
|
|
175
173
|
return {
|
|
176
174
|
account,
|
|
177
175
|
chain: {
|
|
@@ -181,7 +179,7 @@ class InjectedConnector extends base.Connector {
|
|
|
181
179
|
provider
|
|
182
180
|
};
|
|
183
181
|
} catch (error) {
|
|
184
|
-
if (
|
|
182
|
+
if (this.isUserRejectedRequestError(error)) throw new base.UserRejectedRequestError(error);
|
|
185
183
|
if (error.code === -32002) throw new base.ResourceUnavailableError(error);
|
|
186
184
|
throw error;
|
|
187
185
|
}
|
|
@@ -194,8 +192,9 @@ class InjectedConnector extends base.Connector {
|
|
|
194
192
|
if (!(provider !== null && provider !== void 0 && provider.removeListener)) return;
|
|
195
193
|
provider.removeListener('accountsChanged', this.onAccountsChanged);
|
|
196
194
|
provider.removeListener('chainChanged', this.onChainChanged);
|
|
197
|
-
provider.removeListener('disconnect', this.onDisconnect);
|
|
198
|
-
|
|
195
|
+
provider.removeListener('disconnect', this.onDisconnect); // Remove shim signalling wallet is disconnected
|
|
196
|
+
|
|
197
|
+
if ((_this$options4 = this.options) !== null && _this$options4 !== void 0 && _this$options4.shimDisconnect) (_getClient$storage3 = getClient().storage) === null || _getClient$storage3 === void 0 ? void 0 : _getClient$storage3.removeItem(shimDisconnectKey);
|
|
199
198
|
}
|
|
200
199
|
|
|
201
200
|
async getAccount() {
|
|
@@ -230,7 +229,8 @@ class InjectedConnector extends base.Connector {
|
|
|
230
229
|
try {
|
|
231
230
|
var _this$options5, _getClient$storage4;
|
|
232
231
|
|
|
233
|
-
if ((_this$options5 = this.options) !== null && _this$options5 !== void 0 && _this$options5.shimDisconnect &&
|
|
232
|
+
if ((_this$options5 = this.options) !== null && _this$options5 !== void 0 && _this$options5.shimDisconnect && // If shim does not exist in storage, wallet is disconnected
|
|
233
|
+
!((_getClient$storage4 = getClient().storage) !== null && _getClient$storage4 !== void 0 && _getClient$storage4.getItem(shimDisconnectKey))) return false;
|
|
234
234
|
const provider = await this.getProvider();
|
|
235
235
|
if (!provider) throw new base.ConnectorNotFoundError();
|
|
236
236
|
const accounts = await provider.request({
|
|
@@ -292,12 +292,12 @@ class InjectedConnector extends base.Connector {
|
|
|
292
292
|
});
|
|
293
293
|
return chain;
|
|
294
294
|
} catch (addError) {
|
|
295
|
-
if (
|
|
295
|
+
if (this.isUserRejectedRequestError(addError)) throw new base.UserRejectedRequestError(error);
|
|
296
296
|
throw new base.AddChainError();
|
|
297
297
|
}
|
|
298
298
|
}
|
|
299
299
|
|
|
300
|
-
if (
|
|
300
|
+
if (this.isUserRejectedRequestError(error)) throw new base.UserRejectedRequestError(error);
|
|
301
301
|
throw new base.SwitchChainError(error);
|
|
302
302
|
}
|
|
303
303
|
}
|
|
@@ -325,10 +325,10 @@ class InjectedConnector extends base.Connector {
|
|
|
325
325
|
});
|
|
326
326
|
}
|
|
327
327
|
|
|
328
|
-
|
|
328
|
+
isUserRejectedRequestError(error) {
|
|
329
|
+
return error.code === 4001;
|
|
330
|
+
}
|
|
329
331
|
|
|
330
|
-
function _isUserRejectedRequestError2(error) {
|
|
331
|
-
return error.code === 4001;
|
|
332
332
|
}
|
|
333
333
|
|
|
334
334
|
const noopStorage = {
|
|
@@ -636,18 +636,18 @@ function _addEffects2() {
|
|
|
636
636
|
});
|
|
637
637
|
}
|
|
638
638
|
|
|
639
|
-
|
|
639
|
+
let client;
|
|
640
640
|
function createClient(config) {
|
|
641
641
|
const client_ = new Client(config);
|
|
642
|
-
|
|
642
|
+
client = client_;
|
|
643
643
|
return client_;
|
|
644
644
|
}
|
|
645
645
|
function getClient() {
|
|
646
|
-
if (!
|
|
646
|
+
if (!client) {
|
|
647
647
|
throw new Error('No wagmi client found. Ensure you have set up a client: https://wagmi.sh/docs/client');
|
|
648
648
|
}
|
|
649
649
|
|
|
650
|
-
return
|
|
650
|
+
return client;
|
|
651
651
|
}
|
|
652
652
|
|
|
653
653
|
exports.Client = Client;
|
|
@@ -656,3 +656,4 @@ exports.createClient = createClient;
|
|
|
656
656
|
exports.createStorage = createStorage;
|
|
657
657
|
exports.getClient = getClient;
|
|
658
658
|
exports.noopStorage = noopStorage;
|
|
659
|
+
exports.shimDisconnectKey = shimDisconnectKey;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { e as Connector, _ as _defineProperty, j as _classPrivateFieldInitSpec, n as normalizeChainId, k as _classPrivateFieldGet, l as _classPrivateFieldSet, c as ConnectorNotFoundError, U as UserRejectedRequestError, R as ResourceUnavailableError, f as ChainNotConfiguredError, A as AddChainError, i as SwitchChainError, m as _classPrivateMethodInitSpec, o as _classPrivateMethodGet } from './base-b565d5d4.esm.js';
|
|
2
2
|
import create from 'zustand/vanilla';
|
|
3
3
|
import { subscribeWithSelector, persist } from 'zustand/middleware';
|
|
4
4
|
import { providers } from 'ethers';
|
|
@@ -50,14 +50,12 @@ function getInjectedName(ethereum) {
|
|
|
50
50
|
return (_getName = getName(ethereum)) !== null && _getName !== void 0 ? _getName : 'Injected';
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
const
|
|
53
|
+
const shimDisconnectKey = 'injected.shimDisconnect';
|
|
54
54
|
|
|
55
55
|
var _provider = /*#__PURE__*/new WeakMap();
|
|
56
56
|
|
|
57
57
|
var _switchingChains = /*#__PURE__*/new WeakMap();
|
|
58
58
|
|
|
59
|
-
var _isUserRejectedRequestError = /*#__PURE__*/new WeakSet();
|
|
60
|
-
|
|
61
59
|
class InjectedConnector extends Connector {
|
|
62
60
|
constructor() {
|
|
63
61
|
let {
|
|
@@ -71,8 +69,6 @@ class InjectedConnector extends Connector {
|
|
|
71
69
|
options
|
|
72
70
|
});
|
|
73
71
|
|
|
74
|
-
_classPrivateMethodInitSpec(this, _isUserRejectedRequestError);
|
|
75
|
-
|
|
76
72
|
_defineProperty(this, "id", void 0);
|
|
77
73
|
|
|
78
74
|
_defineProperty(this, "name", void 0);
|
|
@@ -118,8 +114,9 @@ class InjectedConnector extends Connector {
|
|
|
118
114
|
return;
|
|
119
115
|
}
|
|
120
116
|
|
|
121
|
-
this.emit('disconnect');
|
|
122
|
-
|
|
117
|
+
this.emit('disconnect'); // Remove shim signalling wallet is disconnected
|
|
118
|
+
|
|
119
|
+
if ((_this$options2 = this.options) !== null && _this$options2 !== void 0 && _this$options2.shimDisconnect) (_getClient$storage = getClient().storage) === null || _getClient$storage === void 0 ? void 0 : _getClient$storage.removeItem(shimDisconnectKey);
|
|
123
120
|
});
|
|
124
121
|
|
|
125
122
|
let name = 'Injected';
|
|
@@ -163,9 +160,10 @@ class InjectedConnector extends Connector {
|
|
|
163
160
|
const chain = await this.switchChain(chainId);
|
|
164
161
|
id = chain.id;
|
|
165
162
|
unsupported = this.isChainUnsupported(id);
|
|
166
|
-
}
|
|
163
|
+
} // Add shim to storage signalling wallet is connected
|
|
167
164
|
|
|
168
|
-
|
|
165
|
+
|
|
166
|
+
if ((_this$options3 = this.options) !== null && _this$options3 !== void 0 && _this$options3.shimDisconnect) (_getClient$storage2 = getClient().storage) === null || _getClient$storage2 === void 0 ? void 0 : _getClient$storage2.setItem(shimDisconnectKey, true);
|
|
169
167
|
return {
|
|
170
168
|
account,
|
|
171
169
|
chain: {
|
|
@@ -175,7 +173,7 @@ class InjectedConnector extends Connector {
|
|
|
175
173
|
provider
|
|
176
174
|
};
|
|
177
175
|
} catch (error) {
|
|
178
|
-
if (
|
|
176
|
+
if (this.isUserRejectedRequestError(error)) throw new UserRejectedRequestError(error);
|
|
179
177
|
if (error.code === -32002) throw new ResourceUnavailableError(error);
|
|
180
178
|
throw error;
|
|
181
179
|
}
|
|
@@ -188,8 +186,9 @@ class InjectedConnector extends Connector {
|
|
|
188
186
|
if (!(provider !== null && provider !== void 0 && provider.removeListener)) return;
|
|
189
187
|
provider.removeListener('accountsChanged', this.onAccountsChanged);
|
|
190
188
|
provider.removeListener('chainChanged', this.onChainChanged);
|
|
191
|
-
provider.removeListener('disconnect', this.onDisconnect);
|
|
192
|
-
|
|
189
|
+
provider.removeListener('disconnect', this.onDisconnect); // Remove shim signalling wallet is disconnected
|
|
190
|
+
|
|
191
|
+
if ((_this$options4 = this.options) !== null && _this$options4 !== void 0 && _this$options4.shimDisconnect) (_getClient$storage3 = getClient().storage) === null || _getClient$storage3 === void 0 ? void 0 : _getClient$storage3.removeItem(shimDisconnectKey);
|
|
193
192
|
}
|
|
194
193
|
|
|
195
194
|
async getAccount() {
|
|
@@ -224,7 +223,8 @@ class InjectedConnector extends Connector {
|
|
|
224
223
|
try {
|
|
225
224
|
var _this$options5, _getClient$storage4;
|
|
226
225
|
|
|
227
|
-
if ((_this$options5 = this.options) !== null && _this$options5 !== void 0 && _this$options5.shimDisconnect &&
|
|
226
|
+
if ((_this$options5 = this.options) !== null && _this$options5 !== void 0 && _this$options5.shimDisconnect && // If shim does not exist in storage, wallet is disconnected
|
|
227
|
+
!((_getClient$storage4 = getClient().storage) !== null && _getClient$storage4 !== void 0 && _getClient$storage4.getItem(shimDisconnectKey))) return false;
|
|
228
228
|
const provider = await this.getProvider();
|
|
229
229
|
if (!provider) throw new ConnectorNotFoundError();
|
|
230
230
|
const accounts = await provider.request({
|
|
@@ -286,12 +286,12 @@ class InjectedConnector extends Connector {
|
|
|
286
286
|
});
|
|
287
287
|
return chain;
|
|
288
288
|
} catch (addError) {
|
|
289
|
-
if (
|
|
289
|
+
if (this.isUserRejectedRequestError(addError)) throw new UserRejectedRequestError(error);
|
|
290
290
|
throw new AddChainError();
|
|
291
291
|
}
|
|
292
292
|
}
|
|
293
293
|
|
|
294
|
-
if (
|
|
294
|
+
if (this.isUserRejectedRequestError(error)) throw new UserRejectedRequestError(error);
|
|
295
295
|
throw new SwitchChainError(error);
|
|
296
296
|
}
|
|
297
297
|
}
|
|
@@ -319,10 +319,10 @@ class InjectedConnector extends Connector {
|
|
|
319
319
|
});
|
|
320
320
|
}
|
|
321
321
|
|
|
322
|
-
|
|
322
|
+
isUserRejectedRequestError(error) {
|
|
323
|
+
return error.code === 4001;
|
|
324
|
+
}
|
|
323
325
|
|
|
324
|
-
function _isUserRejectedRequestError2(error) {
|
|
325
|
-
return error.code === 4001;
|
|
326
326
|
}
|
|
327
327
|
|
|
328
328
|
const noopStorage = {
|
|
@@ -644,4 +644,4 @@ function getClient() {
|
|
|
644
644
|
return client;
|
|
645
645
|
}
|
|
646
646
|
|
|
647
|
-
export { Client as C, InjectedConnector as I,
|
|
647
|
+
export { Client as C, InjectedConnector as I, createStorage as a, createClient as c, getClient as g, noopStorage as n, shimDisconnectKey as s };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var base = require('./base-
|
|
3
|
+
var base = require('./base-797ad073.cjs.prod.js');
|
|
4
4
|
var create = require('zustand/vanilla');
|
|
5
5
|
var middleware = require('zustand/middleware');
|
|
6
6
|
var ethers = require('ethers');
|
|
@@ -56,14 +56,12 @@ function getInjectedName(ethereum) {
|
|
|
56
56
|
return (_getName = getName(ethereum)) !== null && _getName !== void 0 ? _getName : 'Injected';
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
const
|
|
59
|
+
const shimDisconnectKey = 'injected.shimDisconnect';
|
|
60
60
|
|
|
61
61
|
var _provider = /*#__PURE__*/new WeakMap();
|
|
62
62
|
|
|
63
63
|
var _switchingChains = /*#__PURE__*/new WeakMap();
|
|
64
64
|
|
|
65
|
-
var _isUserRejectedRequestError = /*#__PURE__*/new WeakSet();
|
|
66
|
-
|
|
67
65
|
class InjectedConnector extends base.Connector {
|
|
68
66
|
constructor() {
|
|
69
67
|
let {
|
|
@@ -77,8 +75,6 @@ class InjectedConnector extends base.Connector {
|
|
|
77
75
|
options
|
|
78
76
|
});
|
|
79
77
|
|
|
80
|
-
base._classPrivateMethodInitSpec(this, _isUserRejectedRequestError);
|
|
81
|
-
|
|
82
78
|
base._defineProperty(this, "id", void 0);
|
|
83
79
|
|
|
84
80
|
base._defineProperty(this, "name", void 0);
|
|
@@ -124,8 +120,9 @@ class InjectedConnector extends base.Connector {
|
|
|
124
120
|
return;
|
|
125
121
|
}
|
|
126
122
|
|
|
127
|
-
this.emit('disconnect');
|
|
128
|
-
|
|
123
|
+
this.emit('disconnect'); // Remove shim signalling wallet is disconnected
|
|
124
|
+
|
|
125
|
+
if ((_this$options2 = this.options) !== null && _this$options2 !== void 0 && _this$options2.shimDisconnect) (_getClient$storage = getClient().storage) === null || _getClient$storage === void 0 ? void 0 : _getClient$storage.removeItem(shimDisconnectKey);
|
|
129
126
|
});
|
|
130
127
|
|
|
131
128
|
let name = 'Injected';
|
|
@@ -169,9 +166,10 @@ class InjectedConnector extends base.Connector {
|
|
|
169
166
|
const chain = await this.switchChain(chainId);
|
|
170
167
|
id = chain.id;
|
|
171
168
|
unsupported = this.isChainUnsupported(id);
|
|
172
|
-
}
|
|
169
|
+
} // Add shim to storage signalling wallet is connected
|
|
173
170
|
|
|
174
|
-
|
|
171
|
+
|
|
172
|
+
if ((_this$options3 = this.options) !== null && _this$options3 !== void 0 && _this$options3.shimDisconnect) (_getClient$storage2 = getClient().storage) === null || _getClient$storage2 === void 0 ? void 0 : _getClient$storage2.setItem(shimDisconnectKey, true);
|
|
175
173
|
return {
|
|
176
174
|
account,
|
|
177
175
|
chain: {
|
|
@@ -181,7 +179,7 @@ class InjectedConnector extends base.Connector {
|
|
|
181
179
|
provider
|
|
182
180
|
};
|
|
183
181
|
} catch (error) {
|
|
184
|
-
if (
|
|
182
|
+
if (this.isUserRejectedRequestError(error)) throw new base.UserRejectedRequestError(error);
|
|
185
183
|
if (error.code === -32002) throw new base.ResourceUnavailableError(error);
|
|
186
184
|
throw error;
|
|
187
185
|
}
|
|
@@ -194,8 +192,9 @@ class InjectedConnector extends base.Connector {
|
|
|
194
192
|
if (!(provider !== null && provider !== void 0 && provider.removeListener)) return;
|
|
195
193
|
provider.removeListener('accountsChanged', this.onAccountsChanged);
|
|
196
194
|
provider.removeListener('chainChanged', this.onChainChanged);
|
|
197
|
-
provider.removeListener('disconnect', this.onDisconnect);
|
|
198
|
-
|
|
195
|
+
provider.removeListener('disconnect', this.onDisconnect); // Remove shim signalling wallet is disconnected
|
|
196
|
+
|
|
197
|
+
if ((_this$options4 = this.options) !== null && _this$options4 !== void 0 && _this$options4.shimDisconnect) (_getClient$storage3 = getClient().storage) === null || _getClient$storage3 === void 0 ? void 0 : _getClient$storage3.removeItem(shimDisconnectKey);
|
|
199
198
|
}
|
|
200
199
|
|
|
201
200
|
async getAccount() {
|
|
@@ -230,7 +229,8 @@ class InjectedConnector extends base.Connector {
|
|
|
230
229
|
try {
|
|
231
230
|
var _this$options5, _getClient$storage4;
|
|
232
231
|
|
|
233
|
-
if ((_this$options5 = this.options) !== null && _this$options5 !== void 0 && _this$options5.shimDisconnect &&
|
|
232
|
+
if ((_this$options5 = this.options) !== null && _this$options5 !== void 0 && _this$options5.shimDisconnect && // If shim does not exist in storage, wallet is disconnected
|
|
233
|
+
!((_getClient$storage4 = getClient().storage) !== null && _getClient$storage4 !== void 0 && _getClient$storage4.getItem(shimDisconnectKey))) return false;
|
|
234
234
|
const provider = await this.getProvider();
|
|
235
235
|
if (!provider) throw new base.ConnectorNotFoundError();
|
|
236
236
|
const accounts = await provider.request({
|
|
@@ -292,12 +292,12 @@ class InjectedConnector extends base.Connector {
|
|
|
292
292
|
});
|
|
293
293
|
return chain;
|
|
294
294
|
} catch (addError) {
|
|
295
|
-
if (
|
|
295
|
+
if (this.isUserRejectedRequestError(addError)) throw new base.UserRejectedRequestError(error);
|
|
296
296
|
throw new base.AddChainError();
|
|
297
297
|
}
|
|
298
298
|
}
|
|
299
299
|
|
|
300
|
-
if (
|
|
300
|
+
if (this.isUserRejectedRequestError(error)) throw new base.UserRejectedRequestError(error);
|
|
301
301
|
throw new base.SwitchChainError(error);
|
|
302
302
|
}
|
|
303
303
|
}
|
|
@@ -325,10 +325,10 @@ class InjectedConnector extends base.Connector {
|
|
|
325
325
|
});
|
|
326
326
|
}
|
|
327
327
|
|
|
328
|
-
|
|
328
|
+
isUserRejectedRequestError(error) {
|
|
329
|
+
return error.code === 4001;
|
|
330
|
+
}
|
|
329
331
|
|
|
330
|
-
function _isUserRejectedRequestError2(error) {
|
|
331
|
-
return error.code === 4001;
|
|
332
332
|
}
|
|
333
333
|
|
|
334
334
|
const noopStorage = {
|
|
@@ -636,18 +636,18 @@ function _addEffects2() {
|
|
|
636
636
|
});
|
|
637
637
|
}
|
|
638
638
|
|
|
639
|
-
|
|
639
|
+
let client;
|
|
640
640
|
function createClient(config) {
|
|
641
641
|
const client_ = new Client(config);
|
|
642
|
-
|
|
642
|
+
client = client_;
|
|
643
643
|
return client_;
|
|
644
644
|
}
|
|
645
645
|
function getClient() {
|
|
646
|
-
if (!
|
|
646
|
+
if (!client) {
|
|
647
647
|
throw new Error('No wagmi client found. Ensure you have set up a client: https://wagmi.sh/docs/client');
|
|
648
648
|
}
|
|
649
649
|
|
|
650
|
-
return
|
|
650
|
+
return client;
|
|
651
651
|
}
|
|
652
652
|
|
|
653
653
|
exports.Client = Client;
|
|
@@ -656,3 +656,4 @@ exports.createClient = createClient;
|
|
|
656
656
|
exports.createStorage = createStorage;
|
|
657
657
|
exports.getClient = getClient;
|
|
658
658
|
exports.noopStorage = noopStorage;
|
|
659
|
+
exports.shimDisconnectKey = shimDisconnectKey;
|
|
@@ -18,6 +18,7 @@ export declare type InjectedConnectorOptions = {
|
|
|
18
18
|
*/
|
|
19
19
|
shimDisconnect?: boolean;
|
|
20
20
|
};
|
|
21
|
+
export declare const shimDisconnectKey = "injected.shimDisconnect";
|
|
21
22
|
export declare class InjectedConnector extends Connector<Window['ethereum'], InjectedConnectorOptions | undefined> {
|
|
22
23
|
#private;
|
|
23
24
|
readonly id: string;
|
|
@@ -53,4 +54,5 @@ export declare class InjectedConnector extends Connector<Window['ethereum'], Inj
|
|
|
53
54
|
protected onAccountsChanged: (accounts: string[]) => void;
|
|
54
55
|
protected onChainChanged: (chainId: number | string) => void;
|
|
55
56
|
protected onDisconnect: () => void;
|
|
57
|
+
protected isUserRejectedRequestError(error: unknown): boolean;
|
|
56
58
|
}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { Chain } from '../types';
|
|
2
2
|
import { InjectedConnector, InjectedConnectorOptions } from './injected';
|
|
3
|
-
export declare type MetaMaskConnectorOptions = Pick<InjectedConnectorOptions, 'shimChainChangedDisconnect' | 'shimDisconnect'
|
|
3
|
+
export declare type MetaMaskConnectorOptions = Pick<InjectedConnectorOptions, 'shimChainChangedDisconnect' | 'shimDisconnect'> & {
|
|
4
|
+
/**
|
|
5
|
+
* While "disconnected" with `shimDisconnect`, allows user to select a different MetaMask account (than the currently connected account) when trying to connect.
|
|
6
|
+
*/
|
|
7
|
+
UNSTABLE_shimOnConnectSelectAccount?: boolean;
|
|
8
|
+
};
|
|
4
9
|
export declare class MetaMaskConnector extends InjectedConnector {
|
|
5
10
|
#private;
|
|
6
11
|
readonly id = "metaMask";
|
|
@@ -9,5 +14,15 @@ export declare class MetaMaskConnector extends InjectedConnector {
|
|
|
9
14
|
chains?: Chain[];
|
|
10
15
|
options?: MetaMaskConnectorOptions;
|
|
11
16
|
});
|
|
17
|
+
connect({ chainId }?: {
|
|
18
|
+
chainId?: number;
|
|
19
|
+
}): Promise<{
|
|
20
|
+
account: string;
|
|
21
|
+
chain: {
|
|
22
|
+
id: number;
|
|
23
|
+
unsupported: boolean;
|
|
24
|
+
};
|
|
25
|
+
provider: Ethereum;
|
|
26
|
+
}>;
|
|
12
27
|
getProvider(): Promise<Ethereum | undefined>;
|
|
13
28
|
}
|
|
@@ -25,8 +25,9 @@ export declare class WalletConnectConnector extends Connector<WalletConnectProvi
|
|
|
25
25
|
disconnect(): Promise<void>;
|
|
26
26
|
getAccount(): Promise<string>;
|
|
27
27
|
getChainId(): Promise<number>;
|
|
28
|
-
getProvider({ chainId }?: {
|
|
28
|
+
getProvider({ chainId, create, }?: {
|
|
29
29
|
chainId?: number;
|
|
30
|
+
create?: boolean;
|
|
30
31
|
}): Promise<WalletConnectProvider>;
|
|
31
32
|
getSigner({ chainId }?: {
|
|
32
33
|
chainId?: number;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Connector } from './connectors';
|
|
2
|
+
import { BlockExplorer } from './constants';
|
|
2
3
|
import { Chain } from './types';
|
|
3
4
|
/**
|
|
4
5
|
* Error subclass implementing JSON RPC 2.0 errors and Ethereum RPC errors per EIP-1474.
|
|
@@ -70,6 +71,14 @@ export declare class ConnectorNotFoundError extends Error {
|
|
|
70
71
|
name: string;
|
|
71
72
|
message: string;
|
|
72
73
|
}
|
|
74
|
+
export declare class ContractMethodNoResultError extends Error {
|
|
75
|
+
name: string;
|
|
76
|
+
constructor({ addressOrName, blockExplorer, functionName, }: {
|
|
77
|
+
addressOrName: string;
|
|
78
|
+
blockExplorer?: BlockExplorer;
|
|
79
|
+
functionName: string;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
73
82
|
export declare class ProviderChainsNotFound extends Error {
|
|
74
83
|
name: string;
|
|
75
84
|
message: string;
|
|
@@ -5,7 +5,7 @@ export type { ClientConfig } from './client';
|
|
|
5
5
|
export { Connector, InjectedConnector } from './connectors';
|
|
6
6
|
export type { ConnectorData, ConnectorEvents } from './connectors';
|
|
7
7
|
export { alchemyRpcUrls, allChains, chain, chainId, defaultChains, defaultL2Chains, erc20ABI, erc721ABI, etherscanBlockExplorers, infuraRpcUrls, publicRpcUrls, units, } from './constants';
|
|
8
|
-
export { AddChainError, ChainDoesNotSupportMulticallError, ChainMismatchError, ChainNotConfiguredError, ConnectorAlreadyConnectedError, ConnectorNotFoundError, ProviderChainsNotFound, ProviderRpcError, ResourceUnavailableError, RpcError, SwitchChainError, SwitchChainNotSupportedError, UserRejectedRequestError, } from './errors';
|
|
8
|
+
export { AddChainError, ChainDoesNotSupportMulticallError, ChainMismatchError, ChainNotConfiguredError, ConnectorAlreadyConnectedError, ConnectorNotFoundError, ContractMethodNoResultError, ProviderChainsNotFound, ProviderRpcError, ResourceUnavailableError, RpcError, SwitchChainError, SwitchChainNotSupportedError, UserRejectedRequestError, } from './errors';
|
|
9
9
|
export { createStorage, noopStorage } from './storage';
|
|
10
10
|
export type { ClientStorage as Storage } from './storage';
|
|
11
11
|
export type { Chain, ChainProviderFn, FallbackProviderConfig, ProviderWithFallbackConfig, Provider, Unit, WebSocketProvider, } from './types';
|
|
@@ -65,6 +65,17 @@ declare global {
|
|
|
65
65
|
/** Currently ignored. */
|
|
66
66
|
iconUrls?: string[];
|
|
67
67
|
};
|
|
68
|
+
type WalletPermissionCaveat = {
|
|
69
|
+
type: string;
|
|
70
|
+
value: any;
|
|
71
|
+
};
|
|
72
|
+
type WalletPermission = {
|
|
73
|
+
caveats: WalletPermissionCaveat[];
|
|
74
|
+
date: number;
|
|
75
|
+
id: string;
|
|
76
|
+
invoker: `http://${string}` | `https://${string}`;
|
|
77
|
+
parentCapability: 'eth_accounts' | string;
|
|
78
|
+
};
|
|
68
79
|
type WatchAssetParams = {
|
|
69
80
|
/** In the future, other standards will be supported */
|
|
70
81
|
type: 'ERC20';
|
|
@@ -138,6 +149,19 @@ declare global {
|
|
|
138
149
|
request(args: {
|
|
139
150
|
method: 'web3_clientVersion';
|
|
140
151
|
}): Promise<string>;
|
|
152
|
+
/**
|
|
153
|
+
* EIP-2255: Wallet Permissions System
|
|
154
|
+
* https://eips.ethereum.org/EIPS/eip-2255
|
|
155
|
+
*/
|
|
156
|
+
request(args: {
|
|
157
|
+
method: 'wallet_requestPermissions';
|
|
158
|
+
params: [{
|
|
159
|
+
eth_accounts: Record<string, any>;
|
|
160
|
+
}];
|
|
161
|
+
}): Promise<WalletPermission[]>;
|
|
162
|
+
request(args: {
|
|
163
|
+
method: 'wallet_getPermissions';
|
|
164
|
+
}): Promise<WalletPermission[]>;
|
|
141
165
|
/**
|
|
142
166
|
* EIP-3085: Wallet Add Ethereum Chain RPC Method
|
|
143
167
|
* https://eips.ethereum.org/EIPS/eip-3085
|