@wagmi/connectors 0.2.2-cjs → 0.2.2
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 +86 -86
- package/package.json +2 -1
package/dist/walletConnect.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import {
|
|
2
|
+
Connector,
|
|
3
|
+
__privateAdd,
|
|
4
|
+
__privateGet,
|
|
5
|
+
__privateMethod,
|
|
6
|
+
__privateSet,
|
|
7
|
+
__publicField
|
|
8
|
+
} from "./chunk-5NCTPR6C.js";
|
|
9
9
|
|
|
10
10
|
// src/walletConnect.ts
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
import {
|
|
12
|
+
SwitchChainError,
|
|
13
|
+
UserRejectedRequestError,
|
|
14
|
+
getClient,
|
|
15
|
+
normalizeChainId
|
|
16
|
+
} from "@wagmi/core";
|
|
17
|
+
import { providers } from "ethers";
|
|
18
|
+
import { getAddress, hexValue } from "ethers/lib/utils.js";
|
|
19
19
|
var defaultV2Config = {
|
|
20
20
|
namespace: "eip155",
|
|
21
21
|
methods: [
|
|
@@ -28,41 +28,41 @@ var defaultV2Config = {
|
|
|
28
28
|
events: ["accountsChanged", "chainChanged"]
|
|
29
29
|
};
|
|
30
30
|
var _provider, _initUniversalProviderPromise, _web3Modal, _createWeb3Modal, createWeb3Modal_fn, _initUniversalProvider, initUniversalProvider_fn, _createUniversalProvider, createUniversalProvider_fn, _isChainsAuthorized, isChainsAuthorized_fn, _switchChain, switchChain_fn;
|
|
31
|
-
var WalletConnectConnector = class extends
|
|
31
|
+
var WalletConnectConnector = class extends Connector {
|
|
32
32
|
constructor(config) {
|
|
33
33
|
super(config);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
34
|
+
__privateAdd(this, _createWeb3Modal);
|
|
35
|
+
__privateAdd(this, _initUniversalProvider);
|
|
36
|
+
__privateAdd(this, _createUniversalProvider);
|
|
37
|
+
__privateAdd(this, _isChainsAuthorized);
|
|
38
|
+
__privateAdd(this, _switchChain);
|
|
39
|
+
__publicField(this, "id", "walletConnect");
|
|
40
|
+
__publicField(this, "name", "WalletConnect");
|
|
41
|
+
__publicField(this, "ready", true);
|
|
42
|
+
__privateAdd(this, _provider, void 0);
|
|
43
|
+
__privateAdd(this, _initUniversalProviderPromise, void 0);
|
|
44
|
+
__privateAdd(this, _web3Modal, void 0);
|
|
45
|
+
__publicField(this, "onAccountsChanged", (accounts) => {
|
|
46
46
|
if (accounts.length === 0)
|
|
47
47
|
this.emit("disconnect");
|
|
48
48
|
else
|
|
49
|
-
this.emit("change", { account:
|
|
49
|
+
this.emit("change", { account: getAddress(accounts[0]) });
|
|
50
50
|
});
|
|
51
|
-
|
|
52
|
-
const id =
|
|
51
|
+
__publicField(this, "onChainChanged", (chainId) => {
|
|
52
|
+
const id = normalizeChainId(chainId);
|
|
53
53
|
const unsupported = this.isChainUnsupported(id);
|
|
54
54
|
this.emit("change", { chain: { id, unsupported } });
|
|
55
55
|
});
|
|
56
|
-
|
|
56
|
+
__publicField(this, "onDisconnect", () => {
|
|
57
57
|
this.emit("disconnect");
|
|
58
58
|
});
|
|
59
|
-
|
|
59
|
+
__publicField(this, "onDisplayUri", (uri) => {
|
|
60
60
|
this.emit("message", { type: "display_uri", data: uri });
|
|
61
61
|
});
|
|
62
62
|
if (this.version === "2") {
|
|
63
|
-
|
|
63
|
+
__privateMethod(this, _createUniversalProvider, createUniversalProvider_fn).call(this);
|
|
64
64
|
if (this.isQrCode)
|
|
65
|
-
|
|
65
|
+
__privateMethod(this, _createWeb3Modal, createWeb3Modal_fn).call(this);
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
get isQrCode() {
|
|
@@ -84,7 +84,7 @@ var WalletConnectConnector = class extends _chunk5NCTPR6Cjs.Connector {
|
|
|
84
84
|
try {
|
|
85
85
|
let targetChainId = chainId;
|
|
86
86
|
if (!targetChainId) {
|
|
87
|
-
const lastUsedChainId =
|
|
87
|
+
const lastUsedChainId = getClient().lastUsedChainId;
|
|
88
88
|
if (lastUsedChainId && !this.isChainUnsupported(lastUsedChainId))
|
|
89
89
|
targetChainId = lastUsedChainId;
|
|
90
90
|
}
|
|
@@ -98,7 +98,7 @@ var WalletConnectConnector = class extends _chunk5NCTPR6Cjs.Connector {
|
|
|
98
98
|
if (isV2) {
|
|
99
99
|
provider.on("session_delete", this.onDisconnect);
|
|
100
100
|
provider.on("display_uri", this.onDisplayUri);
|
|
101
|
-
const isChainsAuthorized = await
|
|
101
|
+
const isChainsAuthorized = await __privateMethod(this, _isChainsAuthorized, isChainsAuthorized_fn).call(this);
|
|
102
102
|
if (provider.session && !isChainsAuthorized)
|
|
103
103
|
await provider.disconnect();
|
|
104
104
|
if (!provider.session || provider.session && !isChainsAuthorized) {
|
|
@@ -122,17 +122,17 @@ var WalletConnectConnector = class extends _chunk5NCTPR6Cjs.Connector {
|
|
|
122
122
|
...this.isQrCode ? [
|
|
123
123
|
new Promise(
|
|
124
124
|
(_resolve, reject) => provider.on("display_uri", async (uri) => {
|
|
125
|
-
await
|
|
126
|
-
|
|
125
|
+
await __privateGet(this, _web3Modal)?.openModal({ uri });
|
|
126
|
+
__privateGet(this, _web3Modal)?.subscribeModal(({ open }) => {
|
|
127
127
|
if (!open)
|
|
128
128
|
reject(new Error("user rejected"));
|
|
129
|
-
})
|
|
129
|
+
});
|
|
130
130
|
})
|
|
131
131
|
)
|
|
132
132
|
] : []
|
|
133
133
|
]);
|
|
134
134
|
if (this.isQrCode)
|
|
135
|
-
|
|
135
|
+
__privateGet(this, _web3Modal)?.closeModal();
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
setTimeout(() => this.emit("message", { type: "connecting" }), 0);
|
|
@@ -147,30 +147,30 @@ var WalletConnectConnector = class extends _chunk5NCTPR6Cjs.Connector {
|
|
|
147
147
|
)
|
|
148
148
|
] : []
|
|
149
149
|
]);
|
|
150
|
-
const account =
|
|
150
|
+
const account = getAddress(accounts[0]);
|
|
151
151
|
const id = await this.getChainId();
|
|
152
152
|
const unsupported = this.isChainUnsupported(id);
|
|
153
153
|
if (isV1) {
|
|
154
|
-
const walletName =
|
|
154
|
+
const walletName = provider.connector?.peerMeta?.name ?? "";
|
|
155
155
|
const switchChainAllowedRegex = /(imtoken|metamask|omni|rainbow|trust wallet)/i;
|
|
156
156
|
if (switchChainAllowedRegex.test(walletName))
|
|
157
|
-
this.switchChain =
|
|
157
|
+
this.switchChain = __privateMethod(this, _switchChain, switchChain_fn);
|
|
158
158
|
} else
|
|
159
|
-
this.switchChain =
|
|
159
|
+
this.switchChain = __privateMethod(this, _switchChain, switchChain_fn);
|
|
160
160
|
return {
|
|
161
161
|
account,
|
|
162
162
|
chain: { id, unsupported },
|
|
163
|
-
provider: new
|
|
163
|
+
provider: new providers.Web3Provider(
|
|
164
164
|
provider
|
|
165
165
|
)
|
|
166
166
|
};
|
|
167
167
|
} catch (error) {
|
|
168
168
|
if (isV2 && this.isQrCode)
|
|
169
|
-
|
|
169
|
+
__privateGet(this, _web3Modal)?.closeModal();
|
|
170
170
|
if (/user closed modal|user rejected/i.test(
|
|
171
|
-
|
|
171
|
+
error?.message
|
|
172
172
|
)) {
|
|
173
|
-
throw new
|
|
173
|
+
throw new UserRejectedRequestError(error);
|
|
174
174
|
}
|
|
175
175
|
throw error;
|
|
176
176
|
}
|
|
@@ -202,43 +202,43 @@ var WalletConnectConnector = class extends _chunk5NCTPR6Cjs.Connector {
|
|
|
202
202
|
accounts = await provider.request({
|
|
203
203
|
method: "eth_accounts"
|
|
204
204
|
});
|
|
205
|
-
return
|
|
205
|
+
return getAddress(accounts[0]);
|
|
206
206
|
}
|
|
207
207
|
async getChainId() {
|
|
208
208
|
const provider = await this.getProvider();
|
|
209
209
|
if (this.version === "1")
|
|
210
|
-
return
|
|
211
|
-
return
|
|
210
|
+
return normalizeChainId(provider.chainId);
|
|
211
|
+
return getClient().data?.chain?.id ?? normalizeChainId(await provider.request({ method: "eth_chainId" }));
|
|
212
212
|
}
|
|
213
213
|
async getProvider({
|
|
214
214
|
chainId,
|
|
215
215
|
create
|
|
216
216
|
} = {}) {
|
|
217
217
|
if (this.options.version === "2") {
|
|
218
|
-
if (!
|
|
219
|
-
await
|
|
218
|
+
if (!__privateGet(this, _provider))
|
|
219
|
+
await __privateMethod(this, _createUniversalProvider, createUniversalProvider_fn).call(this);
|
|
220
220
|
if (chainId)
|
|
221
|
-
|
|
221
|
+
__privateGet(this, _provider).setDefaultChain(
|
|
222
222
|
`${defaultV2Config.namespace}:${chainId}`
|
|
223
223
|
);
|
|
224
|
-
return
|
|
225
|
-
} else if (!
|
|
226
|
-
const rpc = !
|
|
224
|
+
return __privateGet(this, _provider);
|
|
225
|
+
} else if (!__privateGet(this, _provider) || chainId || create) {
|
|
226
|
+
const rpc = !this.options?.infuraId ? this.chains.reduce(
|
|
227
227
|
(rpc2, chain) => ({
|
|
228
228
|
...rpc2,
|
|
229
229
|
[chain.id]: chain.rpcUrls.default.http[0]
|
|
230
230
|
}),
|
|
231
231
|
{}
|
|
232
232
|
) : {};
|
|
233
|
-
const WalletConnectProvider = (await
|
|
234
|
-
|
|
233
|
+
const WalletConnectProvider = (await import("@walletconnect/ethereum-provider")).default;
|
|
234
|
+
__privateSet(this, _provider, new WalletConnectProvider({
|
|
235
235
|
...this.options,
|
|
236
236
|
chainId,
|
|
237
|
-
rpc: { ...rpc, ...
|
|
237
|
+
rpc: { ...rpc, ...this.options?.rpc }
|
|
238
238
|
}));
|
|
239
|
-
return
|
|
239
|
+
return __privateGet(this, _provider);
|
|
240
240
|
}
|
|
241
|
-
return
|
|
241
|
+
return __privateGet(this, _provider);
|
|
242
242
|
}
|
|
243
243
|
async getSigner({ chainId } = {}) {
|
|
244
244
|
const [provider, account] = await Promise.all([
|
|
@@ -253,21 +253,21 @@ var WalletConnectConnector = class extends _chunk5NCTPR6Cjs.Connector {
|
|
|
253
253
|
async request(args) {
|
|
254
254
|
return await provider.request(
|
|
255
255
|
args,
|
|
256
|
-
`${defaultV2Config.namespace}:${
|
|
256
|
+
`${defaultV2Config.namespace}:${chainId ?? chainId_}`
|
|
257
257
|
);
|
|
258
258
|
}
|
|
259
259
|
};
|
|
260
260
|
}
|
|
261
|
-
return new
|
|
261
|
+
return new providers.Web3Provider(provider_, chainId).getSigner(account);
|
|
262
262
|
}
|
|
263
263
|
async isAuthorized() {
|
|
264
264
|
try {
|
|
265
265
|
const [account, isChainsAuthorized] = await Promise.all([
|
|
266
266
|
this.getAccount(),
|
|
267
|
-
|
|
267
|
+
__privateMethod(this, _isChainsAuthorized, isChainsAuthorized_fn).call(this)
|
|
268
268
|
]);
|
|
269
269
|
return !!account && isChainsAuthorized;
|
|
270
|
-
} catch
|
|
270
|
+
} catch {
|
|
271
271
|
return false;
|
|
272
272
|
}
|
|
273
273
|
}
|
|
@@ -277,35 +277,35 @@ _initUniversalProviderPromise = new WeakMap();
|
|
|
277
277
|
_web3Modal = new WeakMap();
|
|
278
278
|
_createWeb3Modal = new WeakSet();
|
|
279
279
|
createWeb3Modal_fn = async function() {
|
|
280
|
-
const { Web3Modal } = await
|
|
280
|
+
const { Web3Modal } = await import("@web3modal/standalone");
|
|
281
281
|
const { version } = this.options;
|
|
282
|
-
|
|
282
|
+
__privateSet(this, _web3Modal, new Web3Modal({
|
|
283
283
|
projectId: version === "2" ? this.options.projectId : void 0,
|
|
284
284
|
standaloneChains: this.namespacedChains
|
|
285
285
|
}));
|
|
286
286
|
};
|
|
287
287
|
_initUniversalProvider = new WeakSet();
|
|
288
288
|
initUniversalProvider_fn = async function() {
|
|
289
|
-
const WalletConnectProvider = (await
|
|
289
|
+
const WalletConnectProvider = (await import("@walletconnect/universal-provider")).default;
|
|
290
290
|
if (WalletConnectProvider) {
|
|
291
|
-
|
|
291
|
+
__privateSet(this, _provider, await WalletConnectProvider.init(
|
|
292
292
|
this.options
|
|
293
293
|
));
|
|
294
294
|
}
|
|
295
295
|
};
|
|
296
296
|
_createUniversalProvider = new WeakSet();
|
|
297
297
|
createUniversalProvider_fn = async function() {
|
|
298
|
-
if (!
|
|
299
|
-
|
|
298
|
+
if (!__privateGet(this, _initUniversalProviderPromise)) {
|
|
299
|
+
__privateSet(this, _initUniversalProviderPromise, __privateMethod(this, _initUniversalProvider, initUniversalProvider_fn).call(this));
|
|
300
300
|
}
|
|
301
|
-
return
|
|
301
|
+
return __privateGet(this, _initUniversalProviderPromise);
|
|
302
302
|
};
|
|
303
303
|
_isChainsAuthorized = new WeakSet();
|
|
304
304
|
isChainsAuthorized_fn = async function() {
|
|
305
305
|
const provider = await this.getProvider();
|
|
306
306
|
if (this.version === "1")
|
|
307
307
|
return true;
|
|
308
|
-
const providerChains =
|
|
308
|
+
const providerChains = provider.namespaces?.[defaultV2Config.namespace]?.chains || [];
|
|
309
309
|
const authorizedChainIds = providerChains.map(
|
|
310
310
|
(chain) => parseInt(chain.split(":")[1] || "")
|
|
311
311
|
);
|
|
@@ -314,7 +314,7 @@ isChainsAuthorized_fn = async function() {
|
|
|
314
314
|
_switchChain = new WeakSet();
|
|
315
315
|
switchChain_fn = async function(chainId) {
|
|
316
316
|
const provider = await this.getProvider();
|
|
317
|
-
const id =
|
|
317
|
+
const id = hexValue(chainId);
|
|
318
318
|
try {
|
|
319
319
|
await Promise.race([
|
|
320
320
|
provider.request({
|
|
@@ -323,7 +323,7 @@ switchChain_fn = async function(chainId) {
|
|
|
323
323
|
}),
|
|
324
324
|
new Promise(
|
|
325
325
|
(res) => this.on("change", ({ chain }) => {
|
|
326
|
-
if (
|
|
326
|
+
if (chain?.id === chainId)
|
|
327
327
|
res(chainId);
|
|
328
328
|
})
|
|
329
329
|
)
|
|
@@ -335,20 +335,20 @@ switchChain_fn = async function(chainId) {
|
|
|
335
335
|
);
|
|
336
336
|
this.onChainChanged(chainId);
|
|
337
337
|
}
|
|
338
|
-
return
|
|
338
|
+
return this.chains.find((x) => x.id === chainId) ?? {
|
|
339
339
|
id: chainId,
|
|
340
340
|
name: `Chain ${id}`,
|
|
341
341
|
network: `${id}`,
|
|
342
342
|
nativeCurrency: { decimals: 18, name: "Ether", symbol: "ETH" },
|
|
343
343
|
rpcUrls: { default: { http: [""] }, public: { http: [""] } }
|
|
344
|
-
}
|
|
344
|
+
};
|
|
345
345
|
} catch (error) {
|
|
346
|
-
const message = typeof error === "string" ? error :
|
|
346
|
+
const message = typeof error === "string" ? error : error?.message;
|
|
347
347
|
if (/user rejected request/i.test(message))
|
|
348
|
-
throw new
|
|
349
|
-
throw new
|
|
348
|
+
throw new UserRejectedRequestError(error);
|
|
349
|
+
throw new SwitchChainError(error);
|
|
350
350
|
}
|
|
351
351
|
};
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
352
|
+
export {
|
|
353
|
+
WalletConnectConnector
|
|
354
|
+
};
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@wagmi/connectors",
|
|
3
3
|
"description": "A collection of connectors for wagmi",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "0.2.2
|
|
5
|
+
"version": "0.2.2",
|
|
6
6
|
"peerDependencies": {
|
|
7
7
|
"@wagmi/core": ">=0.9.x",
|
|
8
8
|
"ethers": ">=5.5.1",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"@wagmi/core": "^0.8.19",
|
|
30
30
|
"ethers": "^5.7.2"
|
|
31
31
|
},
|
|
32
|
+
"type": "module",
|
|
32
33
|
"main": "dist/index.js",
|
|
33
34
|
"types": "dist/index.d.ts",
|
|
34
35
|
"exports": {
|