@wagmi/connectors 0.2.2 → 0.2.3-cjs
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-5NCTPR6C.js +14 -14
- package/dist/chunk-LNIFBRWC.js +71 -71
- package/dist/coinbaseWallet.js +59 -59
- package/dist/index.js +6 -6
- package/dist/injected.js +7 -7
- package/dist/ledger.js +45 -45
- package/dist/metaMask.js +33 -33
- package/dist/mock/index.js +62 -62
- package/dist/walletConnect.js +93 -88
- package/package.json +2 -3
package/dist/chunk-5NCTPR6C.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }var __defProp = Object.defineProperty;
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
3
|
var __publicField = (obj, key, value) => {
|
|
4
4
|
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
@@ -28,11 +28,11 @@ var __privateMethod = (obj, member, method) => {
|
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
// src/base.ts
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
var Connector = class extends
|
|
31
|
+
var _chains = require('@wagmi/core/chains');
|
|
32
|
+
var _eventemitter3 = require('eventemitter3'); var _eventemitter32 = _interopRequireDefault(_eventemitter3);
|
|
33
|
+
var Connector = class extends _eventemitter32.default {
|
|
34
34
|
constructor({
|
|
35
|
-
chains = [mainnet, goerli],
|
|
35
|
+
chains = [_chains.mainnet, _chains.goerli],
|
|
36
36
|
options
|
|
37
37
|
}) {
|
|
38
38
|
super();
|
|
@@ -42,7 +42,7 @@ var Connector = class extends EventEmitter {
|
|
|
42
42
|
this.options = options;
|
|
43
43
|
}
|
|
44
44
|
getBlockExplorerUrls(chain) {
|
|
45
|
-
const { default: blockExplorer, ...blockExplorers } = chain.blockExplorers
|
|
45
|
+
const { default: blockExplorer, ...blockExplorers } = _nullishCoalesce(chain.blockExplorers, () => ( {}));
|
|
46
46
|
if (blockExplorer)
|
|
47
47
|
return [
|
|
48
48
|
blockExplorer.url,
|
|
@@ -54,11 +54,11 @@ var Connector = class extends EventEmitter {
|
|
|
54
54
|
}
|
|
55
55
|
};
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
exports.__publicField = __publicField; exports.__privateGet = __privateGet; exports.__privateAdd = __privateAdd; exports.__privateSet = __privateSet; exports.__privateMethod = __privateMethod; exports.Connector = Connector;
|
package/dist/chunk-LNIFBRWC.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
var _chunk5NCTPR6Cjs = require('./chunk-5NCTPR6C.js');
|
|
8
8
|
|
|
9
9
|
// src/injected.ts
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
var _core = require('@wagmi/core');
|
|
20
|
+
var _ethers = require('ethers');
|
|
21
|
+
var _utilsjs = require('ethers/lib/utils.js');
|
|
22
22
|
|
|
23
23
|
// src/utils/getInjectedName.ts
|
|
24
24
|
function getInjectedName(ethereum) {
|
|
@@ -60,7 +60,7 @@ function getInjectedName(ethereum) {
|
|
|
60
60
|
if (provider.isMetaMask)
|
|
61
61
|
return "MetaMask";
|
|
62
62
|
};
|
|
63
|
-
if (ethereum.providers
|
|
63
|
+
if (_optionalChain([ethereum, 'access', _ => _.providers, 'optionalAccess', _2 => _2.length])) {
|
|
64
64
|
const nameSet = /* @__PURE__ */ new Set();
|
|
65
65
|
let unknownCount = 1;
|
|
66
66
|
for (const provider of ethereum.providers) {
|
|
@@ -74,14 +74,14 @@ function getInjectedName(ethereum) {
|
|
|
74
74
|
const names = [...nameSet];
|
|
75
75
|
if (names.length)
|
|
76
76
|
return names;
|
|
77
|
-
return names[0]
|
|
77
|
+
return _nullishCoalesce(names[0], () => ( "Injected"));
|
|
78
78
|
}
|
|
79
|
-
return getName(ethereum)
|
|
79
|
+
return _nullishCoalesce(getName(ethereum), () => ( "Injected"));
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
// src/injected.ts
|
|
83
83
|
var _provider, _switchingChains;
|
|
84
|
-
var InjectedConnector = class extends Connector {
|
|
84
|
+
var InjectedConnector = class extends _chunk5NCTPR6Cjs.Connector {
|
|
85
85
|
constructor({
|
|
86
86
|
chains,
|
|
87
87
|
options: options_
|
|
@@ -93,33 +93,33 @@ var InjectedConnector = class extends Connector {
|
|
|
93
93
|
...options_
|
|
94
94
|
};
|
|
95
95
|
super({ chains, options });
|
|
96
|
-
__publicField(this, "id");
|
|
97
|
-
__publicField(this, "name");
|
|
98
|
-
__publicField(this, "ready");
|
|
99
|
-
__privateAdd(this, _provider, void 0);
|
|
100
|
-
__privateAdd(this, _switchingChains, void 0);
|
|
101
|
-
__publicField(this, "shimDisconnectKey", "injected.shimDisconnect");
|
|
102
|
-
__publicField(this, "onAccountsChanged", (accounts) => {
|
|
96
|
+
_chunk5NCTPR6Cjs.__publicField.call(void 0, this, "id");
|
|
97
|
+
_chunk5NCTPR6Cjs.__publicField.call(void 0, this, "name");
|
|
98
|
+
_chunk5NCTPR6Cjs.__publicField.call(void 0, this, "ready");
|
|
99
|
+
_chunk5NCTPR6Cjs.__privateAdd.call(void 0, this, _provider, void 0);
|
|
100
|
+
_chunk5NCTPR6Cjs.__privateAdd.call(void 0, this, _switchingChains, void 0);
|
|
101
|
+
_chunk5NCTPR6Cjs.__publicField.call(void 0, this, "shimDisconnectKey", "injected.shimDisconnect");
|
|
102
|
+
_chunk5NCTPR6Cjs.__publicField.call(void 0, this, "onAccountsChanged", (accounts) => {
|
|
103
103
|
if (accounts.length === 0)
|
|
104
104
|
this.emit("disconnect");
|
|
105
105
|
else
|
|
106
106
|
this.emit("change", {
|
|
107
|
-
account: getAddress(accounts[0])
|
|
107
|
+
account: _utilsjs.getAddress.call(void 0, accounts[0])
|
|
108
108
|
});
|
|
109
109
|
});
|
|
110
|
-
__publicField(this, "onChainChanged", (chainId) => {
|
|
111
|
-
const id = normalizeChainId(chainId);
|
|
110
|
+
_chunk5NCTPR6Cjs.__publicField.call(void 0, this, "onChainChanged", (chainId) => {
|
|
111
|
+
const id = _core.normalizeChainId.call(void 0, chainId);
|
|
112
112
|
const unsupported = this.isChainUnsupported(id);
|
|
113
113
|
this.emit("change", { chain: { id, unsupported } });
|
|
114
114
|
});
|
|
115
|
-
__publicField(this, "onDisconnect", () => {
|
|
116
|
-
if (this.options.shimChainChangedDisconnect && __privateGet(this, _switchingChains)) {
|
|
117
|
-
__privateSet(this, _switchingChains, false);
|
|
115
|
+
_chunk5NCTPR6Cjs.__publicField.call(void 0, this, "onDisconnect", () => {
|
|
116
|
+
if (this.options.shimChainChangedDisconnect && _chunk5NCTPR6Cjs.__privateGet.call(void 0, this, _switchingChains)) {
|
|
117
|
+
_chunk5NCTPR6Cjs.__privateSet.call(void 0, this, _switchingChains, false);
|
|
118
118
|
return;
|
|
119
119
|
}
|
|
120
120
|
this.emit("disconnect");
|
|
121
121
|
if (this.options.shimDisconnect)
|
|
122
|
-
getClient().storage
|
|
122
|
+
_optionalChain([_core.getClient.call(void 0, ), 'access', _3 => _3.storage, 'optionalAccess', _4 => _4.removeItem, 'call', _5 => _5(this.shimDisconnectKey)]);
|
|
123
123
|
});
|
|
124
124
|
const provider = options.getProvider();
|
|
125
125
|
if (typeof options.name === "string")
|
|
@@ -143,7 +143,7 @@ var InjectedConnector = class extends Connector {
|
|
|
143
143
|
try {
|
|
144
144
|
const provider = await this.getProvider();
|
|
145
145
|
if (!provider)
|
|
146
|
-
throw new ConnectorNotFoundError();
|
|
146
|
+
throw new (0, _core.ConnectorNotFoundError)();
|
|
147
147
|
if (provider.on) {
|
|
148
148
|
provider.on("accountsChanged", this.onAccountsChanged);
|
|
149
149
|
provider.on("chainChanged", this.onChainChanged);
|
|
@@ -153,7 +153,7 @@ var InjectedConnector = class extends Connector {
|
|
|
153
153
|
const accounts = await provider.request({
|
|
154
154
|
method: "eth_requestAccounts"
|
|
155
155
|
});
|
|
156
|
-
const account = getAddress(accounts[0]);
|
|
156
|
+
const account = _utilsjs.getAddress.call(void 0, accounts[0]);
|
|
157
157
|
let id = await this.getChainId();
|
|
158
158
|
let unsupported = this.isChainUnsupported(id);
|
|
159
159
|
if (chainId && id !== chainId) {
|
|
@@ -162,77 +162,77 @@ var InjectedConnector = class extends Connector {
|
|
|
162
162
|
unsupported = this.isChainUnsupported(id);
|
|
163
163
|
}
|
|
164
164
|
if (this.options.shimDisconnect)
|
|
165
|
-
getClient().storage
|
|
165
|
+
_optionalChain([_core.getClient.call(void 0, ), 'access', _6 => _6.storage, 'optionalAccess', _7 => _7.setItem, 'call', _8 => _8(this.shimDisconnectKey, true)]);
|
|
166
166
|
return { account, chain: { id, unsupported }, provider };
|
|
167
167
|
} catch (error) {
|
|
168
168
|
if (this.isUserRejectedRequestError(error))
|
|
169
|
-
throw new UserRejectedRequestError(error);
|
|
169
|
+
throw new (0, _core.UserRejectedRequestError)(error);
|
|
170
170
|
if (error.code === -32002)
|
|
171
|
-
throw new ResourceUnavailableError(error);
|
|
171
|
+
throw new (0, _core.ResourceUnavailableError)(error);
|
|
172
172
|
throw error;
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
175
|
async disconnect() {
|
|
176
176
|
const provider = await this.getProvider();
|
|
177
|
-
if (!provider
|
|
177
|
+
if (!_optionalChain([provider, 'optionalAccess', _9 => _9.removeListener]))
|
|
178
178
|
return;
|
|
179
179
|
provider.removeListener("accountsChanged", this.onAccountsChanged);
|
|
180
180
|
provider.removeListener("chainChanged", this.onChainChanged);
|
|
181
181
|
provider.removeListener("disconnect", this.onDisconnect);
|
|
182
182
|
if (this.options.shimDisconnect)
|
|
183
|
-
getClient().storage
|
|
183
|
+
_optionalChain([_core.getClient.call(void 0, ), 'access', _10 => _10.storage, 'optionalAccess', _11 => _11.removeItem, 'call', _12 => _12(this.shimDisconnectKey)]);
|
|
184
184
|
}
|
|
185
185
|
async getAccount() {
|
|
186
186
|
const provider = await this.getProvider();
|
|
187
187
|
if (!provider)
|
|
188
|
-
throw new ConnectorNotFoundError();
|
|
188
|
+
throw new (0, _core.ConnectorNotFoundError)();
|
|
189
189
|
const accounts = await provider.request({
|
|
190
190
|
method: "eth_accounts"
|
|
191
191
|
});
|
|
192
|
-
return getAddress(accounts[0]);
|
|
192
|
+
return _utilsjs.getAddress.call(void 0, accounts[0]);
|
|
193
193
|
}
|
|
194
194
|
async getChainId() {
|
|
195
195
|
const provider = await this.getProvider();
|
|
196
196
|
if (!provider)
|
|
197
|
-
throw new ConnectorNotFoundError();
|
|
198
|
-
return provider.request({ method: "eth_chainId" }).then(normalizeChainId);
|
|
197
|
+
throw new (0, _core.ConnectorNotFoundError)();
|
|
198
|
+
return provider.request({ method: "eth_chainId" }).then(_core.normalizeChainId);
|
|
199
199
|
}
|
|
200
200
|
async getProvider() {
|
|
201
201
|
const provider = this.options.getProvider();
|
|
202
202
|
if (provider)
|
|
203
|
-
__privateSet(this, _provider, provider);
|
|
204
|
-
return __privateGet(this, _provider);
|
|
203
|
+
_chunk5NCTPR6Cjs.__privateSet.call(void 0, this, _provider, provider);
|
|
204
|
+
return _chunk5NCTPR6Cjs.__privateGet.call(void 0, this, _provider);
|
|
205
205
|
}
|
|
206
206
|
async getSigner({ chainId } = {}) {
|
|
207
207
|
const [provider, account] = await Promise.all([
|
|
208
208
|
this.getProvider(),
|
|
209
209
|
this.getAccount()
|
|
210
210
|
]);
|
|
211
|
-
return new providers.Web3Provider(
|
|
211
|
+
return new _ethers.providers.Web3Provider(
|
|
212
212
|
provider,
|
|
213
213
|
chainId
|
|
214
214
|
).getSigner(account);
|
|
215
215
|
}
|
|
216
216
|
async isAuthorized() {
|
|
217
217
|
try {
|
|
218
|
-
if (this.options.shimDisconnect && !getClient().storage
|
|
218
|
+
if (this.options.shimDisconnect && !_optionalChain([_core.getClient.call(void 0, ), 'access', _13 => _13.storage, 'optionalAccess', _14 => _14.getItem, 'call', _15 => _15(this.shimDisconnectKey)]))
|
|
219
219
|
return false;
|
|
220
220
|
const provider = await this.getProvider();
|
|
221
221
|
if (!provider)
|
|
222
|
-
throw new ConnectorNotFoundError();
|
|
222
|
+
throw new (0, _core.ConnectorNotFoundError)();
|
|
223
223
|
const account = await this.getAccount();
|
|
224
224
|
return !!account;
|
|
225
|
-
} catch {
|
|
225
|
+
} catch (e) {
|
|
226
226
|
return false;
|
|
227
227
|
}
|
|
228
228
|
}
|
|
229
229
|
async switchChain(chainId) {
|
|
230
230
|
if (this.options.shimChainChangedDisconnect)
|
|
231
|
-
__privateSet(this, _switchingChains, true);
|
|
231
|
+
_chunk5NCTPR6Cjs.__privateSet.call(void 0, this, _switchingChains, true);
|
|
232
232
|
const provider = await this.getProvider();
|
|
233
233
|
if (!provider)
|
|
234
|
-
throw new ConnectorNotFoundError();
|
|
235
|
-
const id = hexValue(chainId);
|
|
234
|
+
throw new (0, _core.ConnectorNotFoundError)();
|
|
235
|
+
const id = _utilsjs.hexValue.call(void 0, chainId);
|
|
236
236
|
try {
|
|
237
237
|
await Promise.all([
|
|
238
238
|
provider.request({
|
|
@@ -241,23 +241,23 @@ var InjectedConnector = class extends Connector {
|
|
|
241
241
|
}),
|
|
242
242
|
new Promise(
|
|
243
243
|
(res) => this.on("change", ({ chain }) => {
|
|
244
|
-
if (chain
|
|
244
|
+
if (_optionalChain([chain, 'optionalAccess', _16 => _16.id]) === chainId)
|
|
245
245
|
res();
|
|
246
246
|
})
|
|
247
247
|
)
|
|
248
248
|
]);
|
|
249
|
-
return this.chains.find((x) => x.id === chainId)
|
|
249
|
+
return _nullishCoalesce(this.chains.find((x) => x.id === chainId), () => ( {
|
|
250
250
|
id: chainId,
|
|
251
251
|
name: `Chain ${id}`,
|
|
252
252
|
network: `${id}`,
|
|
253
253
|
nativeCurrency: { name: "Ether", decimals: 18, symbol: "ETH" },
|
|
254
254
|
rpcUrls: { default: { http: [""] }, public: { http: [""] } }
|
|
255
|
-
};
|
|
255
|
+
}));
|
|
256
256
|
} catch (error) {
|
|
257
257
|
const chain = this.chains.find((x) => x.id === chainId);
|
|
258
258
|
if (!chain)
|
|
259
|
-
throw new ChainNotConfiguredError({ chainId, connectorId: this.id });
|
|
260
|
-
if (error.code === 4902 || error
|
|
259
|
+
throw new (0, _core.ChainNotConfiguredError)({ chainId, connectorId: this.id });
|
|
260
|
+
if (error.code === 4902 || _optionalChain([error, 'optionalAccess', _17 => _17.data, 'optionalAccess', _18 => _18.originalError, 'optionalAccess', _19 => _19.code]) === 4902) {
|
|
261
261
|
try {
|
|
262
262
|
await provider.request({
|
|
263
263
|
method: "wallet_addEthereumChain",
|
|
@@ -266,7 +266,7 @@ var InjectedConnector = class extends Connector {
|
|
|
266
266
|
chainId: id,
|
|
267
267
|
chainName: chain.name,
|
|
268
268
|
nativeCurrency: chain.nativeCurrency,
|
|
269
|
-
rpcUrls: [chain.rpcUrls.public
|
|
269
|
+
rpcUrls: [_nullishCoalesce(_optionalChain([chain, 'access', _20 => _20.rpcUrls, 'access', _21 => _21.public, 'optionalAccess', _22 => _22.http, 'access', _23 => _23[0]]), () => ( ""))],
|
|
270
270
|
blockExplorerUrls: this.getBlockExplorerUrls(chain)
|
|
271
271
|
}
|
|
272
272
|
]
|
|
@@ -274,13 +274,13 @@ var InjectedConnector = class extends Connector {
|
|
|
274
274
|
return chain;
|
|
275
275
|
} catch (addError) {
|
|
276
276
|
if (this.isUserRejectedRequestError(addError))
|
|
277
|
-
throw new UserRejectedRequestError(error);
|
|
278
|
-
throw new AddChainError();
|
|
277
|
+
throw new (0, _core.UserRejectedRequestError)(error);
|
|
278
|
+
throw new (0, _core.AddChainError)();
|
|
279
279
|
}
|
|
280
280
|
}
|
|
281
281
|
if (this.isUserRejectedRequestError(error))
|
|
282
|
-
throw new UserRejectedRequestError(error);
|
|
283
|
-
throw new SwitchChainError(error);
|
|
282
|
+
throw new (0, _core.UserRejectedRequestError)(error);
|
|
283
|
+
throw new (0, _core.SwitchChainError)(error);
|
|
284
284
|
}
|
|
285
285
|
}
|
|
286
286
|
async watchAsset({
|
|
@@ -291,7 +291,7 @@ var InjectedConnector = class extends Connector {
|
|
|
291
291
|
}) {
|
|
292
292
|
const provider = await this.getProvider();
|
|
293
293
|
if (!provider)
|
|
294
|
-
throw new ConnectorNotFoundError();
|
|
294
|
+
throw new (0, _core.ConnectorNotFoundError)();
|
|
295
295
|
return provider.request({
|
|
296
296
|
method: "wallet_watchAsset",
|
|
297
297
|
params: {
|
|
@@ -312,6 +312,6 @@ var InjectedConnector = class extends Connector {
|
|
|
312
312
|
_provider = new WeakMap();
|
|
313
313
|
_switchingChains = new WeakMap();
|
|
314
314
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
exports.InjectedConnector = InjectedConnector;
|
package/dist/coinbaseWallet.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
var _chunk5NCTPR6Cjs = require('./chunk-5NCTPR6C.js');
|
|
9
9
|
|
|
10
10
|
// src/coinbaseWallet.ts
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
var _core = require('@wagmi/core');
|
|
18
|
+
var _ethers = require('ethers');
|
|
19
|
+
var _utilsjs = require('ethers/lib/utils.js');
|
|
20
20
|
var _client, _provider, _isUserRejectedRequestError, isUserRejectedRequestError_fn;
|
|
21
|
-
var CoinbaseWalletConnector = class extends Connector {
|
|
21
|
+
var CoinbaseWalletConnector = class extends _chunk5NCTPR6Cjs.Connector {
|
|
22
22
|
constructor({ chains, options }) {
|
|
23
23
|
super({
|
|
24
24
|
chains,
|
|
@@ -27,24 +27,24 @@ var CoinbaseWalletConnector = class extends Connector {
|
|
|
27
27
|
...options
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
|
-
__privateAdd(this, _isUserRejectedRequestError);
|
|
31
|
-
__publicField(this, "id", "coinbaseWallet");
|
|
32
|
-
__publicField(this, "name", "Coinbase Wallet");
|
|
33
|
-
__publicField(this, "ready", true);
|
|
34
|
-
__privateAdd(this, _client, void 0);
|
|
35
|
-
__privateAdd(this, _provider, void 0);
|
|
36
|
-
__publicField(this, "onAccountsChanged", (accounts) => {
|
|
30
|
+
_chunk5NCTPR6Cjs.__privateAdd.call(void 0, this, _isUserRejectedRequestError);
|
|
31
|
+
_chunk5NCTPR6Cjs.__publicField.call(void 0, this, "id", "coinbaseWallet");
|
|
32
|
+
_chunk5NCTPR6Cjs.__publicField.call(void 0, this, "name", "Coinbase Wallet");
|
|
33
|
+
_chunk5NCTPR6Cjs.__publicField.call(void 0, this, "ready", true);
|
|
34
|
+
_chunk5NCTPR6Cjs.__privateAdd.call(void 0, this, _client, void 0);
|
|
35
|
+
_chunk5NCTPR6Cjs.__privateAdd.call(void 0, this, _provider, void 0);
|
|
36
|
+
_chunk5NCTPR6Cjs.__publicField.call(void 0, this, "onAccountsChanged", (accounts) => {
|
|
37
37
|
if (accounts.length === 0)
|
|
38
38
|
this.emit("disconnect");
|
|
39
39
|
else
|
|
40
|
-
this.emit("change", { account: getAddress(accounts[0]) });
|
|
40
|
+
this.emit("change", { account: _utilsjs.getAddress.call(void 0, accounts[0]) });
|
|
41
41
|
});
|
|
42
|
-
__publicField(this, "onChainChanged", (chainId) => {
|
|
43
|
-
const id = normalizeChainId(chainId);
|
|
42
|
+
_chunk5NCTPR6Cjs.__publicField.call(void 0, this, "onChainChanged", (chainId) => {
|
|
43
|
+
const id = _core.normalizeChainId.call(void 0, chainId);
|
|
44
44
|
const unsupported = this.isChainUnsupported(id);
|
|
45
45
|
this.emit("change", { chain: { id, unsupported } });
|
|
46
46
|
});
|
|
47
|
-
__publicField(this, "onDisconnect", () => {
|
|
47
|
+
_chunk5NCTPR6Cjs.__publicField.call(void 0, this, "onDisconnect", () => {
|
|
48
48
|
this.emit("disconnect");
|
|
49
49
|
});
|
|
50
50
|
}
|
|
@@ -56,7 +56,7 @@ var CoinbaseWalletConnector = class extends Connector {
|
|
|
56
56
|
provider.on("disconnect", this.onDisconnect);
|
|
57
57
|
this.emit("message", { type: "connecting" });
|
|
58
58
|
const accounts = await provider.enable();
|
|
59
|
-
const account = getAddress(accounts[0]);
|
|
59
|
+
const account = _utilsjs.getAddress.call(void 0, accounts[0]);
|
|
60
60
|
let id = await this.getChainId();
|
|
61
61
|
let unsupported = this.isChainUnsupported(id);
|
|
62
62
|
if (chainId && id !== chainId) {
|
|
@@ -67,7 +67,7 @@ var CoinbaseWalletConnector = class extends Connector {
|
|
|
67
67
|
return {
|
|
68
68
|
account,
|
|
69
69
|
chain: { id, unsupported },
|
|
70
|
-
provider: new providers.Web3Provider(
|
|
70
|
+
provider: new _ethers.providers.Web3Provider(
|
|
71
71
|
provider
|
|
72
72
|
)
|
|
73
73
|
};
|
|
@@ -75,12 +75,12 @@ var CoinbaseWalletConnector = class extends Connector {
|
|
|
75
75
|
if (/(user closed modal|accounts received is empty)/i.test(
|
|
76
76
|
error.message
|
|
77
77
|
))
|
|
78
|
-
throw new UserRejectedRequestError(error);
|
|
78
|
+
throw new (0, _core.UserRejectedRequestError)(error);
|
|
79
79
|
throw error;
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
async disconnect() {
|
|
83
|
-
if (!__privateGet(this, _provider))
|
|
83
|
+
if (!_chunk5NCTPR6Cjs.__privateGet.call(void 0, this, _provider))
|
|
84
84
|
return;
|
|
85
85
|
const provider = await this.getProvider();
|
|
86
86
|
provider.removeListener("accountsChanged", this.onAccountsChanged);
|
|
@@ -94,39 +94,39 @@ var CoinbaseWalletConnector = class extends Connector {
|
|
|
94
94
|
const accounts = await provider.request({
|
|
95
95
|
method: "eth_accounts"
|
|
96
96
|
});
|
|
97
|
-
return getAddress(accounts[0]);
|
|
97
|
+
return _utilsjs.getAddress.call(void 0, accounts[0]);
|
|
98
98
|
}
|
|
99
99
|
async getChainId() {
|
|
100
100
|
const provider = await this.getProvider();
|
|
101
|
-
const chainId = normalizeChainId(provider.chainId);
|
|
101
|
+
const chainId = _core.normalizeChainId.call(void 0, provider.chainId);
|
|
102
102
|
return chainId;
|
|
103
103
|
}
|
|
104
104
|
async getProvider() {
|
|
105
|
-
if (!__privateGet(this, _provider)) {
|
|
106
|
-
let CoinbaseWalletSDK = (await
|
|
105
|
+
if (!_chunk5NCTPR6Cjs.__privateGet.call(void 0, this, _provider)) {
|
|
106
|
+
let CoinbaseWalletSDK = (await Promise.resolve().then(() => require("@coinbase/wallet-sdk"))).default;
|
|
107
107
|
if (typeof CoinbaseWalletSDK !== "function" && typeof CoinbaseWalletSDK.default === "function")
|
|
108
108
|
CoinbaseWalletSDK = CoinbaseWalletSDK.default;
|
|
109
|
-
__privateSet(this, _client, new CoinbaseWalletSDK(this.options));
|
|
109
|
+
_chunk5NCTPR6Cjs.__privateSet.call(void 0, this, _client, new CoinbaseWalletSDK(this.options));
|
|
110
110
|
class WalletProvider {
|
|
111
111
|
}
|
|
112
112
|
class Client {
|
|
113
113
|
}
|
|
114
|
-
const walletExtensionChainId = __privateGet(this, _client).walletExtension
|
|
114
|
+
const walletExtensionChainId = _optionalChain([_chunk5NCTPR6Cjs.__privateGet.call(void 0, this, _client), 'access', _ => _.walletExtension, 'optionalAccess', _2 => _2.getChainId, 'call', _3 => _3()]);
|
|
115
115
|
const chain = this.chains.find(
|
|
116
116
|
(chain2) => this.options.chainId ? chain2.id === this.options.chainId : chain2.id === walletExtensionChainId
|
|
117
117
|
) || this.chains[0];
|
|
118
|
-
const chainId = this.options.chainId || chain
|
|
119
|
-
const jsonRpcUrl = this.options.jsonRpcUrl || chain
|
|
120
|
-
__privateSet(this, _provider, __privateGet(this, _client).makeWeb3Provider(jsonRpcUrl, chainId));
|
|
118
|
+
const chainId = this.options.chainId || _optionalChain([chain, 'optionalAccess', _4 => _4.id]);
|
|
119
|
+
const jsonRpcUrl = this.options.jsonRpcUrl || _optionalChain([chain, 'optionalAccess', _5 => _5.rpcUrls, 'access', _6 => _6.default, 'access', _7 => _7.http, 'access', _8 => _8[0]]);
|
|
120
|
+
_chunk5NCTPR6Cjs.__privateSet.call(void 0, this, _provider, _chunk5NCTPR6Cjs.__privateGet.call(void 0, this, _client).makeWeb3Provider(jsonRpcUrl, chainId));
|
|
121
121
|
}
|
|
122
|
-
return __privateGet(this, _provider);
|
|
122
|
+
return _chunk5NCTPR6Cjs.__privateGet.call(void 0, this, _provider);
|
|
123
123
|
}
|
|
124
124
|
async getSigner({ chainId } = {}) {
|
|
125
125
|
const [provider, account] = await Promise.all([
|
|
126
126
|
this.getProvider(),
|
|
127
127
|
this.getAccount()
|
|
128
128
|
]);
|
|
129
|
-
return new providers.Web3Provider(
|
|
129
|
+
return new _ethers.providers.Web3Provider(
|
|
130
130
|
provider,
|
|
131
131
|
chainId
|
|
132
132
|
).getSigner(account);
|
|
@@ -135,29 +135,29 @@ var CoinbaseWalletConnector = class extends Connector {
|
|
|
135
135
|
try {
|
|
136
136
|
const account = await this.getAccount();
|
|
137
137
|
return !!account;
|
|
138
|
-
} catch {
|
|
138
|
+
} catch (e) {
|
|
139
139
|
return false;
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
async switchChain(chainId) {
|
|
143
143
|
const provider = await this.getProvider();
|
|
144
|
-
const id = hexValue(chainId);
|
|
144
|
+
const id = _utilsjs.hexValue.call(void 0, chainId);
|
|
145
145
|
try {
|
|
146
146
|
await provider.request({
|
|
147
147
|
method: "wallet_switchEthereumChain",
|
|
148
148
|
params: [{ chainId: id }]
|
|
149
149
|
});
|
|
150
|
-
return this.chains.find((x) => x.id === chainId)
|
|
150
|
+
return _nullishCoalesce(this.chains.find((x) => x.id === chainId), () => ( {
|
|
151
151
|
id: chainId,
|
|
152
152
|
name: `Chain ${id}`,
|
|
153
153
|
network: `${id}`,
|
|
154
154
|
nativeCurrency: { name: "Ether", decimals: 18, symbol: "ETH" },
|
|
155
155
|
rpcUrls: { default: { http: [""] }, public: { http: [""] } }
|
|
156
|
-
};
|
|
156
|
+
}));
|
|
157
157
|
} catch (error) {
|
|
158
158
|
const chain = this.chains.find((x) => x.id === chainId);
|
|
159
159
|
if (!chain)
|
|
160
|
-
throw new ChainNotConfiguredError({ chainId, connectorId: this.id });
|
|
160
|
+
throw new (0, _core.ChainNotConfiguredError)({ chainId, connectorId: this.id });
|
|
161
161
|
if (error.code === 4902) {
|
|
162
162
|
try {
|
|
163
163
|
await provider.request({
|
|
@@ -167,21 +167,21 @@ var CoinbaseWalletConnector = class extends Connector {
|
|
|
167
167
|
chainId: id,
|
|
168
168
|
chainName: chain.name,
|
|
169
169
|
nativeCurrency: chain.nativeCurrency,
|
|
170
|
-
rpcUrls: [chain.rpcUrls.public
|
|
170
|
+
rpcUrls: [_nullishCoalesce(_optionalChain([chain, 'access', _9 => _9.rpcUrls, 'access', _10 => _10.public, 'optionalAccess', _11 => _11.http, 'access', _12 => _12[0]]), () => ( ""))],
|
|
171
171
|
blockExplorerUrls: this.getBlockExplorerUrls(chain)
|
|
172
172
|
}
|
|
173
173
|
]
|
|
174
174
|
});
|
|
175
175
|
return chain;
|
|
176
176
|
} catch (addError) {
|
|
177
|
-
if (__privateMethod(this, _isUserRejectedRequestError, isUserRejectedRequestError_fn).call(this, addError))
|
|
178
|
-
throw new UserRejectedRequestError(addError);
|
|
179
|
-
throw new AddChainError();
|
|
177
|
+
if (_chunk5NCTPR6Cjs.__privateMethod.call(void 0, this, _isUserRejectedRequestError, isUserRejectedRequestError_fn).call(this, addError))
|
|
178
|
+
throw new (0, _core.UserRejectedRequestError)(addError);
|
|
179
|
+
throw new (0, _core.AddChainError)();
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
|
-
if (__privateMethod(this, _isUserRejectedRequestError, isUserRejectedRequestError_fn).call(this, error))
|
|
183
|
-
throw new UserRejectedRequestError(error);
|
|
184
|
-
throw new SwitchChainError(error);
|
|
182
|
+
if (_chunk5NCTPR6Cjs.__privateMethod.call(void 0, this, _isUserRejectedRequestError, isUserRejectedRequestError_fn).call(this, error))
|
|
183
|
+
throw new (0, _core.UserRejectedRequestError)(error);
|
|
184
|
+
throw new (0, _core.SwitchChainError)(error);
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
187
|
async watchAsset({
|
|
@@ -211,6 +211,6 @@ _isUserRejectedRequestError = new WeakSet();
|
|
|
211
211
|
isUserRejectedRequestError_fn = function(error) {
|
|
212
212
|
return /(user rejected)/i.test(error.message);
|
|
213
213
|
};
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
exports.CoinbaseWalletConnector = CoinbaseWalletConnector;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunk5NCTPR6Cjs = require('./chunk-5NCTPR6C.js');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
exports.Connector = _chunk5NCTPR6Cjs.Connector;
|
package/dist/injected.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkLNIFBRWCjs = require('./chunk-LNIFBRWC.js');
|
|
4
|
+
require('./chunk-5NCTPR6C.js');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
exports.InjectedConnector = _chunkLNIFBRWCjs.InjectedConnector;
|