@wagmi/connectors 0.1.7 → 0.1.8
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/coinbaseWallet.d.ts +5 -1
- package/dist/walletConnect.d.ts +2 -0
- package/dist/walletConnect.js +81 -47
- package/package.json +3 -3
package/dist/coinbaseWallet.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { C as Connector } from './base-6b5431a5.js';
|
|
|
6
6
|
import 'abitype';
|
|
7
7
|
import 'eventemitter3';
|
|
8
8
|
|
|
9
|
-
declare type Options = CoinbaseWalletSDKOptions & {
|
|
9
|
+
declare type Options = Omit<CoinbaseWalletSDKOptions, 'reloadOnDisconnect'> & {
|
|
10
10
|
/**
|
|
11
11
|
* Fallback Ethereum JSON RPC URL
|
|
12
12
|
* @default ""
|
|
@@ -17,6 +17,10 @@ declare type Options = CoinbaseWalletSDKOptions & {
|
|
|
17
17
|
* @default 1
|
|
18
18
|
*/
|
|
19
19
|
chainId?: number;
|
|
20
|
+
/**
|
|
21
|
+
* Whether or not to reload dapp automatically after disconnect.
|
|
22
|
+
*/
|
|
23
|
+
reloadOnDisconnect?: boolean;
|
|
20
24
|
};
|
|
21
25
|
declare class CoinbaseWalletConnector extends Connector<CoinbaseWalletProvider, Options, providers.JsonRpcSigner> {
|
|
22
26
|
#private;
|
package/dist/walletConnect.d.ts
CHANGED
|
@@ -31,6 +31,8 @@ declare class WalletConnectConnector extends Connector<WalletConnectProvider | U
|
|
|
31
31
|
chains?: Chain[];
|
|
32
32
|
options: WalletConnectOptions;
|
|
33
33
|
});
|
|
34
|
+
get isQrCode(): boolean;
|
|
35
|
+
get namespacedChains(): string[];
|
|
34
36
|
get version(): "1" | "2" | undefined;
|
|
35
37
|
connect({ chainId }?: {
|
|
36
38
|
chainId?: number;
|
package/dist/walletConnect.js
CHANGED
|
@@ -27,16 +27,20 @@ var defaultV2Config = {
|
|
|
27
27
|
],
|
|
28
28
|
events: ["accountsChanged", "chainChanged"]
|
|
29
29
|
};
|
|
30
|
-
var _provider, _isChainsAuthorized, isChainsAuthorized_fn, _switchChain, switchChain_fn;
|
|
30
|
+
var _provider, _universalProviderPromise, _web3Modal, _createWeb3Modal, createWeb3Modal_fn, _getUniversalProvider, getUniversalProvider_fn, _isChainsAuthorized, isChainsAuthorized_fn, _switchChain, switchChain_fn;
|
|
31
31
|
var WalletConnectConnector = class extends Connector {
|
|
32
32
|
constructor(config) {
|
|
33
33
|
super(config);
|
|
34
|
+
__privateAdd(this, _createWeb3Modal);
|
|
35
|
+
__privateAdd(this, _getUniversalProvider);
|
|
34
36
|
__privateAdd(this, _isChainsAuthorized);
|
|
35
37
|
__privateAdd(this, _switchChain);
|
|
36
38
|
__publicField(this, "id", "walletConnect");
|
|
37
39
|
__publicField(this, "name", "WalletConnect");
|
|
38
40
|
__publicField(this, "ready", true);
|
|
39
41
|
__privateAdd(this, _provider, void 0);
|
|
42
|
+
__privateAdd(this, _universalProviderPromise, void 0);
|
|
43
|
+
__privateAdd(this, _web3Modal, void 0);
|
|
40
44
|
__publicField(this, "onAccountsChanged", (accounts) => {
|
|
41
45
|
if (accounts.length === 0)
|
|
42
46
|
this.emit("disconnect");
|
|
@@ -54,6 +58,19 @@ var WalletConnectConnector = class extends Connector {
|
|
|
54
58
|
__publicField(this, "onDisplayUri", (uri) => {
|
|
55
59
|
this.emit("message", { type: "display_uri", data: uri });
|
|
56
60
|
});
|
|
61
|
+
if (this.version === "2") {
|
|
62
|
+
__privateMethod(this, _getUniversalProvider, getUniversalProvider_fn).call(this);
|
|
63
|
+
if (this.isQrCode)
|
|
64
|
+
__privateMethod(this, _createWeb3Modal, createWeb3Modal_fn).call(this);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
get isQrCode() {
|
|
68
|
+
return this.options.qrcode !== false;
|
|
69
|
+
}
|
|
70
|
+
get namespacedChains() {
|
|
71
|
+
return this.chains.map(
|
|
72
|
+
(chain) => `${defaultV2Config.namespace}:${chain.id}`
|
|
73
|
+
);
|
|
57
74
|
}
|
|
58
75
|
get version() {
|
|
59
76
|
if ("version" in this.options)
|
|
@@ -61,6 +78,8 @@ var WalletConnectConnector = class extends Connector {
|
|
|
61
78
|
return "1";
|
|
62
79
|
}
|
|
63
80
|
async connect({ chainId } = {}) {
|
|
81
|
+
const isV1 = this.version === "1";
|
|
82
|
+
const isV2 = this.version === "2";
|
|
64
83
|
try {
|
|
65
84
|
let targetChainId = chainId;
|
|
66
85
|
if (!targetChainId) {
|
|
@@ -70,12 +89,12 @@ var WalletConnectConnector = class extends Connector {
|
|
|
70
89
|
}
|
|
71
90
|
const provider = await this.getProvider({
|
|
72
91
|
chainId: targetChainId,
|
|
73
|
-
create:
|
|
92
|
+
create: isV1
|
|
74
93
|
});
|
|
75
94
|
provider.on("accountsChanged", this.onAccountsChanged);
|
|
76
95
|
provider.on("chainChanged", this.onChainChanged);
|
|
77
96
|
provider.on("disconnect", this.onDisconnect);
|
|
78
|
-
if (
|
|
97
|
+
if (isV2) {
|
|
79
98
|
provider.on("session_delete", this.onDisconnect);
|
|
80
99
|
provider.on("display_uri", this.onDisplayUri);
|
|
81
100
|
const isChainsAuthorized = await __privateMethod(this, _isChainsAuthorized, isChainsAuthorized_fn).call(this);
|
|
@@ -88,9 +107,7 @@ var WalletConnectConnector = class extends Connector {
|
|
|
88
107
|
[defaultV2Config.namespace]: {
|
|
89
108
|
methods: defaultV2Config.methods,
|
|
90
109
|
events: defaultV2Config.events,
|
|
91
|
-
chains: this.
|
|
92
|
-
(chain) => `${defaultV2Config.namespace}:${chain.id}`
|
|
93
|
-
),
|
|
110
|
+
chains: this.namespacedChains,
|
|
94
111
|
rpcMap: this.chains.reduce(
|
|
95
112
|
(rpc, chain) => ({
|
|
96
113
|
...rpc,
|
|
@@ -101,26 +118,26 @@ var WalletConnectConnector = class extends Connector {
|
|
|
101
118
|
}
|
|
102
119
|
}
|
|
103
120
|
}),
|
|
104
|
-
...this.
|
|
121
|
+
...this.isQrCode ? [
|
|
105
122
|
new Promise(
|
|
106
|
-
(
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
)
|
|
112
|
-
)
|
|
123
|
+
(_resolve, reject) => provider.on("display_uri", async (uri) => {
|
|
124
|
+
await __privateGet(this, _web3Modal)?.openModal({ uri });
|
|
125
|
+
__privateGet(this, _web3Modal)?.subscribeModal(({ open }) => {
|
|
126
|
+
if (!open)
|
|
127
|
+
reject(new Error("user rejected"));
|
|
128
|
+
});
|
|
129
|
+
})
|
|
113
130
|
)
|
|
114
131
|
] : []
|
|
115
132
|
]);
|
|
116
|
-
if (this.
|
|
117
|
-
(
|
|
133
|
+
if (this.isQrCode)
|
|
134
|
+
__privateGet(this, _web3Modal)?.closeModal();
|
|
118
135
|
}
|
|
119
136
|
}
|
|
120
137
|
setTimeout(() => this.emit("message", { type: "connecting" }), 0);
|
|
121
138
|
const accounts = await Promise.race([
|
|
122
139
|
provider.enable(),
|
|
123
|
-
...
|
|
140
|
+
...isV1 && this.isQrCode ? [
|
|
124
141
|
new Promise(
|
|
125
142
|
(_res, reject) => provider.connector.on(
|
|
126
143
|
"disconnect",
|
|
@@ -132,7 +149,7 @@ var WalletConnectConnector = class extends Connector {
|
|
|
132
149
|
const account = getAddress(accounts[0]);
|
|
133
150
|
const id = await this.getChainId();
|
|
134
151
|
const unsupported = this.isChainUnsupported(id);
|
|
135
|
-
if (
|
|
152
|
+
if (isV1) {
|
|
136
153
|
const walletName = provider.connector?.peerMeta?.name ?? "";
|
|
137
154
|
const switchChainAllowedRegex = /(imtoken|metamask|omni|rainbow|trust wallet)/i;
|
|
138
155
|
if (switchChainAllowedRegex.test(walletName))
|
|
@@ -147,8 +164,8 @@ var WalletConnectConnector = class extends Connector {
|
|
|
147
164
|
)
|
|
148
165
|
};
|
|
149
166
|
} catch (error) {
|
|
150
|
-
if (
|
|
151
|
-
(
|
|
167
|
+
if (isV2 && this.isQrCode)
|
|
168
|
+
__privateGet(this, _web3Modal)?.closeModal();
|
|
152
169
|
if (/user closed modal|user rejected/i.test(
|
|
153
170
|
error?.message
|
|
154
171
|
)) {
|
|
@@ -196,33 +213,29 @@ var WalletConnectConnector = class extends Connector {
|
|
|
196
213
|
chainId,
|
|
197
214
|
create
|
|
198
215
|
} = {}) {
|
|
199
|
-
if (
|
|
200
|
-
if (this
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
rpc: { ...rpc, ...this.options?.rpc }
|
|
223
|
-
}));
|
|
224
|
-
return __privateGet(this, _provider);
|
|
225
|
-
}
|
|
216
|
+
if (this.options.version === "2") {
|
|
217
|
+
if (!__privateGet(this, _provider) || create)
|
|
218
|
+
__privateSet(this, _provider, await __privateMethod(this, _getUniversalProvider, getUniversalProvider_fn).call(this));
|
|
219
|
+
if (chainId)
|
|
220
|
+
__privateGet(this, _provider).setDefaultChain(
|
|
221
|
+
`${defaultV2Config.namespace}:${chainId}`
|
|
222
|
+
);
|
|
223
|
+
return __privateGet(this, _provider);
|
|
224
|
+
} else if (!__privateGet(this, _provider) || chainId || create) {
|
|
225
|
+
const rpc = !this.options?.infuraId ? this.chains.reduce(
|
|
226
|
+
(rpc2, chain) => ({
|
|
227
|
+
...rpc2,
|
|
228
|
+
[chain.id]: chain.rpcUrls.default.http[0]
|
|
229
|
+
}),
|
|
230
|
+
{}
|
|
231
|
+
) : {};
|
|
232
|
+
const WalletConnectProvider = (await import("@walletconnect/ethereum-provider")).default;
|
|
233
|
+
__privateSet(this, _provider, new WalletConnectProvider({
|
|
234
|
+
...this.options,
|
|
235
|
+
chainId,
|
|
236
|
+
rpc: { ...rpc, ...this.options?.rpc }
|
|
237
|
+
}));
|
|
238
|
+
return __privateGet(this, _provider);
|
|
226
239
|
}
|
|
227
240
|
return __privateGet(this, _provider);
|
|
228
241
|
}
|
|
@@ -259,6 +272,27 @@ var WalletConnectConnector = class extends Connector {
|
|
|
259
272
|
}
|
|
260
273
|
};
|
|
261
274
|
_provider = new WeakMap();
|
|
275
|
+
_universalProviderPromise = new WeakMap();
|
|
276
|
+
_web3Modal = new WeakMap();
|
|
277
|
+
_createWeb3Modal = new WeakSet();
|
|
278
|
+
createWeb3Modal_fn = async function() {
|
|
279
|
+
const { Web3Modal } = await import("@web3modal/standalone");
|
|
280
|
+
const { version } = this.options;
|
|
281
|
+
__privateSet(this, _web3Modal, new Web3Modal({
|
|
282
|
+
projectId: version === "2" ? this.options.projectId : void 0,
|
|
283
|
+
standaloneChains: this.namespacedChains
|
|
284
|
+
}));
|
|
285
|
+
};
|
|
286
|
+
_getUniversalProvider = new WeakSet();
|
|
287
|
+
getUniversalProvider_fn = async function() {
|
|
288
|
+
if (!__privateGet(this, _universalProviderPromise)) {
|
|
289
|
+
const WalletConnectProvider = (await import("@walletconnect/universal-provider")).default;
|
|
290
|
+
__privateSet(this, _universalProviderPromise, WalletConnectProvider.init(
|
|
291
|
+
this.options
|
|
292
|
+
));
|
|
293
|
+
}
|
|
294
|
+
return __privateGet(this, _universalProviderPromise);
|
|
295
|
+
};
|
|
262
296
|
_isChainsAuthorized = new WeakSet();
|
|
263
297
|
isChainsAuthorized_fn = async function() {
|
|
264
298
|
const provider = await this.getProvider();
|
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.1.
|
|
5
|
+
"version": "0.1.8",
|
|
6
6
|
"peerDependencies": {
|
|
7
7
|
"@wagmi/core": "0.8.x",
|
|
8
8
|
"ethers": "^5.0.0"
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"@coinbase/wallet-sdk": "^3.5.4",
|
|
17
17
|
"@ledgerhq/connect-kit-loader": "^1.0.1",
|
|
18
18
|
"@walletconnect/ethereum-provider": "^1.8.0",
|
|
19
|
-
"@
|
|
20
|
-
"@walletconnect/universal-provider": "^2.2.
|
|
19
|
+
"@web3modal/standalone": "^2.0.0-rc.2",
|
|
20
|
+
"@walletconnect/universal-provider": "^2.2.1",
|
|
21
21
|
"abitype": "^0.1.8",
|
|
22
22
|
"eventemitter3": "^4.0.7"
|
|
23
23
|
},
|