@wagmi/connectors 2.7.0 → 3.0.0-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/coinbaseWallet/package.json +1 -1
- package/dist/chunk-OQILYQDO.js +4 -4
- package/dist/chunk-QYMCVNHT.js +14 -14
- package/dist/chunk-YZRVUC6Y.js +73 -73
- package/dist/chunk-ZCAPXGBX.js +10 -10
- package/dist/coinbaseWallet.js +58 -58
- package/dist/index.js +16 -16
- package/dist/injected.js +9 -9
- package/dist/ledger.js +83 -83
- package/dist/metaMask.js +37 -37
- package/dist/mock/index.js +63 -63
- package/dist/safe.js +46 -46
- package/dist/walletConnect.js +110 -110
- package/dist/walletConnectLegacy.js +58 -58
- package/injected/package.json +1 -1
- package/ledger/package.json +1 -1
- package/metaMask/package.json +1 -1
- package/mock/package.json +1 -1
- package/package.json +5 -45
- package/safe/package.json +1 -1
- package/walletConnect/package.json +1 -1
- package/walletConnectLegacy/package.json +1 -1
package/dist/chunk-OQILYQDO.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/utils/normalizeChainId.ts
|
|
2
2
|
function normalizeChainId(chainId) {
|
|
3
3
|
if (typeof chainId === "string")
|
|
4
4
|
return Number.parseInt(
|
|
@@ -10,6 +10,6 @@ function normalizeChainId(chainId) {
|
|
|
10
10
|
return chainId;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
exports.normalizeChainId = normalizeChainId;
|
package/dist/chunk-QYMCVNHT.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 _eventemitter3 = require('eventemitter3'); var _eventemitter32 = _interopRequireDefault(_eventemitter3);
|
|
32
|
+
var _chains = require('viem/chains');
|
|
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();
|
|
@@ -43,7 +43,7 @@ var Connector = class extends EventEmitter {
|
|
|
43
43
|
this.options = options;
|
|
44
44
|
}
|
|
45
45
|
getBlockExplorerUrls(chain) {
|
|
46
|
-
const { default: blockExplorer, ...blockExplorers } = chain.blockExplorers
|
|
46
|
+
const { default: blockExplorer, ...blockExplorers } = _nullishCoalesce(chain.blockExplorers, () => ( {}));
|
|
47
47
|
if (blockExplorer)
|
|
48
48
|
return [
|
|
49
49
|
blockExplorer.url,
|
|
@@ -58,11 +58,11 @@ var Connector = class extends EventEmitter {
|
|
|
58
58
|
}
|
|
59
59
|
};
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
exports.__publicField = __publicField; exports.__privateGet = __privateGet; exports.__privateAdd = __privateAdd; exports.__privateSet = __privateSet; exports.__privateMethod = __privateMethod; exports.Connector = Connector;
|
package/dist/chunk-YZRVUC6Y.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
+
var _chunkZCAPXGBXjs = require('./chunk-ZCAPXGBX.js');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
var _chunkOQILYQDOjs = require('./chunk-OQILYQDO.js');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
var _chunkQYMCVNHTjs = require('./chunk-QYMCVNHT.js');
|
|
15
15
|
|
|
16
16
|
// src/injected.ts
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
var _viem = require('viem');
|
|
26
26
|
|
|
27
27
|
// src/utils/getInjectedName.ts
|
|
28
28
|
function getInjectedName(ethereum) {
|
|
@@ -118,7 +118,7 @@ function getInjectedName(ethereum) {
|
|
|
118
118
|
if (provider.isMetaMask)
|
|
119
119
|
return "MetaMask";
|
|
120
120
|
};
|
|
121
|
-
if (ethereum.providers
|
|
121
|
+
if (_optionalChain([ethereum, 'access', _ => _.providers, 'optionalAccess', _2 => _2.length])) {
|
|
122
122
|
const nameSet = /* @__PURE__ */ new Set();
|
|
123
123
|
let unknownCount = 1;
|
|
124
124
|
for (const provider of ethereum.providers) {
|
|
@@ -132,14 +132,14 @@ function getInjectedName(ethereum) {
|
|
|
132
132
|
const names = [...nameSet];
|
|
133
133
|
if (names.length)
|
|
134
134
|
return names;
|
|
135
|
-
return names[0]
|
|
135
|
+
return _nullishCoalesce(names[0], () => ( "Injected"));
|
|
136
136
|
}
|
|
137
|
-
return getName(ethereum)
|
|
137
|
+
return _nullishCoalesce(getName(ethereum), () => ( "Injected"));
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
// src/injected.ts
|
|
141
141
|
var _provider;
|
|
142
|
-
var InjectedConnector = class extends Connector {
|
|
142
|
+
var InjectedConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
143
143
|
constructor({
|
|
144
144
|
chains,
|
|
145
145
|
options: options_
|
|
@@ -150,32 +150,32 @@ var InjectedConnector = class extends Connector {
|
|
|
150
150
|
if (typeof window === "undefined")
|
|
151
151
|
return;
|
|
152
152
|
const ethereum = window.ethereum;
|
|
153
|
-
if (ethereum
|
|
153
|
+
if (_optionalChain([ethereum, 'optionalAccess', _3 => _3.providers]))
|
|
154
154
|
return ethereum.providers[0];
|
|
155
155
|
return ethereum;
|
|
156
156
|
},
|
|
157
157
|
...options_
|
|
158
158
|
};
|
|
159
159
|
super({ chains, options });
|
|
160
|
-
__publicField(this, "id", "injected");
|
|
161
|
-
__publicField(this, "name");
|
|
162
|
-
__publicField(this, "ready");
|
|
163
|
-
__privateAdd(this, _provider, void 0);
|
|
164
|
-
__publicField(this, "shimDisconnectKey", `${this.id}.shimDisconnect`);
|
|
165
|
-
__publicField(this, "onAccountsChanged", (accounts) => {
|
|
160
|
+
_chunkQYMCVNHTjs.__publicField.call(void 0, this, "id", "injected");
|
|
161
|
+
_chunkQYMCVNHTjs.__publicField.call(void 0, this, "name");
|
|
162
|
+
_chunkQYMCVNHTjs.__publicField.call(void 0, this, "ready");
|
|
163
|
+
_chunkQYMCVNHTjs.__privateAdd.call(void 0, this, _provider, void 0);
|
|
164
|
+
_chunkQYMCVNHTjs.__publicField.call(void 0, this, "shimDisconnectKey", `${this.id}.shimDisconnect`);
|
|
165
|
+
_chunkQYMCVNHTjs.__publicField.call(void 0, this, "onAccountsChanged", (accounts) => {
|
|
166
166
|
if (accounts.length === 0)
|
|
167
167
|
this.emit("disconnect");
|
|
168
168
|
else
|
|
169
169
|
this.emit("change", {
|
|
170
|
-
account: getAddress(accounts[0])
|
|
170
|
+
account: _viem.getAddress.call(void 0, accounts[0])
|
|
171
171
|
});
|
|
172
172
|
});
|
|
173
|
-
__publicField(this, "onChainChanged", (chainId) => {
|
|
174
|
-
const id = normalizeChainId(chainId);
|
|
173
|
+
_chunkQYMCVNHTjs.__publicField.call(void 0, this, "onChainChanged", (chainId) => {
|
|
174
|
+
const id = _chunkOQILYQDOjs.normalizeChainId.call(void 0, chainId);
|
|
175
175
|
const unsupported = this.isChainUnsupported(id);
|
|
176
176
|
this.emit("change", { chain: { id, unsupported } });
|
|
177
177
|
});
|
|
178
|
-
__publicField(this, "onDisconnect", async (error) => {
|
|
178
|
+
_chunkQYMCVNHTjs.__publicField.call(void 0, this, "onDisconnect", async (error) => {
|
|
179
179
|
if (error.code === 1013) {
|
|
180
180
|
const provider = await this.getProvider();
|
|
181
181
|
if (provider) {
|
|
@@ -186,7 +186,7 @@ var InjectedConnector = class extends Connector {
|
|
|
186
186
|
}
|
|
187
187
|
this.emit("disconnect");
|
|
188
188
|
if (this.options.shimDisconnect)
|
|
189
|
-
this.storage
|
|
189
|
+
_optionalChain([this, 'access', _4 => _4.storage, 'optionalAccess', _5 => _5.removeItem, 'call', _6 => _6(this.shimDisconnectKey)]);
|
|
190
190
|
});
|
|
191
191
|
const provider = options.getProvider();
|
|
192
192
|
if (typeof options.name === "string")
|
|
@@ -209,7 +209,7 @@ var InjectedConnector = class extends Connector {
|
|
|
209
209
|
try {
|
|
210
210
|
const provider = await this.getProvider();
|
|
211
211
|
if (!provider)
|
|
212
|
-
throw new ConnectorNotFoundError();
|
|
212
|
+
throw new (0, _chunkZCAPXGBXjs.ConnectorNotFoundError)();
|
|
213
213
|
if (provider.on) {
|
|
214
214
|
provider.on("accountsChanged", this.onAccountsChanged);
|
|
215
215
|
provider.on("chainChanged", this.onChainChanged);
|
|
@@ -219,7 +219,7 @@ var InjectedConnector = class extends Connector {
|
|
|
219
219
|
const accounts = await provider.request({
|
|
220
220
|
method: "eth_requestAccounts"
|
|
221
221
|
});
|
|
222
|
-
const account = getAddress(accounts[0]);
|
|
222
|
+
const account = _viem.getAddress.call(void 0, accounts[0]);
|
|
223
223
|
let id = await this.getChainId();
|
|
224
224
|
let unsupported = this.isChainUnsupported(id);
|
|
225
225
|
if (chainId && id !== chainId) {
|
|
@@ -228,46 +228,46 @@ var InjectedConnector = class extends Connector {
|
|
|
228
228
|
unsupported = this.isChainUnsupported(id);
|
|
229
229
|
}
|
|
230
230
|
if (this.options.shimDisconnect)
|
|
231
|
-
this.storage
|
|
231
|
+
_optionalChain([this, 'access', _7 => _7.storage, 'optionalAccess', _8 => _8.setItem, 'call', _9 => _9(this.shimDisconnectKey, true)]);
|
|
232
232
|
return { account, chain: { id, unsupported } };
|
|
233
233
|
} catch (error) {
|
|
234
234
|
if (this.isUserRejectedRequestError(error))
|
|
235
|
-
throw new UserRejectedRequestError(error);
|
|
235
|
+
throw new (0, _viem.UserRejectedRequestError)(error);
|
|
236
236
|
if (error.code === -32002)
|
|
237
|
-
throw new ResourceUnavailableRpcError(error);
|
|
237
|
+
throw new (0, _viem.ResourceUnavailableRpcError)(error);
|
|
238
238
|
throw error;
|
|
239
239
|
}
|
|
240
240
|
}
|
|
241
241
|
async disconnect() {
|
|
242
242
|
const provider = await this.getProvider();
|
|
243
|
-
if (!provider
|
|
243
|
+
if (!_optionalChain([provider, 'optionalAccess', _10 => _10.removeListener]))
|
|
244
244
|
return;
|
|
245
245
|
provider.removeListener("accountsChanged", this.onAccountsChanged);
|
|
246
246
|
provider.removeListener("chainChanged", this.onChainChanged);
|
|
247
247
|
provider.removeListener("disconnect", this.onDisconnect);
|
|
248
248
|
if (this.options.shimDisconnect)
|
|
249
|
-
this.storage
|
|
249
|
+
_optionalChain([this, 'access', _11 => _11.storage, 'optionalAccess', _12 => _12.removeItem, 'call', _13 => _13(this.shimDisconnectKey)]);
|
|
250
250
|
}
|
|
251
251
|
async getAccount() {
|
|
252
252
|
const provider = await this.getProvider();
|
|
253
253
|
if (!provider)
|
|
254
|
-
throw new ConnectorNotFoundError();
|
|
254
|
+
throw new (0, _chunkZCAPXGBXjs.ConnectorNotFoundError)();
|
|
255
255
|
const accounts = await provider.request({
|
|
256
256
|
method: "eth_accounts"
|
|
257
257
|
});
|
|
258
|
-
return getAddress(accounts[0]);
|
|
258
|
+
return _viem.getAddress.call(void 0, accounts[0]);
|
|
259
259
|
}
|
|
260
260
|
async getChainId() {
|
|
261
261
|
const provider = await this.getProvider();
|
|
262
262
|
if (!provider)
|
|
263
|
-
throw new ConnectorNotFoundError();
|
|
264
|
-
return provider.request({ method: "eth_chainId" }).then(normalizeChainId);
|
|
263
|
+
throw new (0, _chunkZCAPXGBXjs.ConnectorNotFoundError)();
|
|
264
|
+
return provider.request({ method: "eth_chainId" }).then(_chunkOQILYQDOjs.normalizeChainId);
|
|
265
265
|
}
|
|
266
266
|
async getProvider() {
|
|
267
267
|
const provider = this.options.getProvider();
|
|
268
268
|
if (provider)
|
|
269
|
-
__privateSet(this, _provider, provider);
|
|
270
|
-
return __privateGet(this, _provider);
|
|
269
|
+
_chunkQYMCVNHTjs.__privateSet.call(void 0, this, _provider, provider);
|
|
270
|
+
return _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider);
|
|
271
271
|
}
|
|
272
272
|
async getWalletClient({
|
|
273
273
|
chainId
|
|
@@ -279,30 +279,30 @@ var InjectedConnector = class extends Connector {
|
|
|
279
279
|
const chain = this.chains.find((x) => x.id === chainId);
|
|
280
280
|
if (!provider)
|
|
281
281
|
throw new Error("provider is required.");
|
|
282
|
-
return createWalletClient({
|
|
282
|
+
return _viem.createWalletClient.call(void 0, {
|
|
283
283
|
account,
|
|
284
284
|
chain,
|
|
285
|
-
transport: custom(provider)
|
|
285
|
+
transport: _viem.custom.call(void 0, provider)
|
|
286
286
|
});
|
|
287
287
|
}
|
|
288
288
|
async isAuthorized() {
|
|
289
289
|
try {
|
|
290
|
-
if (this.options.shimDisconnect && !this.storage
|
|
290
|
+
if (this.options.shimDisconnect && !_optionalChain([this, 'access', _14 => _14.storage, 'optionalAccess', _15 => _15.getItem, 'call', _16 => _16(this.shimDisconnectKey)]))
|
|
291
291
|
return false;
|
|
292
292
|
const provider = await this.getProvider();
|
|
293
293
|
if (!provider)
|
|
294
|
-
throw new ConnectorNotFoundError();
|
|
294
|
+
throw new (0, _chunkZCAPXGBXjs.ConnectorNotFoundError)();
|
|
295
295
|
const account = await this.getAccount();
|
|
296
296
|
return !!account;
|
|
297
|
-
} catch {
|
|
297
|
+
} catch (e) {
|
|
298
298
|
return false;
|
|
299
299
|
}
|
|
300
300
|
}
|
|
301
301
|
async switchChain(chainId) {
|
|
302
302
|
const provider = await this.getProvider();
|
|
303
303
|
if (!provider)
|
|
304
|
-
throw new ConnectorNotFoundError();
|
|
305
|
-
const id = numberToHex(chainId);
|
|
304
|
+
throw new (0, _chunkZCAPXGBXjs.ConnectorNotFoundError)();
|
|
305
|
+
const id = _viem.numberToHex.call(void 0, chainId);
|
|
306
306
|
try {
|
|
307
307
|
await Promise.all([
|
|
308
308
|
provider.request({
|
|
@@ -311,26 +311,26 @@ var InjectedConnector = class extends Connector {
|
|
|
311
311
|
}),
|
|
312
312
|
new Promise(
|
|
313
313
|
(res) => this.on("change", ({ chain }) => {
|
|
314
|
-
if (chain
|
|
314
|
+
if (_optionalChain([chain, 'optionalAccess', _17 => _17.id]) === chainId)
|
|
315
315
|
res();
|
|
316
316
|
})
|
|
317
317
|
)
|
|
318
318
|
]);
|
|
319
|
-
return this.chains.find((x) => x.id === chainId)
|
|
319
|
+
return _nullishCoalesce(this.chains.find((x) => x.id === chainId), () => ( {
|
|
320
320
|
id: chainId,
|
|
321
321
|
name: `Chain ${id}`,
|
|
322
322
|
network: `${id}`,
|
|
323
323
|
nativeCurrency: { name: "Ether", decimals: 18, symbol: "ETH" },
|
|
324
324
|
rpcUrls: { default: { http: [""] }, public: { http: [""] } }
|
|
325
|
-
};
|
|
325
|
+
}));
|
|
326
326
|
} catch (error) {
|
|
327
327
|
const chain = this.chains.find((x) => x.id === chainId);
|
|
328
328
|
if (!chain)
|
|
329
|
-
throw new ChainNotConfiguredForConnectorError({
|
|
329
|
+
throw new (0, _chunkZCAPXGBXjs.ChainNotConfiguredForConnectorError)({
|
|
330
330
|
chainId,
|
|
331
331
|
connectorId: this.id
|
|
332
332
|
});
|
|
333
|
-
if (error.code === 4902 || error
|
|
333
|
+
if (error.code === 4902 || _optionalChain([error, 'optionalAccess', _18 => _18.data, 'optionalAccess', _19 => _19.originalError, 'optionalAccess', _20 => _20.code]) === 4902) {
|
|
334
334
|
try {
|
|
335
335
|
await provider.request({
|
|
336
336
|
method: "wallet_addEthereumChain",
|
|
@@ -339,24 +339,24 @@ var InjectedConnector = class extends Connector {
|
|
|
339
339
|
chainId: id,
|
|
340
340
|
chainName: chain.name,
|
|
341
341
|
nativeCurrency: chain.nativeCurrency,
|
|
342
|
-
rpcUrls: [chain.rpcUrls.public
|
|
342
|
+
rpcUrls: [_nullishCoalesce(_optionalChain([chain, 'access', _21 => _21.rpcUrls, 'access', _22 => _22.public, 'optionalAccess', _23 => _23.http, 'access', _24 => _24[0]]), () => ( ""))],
|
|
343
343
|
blockExplorerUrls: this.getBlockExplorerUrls(chain)
|
|
344
344
|
}
|
|
345
345
|
]
|
|
346
346
|
});
|
|
347
347
|
const currentChainId = await this.getChainId();
|
|
348
348
|
if (currentChainId !== chainId)
|
|
349
|
-
throw new UserRejectedRequestError(
|
|
349
|
+
throw new (0, _viem.UserRejectedRequestError)(
|
|
350
350
|
new Error("User rejected switch after adding network.")
|
|
351
351
|
);
|
|
352
352
|
return chain;
|
|
353
353
|
} catch (error2) {
|
|
354
|
-
throw new UserRejectedRequestError(error2);
|
|
354
|
+
throw new (0, _viem.UserRejectedRequestError)(error2);
|
|
355
355
|
}
|
|
356
356
|
}
|
|
357
357
|
if (this.isUserRejectedRequestError(error))
|
|
358
|
-
throw new UserRejectedRequestError(error);
|
|
359
|
-
throw new SwitchChainError(error);
|
|
358
|
+
throw new (0, _viem.UserRejectedRequestError)(error);
|
|
359
|
+
throw new (0, _viem.SwitchChainError)(error);
|
|
360
360
|
}
|
|
361
361
|
}
|
|
362
362
|
async watchAsset({
|
|
@@ -367,7 +367,7 @@ var InjectedConnector = class extends Connector {
|
|
|
367
367
|
}) {
|
|
368
368
|
const provider = await this.getProvider();
|
|
369
369
|
if (!provider)
|
|
370
|
-
throw new ConnectorNotFoundError();
|
|
370
|
+
throw new (0, _chunkZCAPXGBXjs.ConnectorNotFoundError)();
|
|
371
371
|
return provider.request({
|
|
372
372
|
method: "wallet_watchAsset",
|
|
373
373
|
params: {
|
|
@@ -387,6 +387,6 @@ var InjectedConnector = class extends Connector {
|
|
|
387
387
|
};
|
|
388
388
|
_provider = new WeakMap();
|
|
389
389
|
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
exports.InjectedConnector = InjectedConnector;
|
package/dist/chunk-ZCAPXGBX.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkQYMCVNHTjs = require('./chunk-QYMCVNHT.js');
|
|
4
4
|
|
|
5
5
|
// src/errors.ts
|
|
6
6
|
var ChainNotConfiguredForConnectorError = class extends Error {
|
|
@@ -9,18 +9,18 @@ var ChainNotConfiguredForConnectorError = class extends Error {
|
|
|
9
9
|
connectorId
|
|
10
10
|
}) {
|
|
11
11
|
super(`Chain "${chainId}" not configured for connector "${connectorId}".`);
|
|
12
|
-
__publicField(this, "name", "ChainNotConfiguredForConnectorError");
|
|
12
|
+
_chunkQYMCVNHTjs.__publicField.call(void 0, this, "name", "ChainNotConfiguredForConnectorError");
|
|
13
13
|
}
|
|
14
14
|
};
|
|
15
15
|
var ConnectorNotFoundError = class extends Error {
|
|
16
16
|
constructor() {
|
|
17
17
|
super(...arguments);
|
|
18
|
-
__publicField(this, "name", "ConnectorNotFoundError");
|
|
19
|
-
__publicField(this, "message", "Connector not found");
|
|
18
|
+
_chunkQYMCVNHTjs.__publicField.call(void 0, this, "name", "ConnectorNotFoundError");
|
|
19
|
+
_chunkQYMCVNHTjs.__publicField.call(void 0, this, "message", "Connector not found");
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
exports.ChainNotConfiguredForConnectorError = ChainNotConfiguredForConnectorError; exports.ConnectorNotFoundError = ConnectorNotFoundError;
|
package/dist/coinbaseWallet.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
+
var _chunkZCAPXGBXjs = require('./chunk-ZCAPXGBX.js');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunkOQILYQDOjs = require('./chunk-OQILYQDO.js');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
var _chunkQYMCVNHTjs = require('./chunk-QYMCVNHT.js');
|
|
14
14
|
|
|
15
15
|
// src/coinbaseWallet.ts
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
var _viem = require('viem');
|
|
24
24
|
var _client, _provider;
|
|
25
|
-
var CoinbaseWalletConnector = class extends Connector {
|
|
25
|
+
var CoinbaseWalletConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
26
26
|
constructor({ chains, options }) {
|
|
27
27
|
super({
|
|
28
28
|
chains,
|
|
@@ -31,23 +31,23 @@ var CoinbaseWalletConnector = class extends Connector {
|
|
|
31
31
|
...options
|
|
32
32
|
}
|
|
33
33
|
});
|
|
34
|
-
__publicField(this, "id", "coinbaseWallet");
|
|
35
|
-
__publicField(this, "name", "Coinbase Wallet");
|
|
36
|
-
__publicField(this, "ready", true);
|
|
37
|
-
__privateAdd(this, _client, void 0);
|
|
38
|
-
__privateAdd(this, _provider, void 0);
|
|
39
|
-
__publicField(this, "onAccountsChanged", (accounts) => {
|
|
34
|
+
_chunkQYMCVNHTjs.__publicField.call(void 0, this, "id", "coinbaseWallet");
|
|
35
|
+
_chunkQYMCVNHTjs.__publicField.call(void 0, this, "name", "Coinbase Wallet");
|
|
36
|
+
_chunkQYMCVNHTjs.__publicField.call(void 0, this, "ready", true);
|
|
37
|
+
_chunkQYMCVNHTjs.__privateAdd.call(void 0, this, _client, void 0);
|
|
38
|
+
_chunkQYMCVNHTjs.__privateAdd.call(void 0, this, _provider, void 0);
|
|
39
|
+
_chunkQYMCVNHTjs.__publicField.call(void 0, this, "onAccountsChanged", (accounts) => {
|
|
40
40
|
if (accounts.length === 0)
|
|
41
41
|
this.emit("disconnect");
|
|
42
42
|
else
|
|
43
|
-
this.emit("change", { account: getAddress(accounts[0]) });
|
|
43
|
+
this.emit("change", { account: _viem.getAddress.call(void 0, accounts[0]) });
|
|
44
44
|
});
|
|
45
|
-
__publicField(this, "onChainChanged", (chainId) => {
|
|
46
|
-
const id = normalizeChainId(chainId);
|
|
45
|
+
_chunkQYMCVNHTjs.__publicField.call(void 0, this, "onChainChanged", (chainId) => {
|
|
46
|
+
const id = _chunkOQILYQDOjs.normalizeChainId.call(void 0, chainId);
|
|
47
47
|
const unsupported = this.isChainUnsupported(id);
|
|
48
48
|
this.emit("change", { chain: { id, unsupported } });
|
|
49
49
|
});
|
|
50
|
-
__publicField(this, "onDisconnect", () => {
|
|
50
|
+
_chunkQYMCVNHTjs.__publicField.call(void 0, this, "onDisconnect", () => {
|
|
51
51
|
this.emit("disconnect");
|
|
52
52
|
});
|
|
53
53
|
}
|
|
@@ -59,7 +59,7 @@ var CoinbaseWalletConnector = class extends Connector {
|
|
|
59
59
|
provider.on("disconnect", this.onDisconnect);
|
|
60
60
|
this.emit("message", { type: "connecting" });
|
|
61
61
|
const accounts = await provider.enable();
|
|
62
|
-
const account = getAddress(accounts[0]);
|
|
62
|
+
const account = _viem.getAddress.call(void 0, accounts[0]);
|
|
63
63
|
let id = await this.getChainId();
|
|
64
64
|
let unsupported = this.isChainUnsupported(id);
|
|
65
65
|
if (chainId && id !== chainId) {
|
|
@@ -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, _viem.UserRejectedRequestError)(error);
|
|
79
79
|
throw error;
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
async disconnect() {
|
|
83
|
-
if (!__privateGet(this, _provider))
|
|
83
|
+
if (!_chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider))
|
|
84
84
|
return;
|
|
85
85
|
const provider = await this.getProvider();
|
|
86
86
|
provider.removeListener("accountsChanged", this.onAccountsChanged);
|
|
@@ -94,32 +94,32 @@ 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 _viem.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 = _chunkOQILYQDOjs.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 (!_chunkQYMCVNHTjs.__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
|
+
_chunkQYMCVNHTjs.__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([_chunkQYMCVNHTjs.__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
|
+
_chunkQYMCVNHTjs.__privateSet.call(void 0, this, _provider, _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _client).makeWeb3Provider(jsonRpcUrl, chainId));
|
|
121
121
|
}
|
|
122
|
-
return __privateGet(this, _provider);
|
|
122
|
+
return _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider);
|
|
123
123
|
}
|
|
124
124
|
async getWalletClient({
|
|
125
125
|
chainId
|
|
@@ -131,39 +131,39 @@ var CoinbaseWalletConnector = class extends Connector {
|
|
|
131
131
|
const chain = this.chains.find((x) => x.id === chainId);
|
|
132
132
|
if (!provider)
|
|
133
133
|
throw new Error("provider is required.");
|
|
134
|
-
return createWalletClient({
|
|
134
|
+
return _viem.createWalletClient.call(void 0, {
|
|
135
135
|
account,
|
|
136
136
|
chain,
|
|
137
|
-
transport: custom(provider)
|
|
137
|
+
transport: _viem.custom.call(void 0, provider)
|
|
138
138
|
});
|
|
139
139
|
}
|
|
140
140
|
async isAuthorized() {
|
|
141
141
|
try {
|
|
142
142
|
const account = await this.getAccount();
|
|
143
143
|
return !!account;
|
|
144
|
-
} catch {
|
|
144
|
+
} catch (e) {
|
|
145
145
|
return false;
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
async switchChain(chainId) {
|
|
149
149
|
const provider = await this.getProvider();
|
|
150
|
-
const id = numberToHex(chainId);
|
|
150
|
+
const id = _viem.numberToHex.call(void 0, chainId);
|
|
151
151
|
try {
|
|
152
152
|
await provider.request({
|
|
153
153
|
method: "wallet_switchEthereumChain",
|
|
154
154
|
params: [{ chainId: id }]
|
|
155
155
|
});
|
|
156
|
-
return this.chains.find((x) => x.id === chainId)
|
|
156
|
+
return _nullishCoalesce(this.chains.find((x) => x.id === chainId), () => ( {
|
|
157
157
|
id: chainId,
|
|
158
158
|
name: `Chain ${id}`,
|
|
159
159
|
network: `${id}`,
|
|
160
160
|
nativeCurrency: { name: "Ether", decimals: 18, symbol: "ETH" },
|
|
161
161
|
rpcUrls: { default: { http: [""] }, public: { http: [""] } }
|
|
162
|
-
};
|
|
162
|
+
}));
|
|
163
163
|
} catch (error) {
|
|
164
164
|
const chain = this.chains.find((x) => x.id === chainId);
|
|
165
165
|
if (!chain)
|
|
166
|
-
throw new ChainNotConfiguredForConnectorError({
|
|
166
|
+
throw new (0, _chunkZCAPXGBXjs.ChainNotConfiguredForConnectorError)({
|
|
167
167
|
chainId,
|
|
168
168
|
connectorId: this.id
|
|
169
169
|
});
|
|
@@ -176,17 +176,17 @@ var CoinbaseWalletConnector = class extends Connector {
|
|
|
176
176
|
chainId: id,
|
|
177
177
|
chainName: chain.name,
|
|
178
178
|
nativeCurrency: chain.nativeCurrency,
|
|
179
|
-
rpcUrls: [chain.rpcUrls.public
|
|
179
|
+
rpcUrls: [_nullishCoalesce(_optionalChain([chain, 'access', _9 => _9.rpcUrls, 'access', _10 => _10.public, 'optionalAccess', _11 => _11.http, 'access', _12 => _12[0]]), () => ( ""))],
|
|
180
180
|
blockExplorerUrls: this.getBlockExplorerUrls(chain)
|
|
181
181
|
}
|
|
182
182
|
]
|
|
183
183
|
});
|
|
184
184
|
return chain;
|
|
185
185
|
} catch (error2) {
|
|
186
|
-
throw new UserRejectedRequestError(error2);
|
|
186
|
+
throw new (0, _viem.UserRejectedRequestError)(error2);
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
|
-
throw new SwitchChainError(error);
|
|
189
|
+
throw new (0, _viem.SwitchChainError)(error);
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
192
|
async watchAsset({
|
|
@@ -212,6 +212,6 @@ var CoinbaseWalletConnector = class extends Connector {
|
|
|
212
212
|
};
|
|
213
213
|
_client = new WeakMap();
|
|
214
214
|
_provider = new WeakMap();
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
exports.CoinbaseWalletConnector = CoinbaseWalletConnector;
|