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