@wagmi/connectors 3.1.10 → 3.1.11-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-OQILYQDO.js +4 -4
- package/dist/chunk-P4NRLOY7.js +65 -65
- package/dist/chunk-UGBGYVBH.js +5 -5
- package/dist/chunk-W65LBPLT.js +13 -13
- package/dist/coinbaseWallet.js +51 -51
- package/dist/index.js +16 -16
- package/dist/injected.js +9 -9
- package/dist/metaMask.js +34 -34
- package/dist/mock/index.js +55 -55
- package/dist/safe.js +42 -42
- package/dist/walletConnect.js +101 -101
- package/dist/walletConnectLegacy.js +51 -51
- package/package.json +3 -4
package/dist/walletConnect.js
CHANGED
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } 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 _chunkW65LBPLTjs = require('./chunk-W65LBPLT.js');
|
|
8
8
|
|
|
9
9
|
// src/walletConnect.ts
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
var _utils = require('@walletconnect/utils');
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
var _viem = require('viem');
|
|
19
19
|
var NAMESPACE = "eip155";
|
|
20
20
|
var STORE_KEY = "store";
|
|
21
21
|
var REQUESTED_CHAINS_KEY = "requestedChains";
|
|
22
22
|
var ADD_ETH_CHAIN_METHOD = "wallet_addEthereumChain";
|
|
23
23
|
var _provider, _initProviderPromise, _createProvider, createProvider_fn, _initProvider, initProvider_fn, _isChainsStale, isChainsStale_fn, _setupListeners, setupListeners_fn, _removeListeners, removeListeners_fn, _setRequestedChainsIds, setRequestedChainsIds_fn, _getRequestedChainsIds, getRequestedChainsIds_fn, _getNamespaceChainsIds, getNamespaceChainsIds_fn, _getNamespaceMethods, getNamespaceMethods_fn;
|
|
24
|
-
var WalletConnectConnector = class extends Connector {
|
|
24
|
+
var WalletConnectConnector = class extends _chunkW65LBPLTjs.Connector {
|
|
25
25
|
constructor(config) {
|
|
26
26
|
super({
|
|
27
27
|
...config,
|
|
28
28
|
options: { isNewChainsStale: true, ...config.options }
|
|
29
29
|
});
|
|
30
|
-
__privateAdd(this, _createProvider);
|
|
31
|
-
__privateAdd(this, _initProvider);
|
|
32
|
-
__privateAdd(this, _isChainsStale);
|
|
33
|
-
__privateAdd(this, _setupListeners);
|
|
34
|
-
__privateAdd(this, _removeListeners);
|
|
35
|
-
__privateAdd(this, _setRequestedChainsIds);
|
|
36
|
-
__privateAdd(this, _getRequestedChainsIds);
|
|
37
|
-
__privateAdd(this, _getNamespaceChainsIds);
|
|
38
|
-
__privateAdd(this, _getNamespaceMethods);
|
|
30
|
+
_chunkW65LBPLTjs.__privateAdd.call(void 0, this, _createProvider);
|
|
31
|
+
_chunkW65LBPLTjs.__privateAdd.call(void 0, this, _initProvider);
|
|
32
|
+
_chunkW65LBPLTjs.__privateAdd.call(void 0, this, _isChainsStale);
|
|
33
|
+
_chunkW65LBPLTjs.__privateAdd.call(void 0, this, _setupListeners);
|
|
34
|
+
_chunkW65LBPLTjs.__privateAdd.call(void 0, this, _removeListeners);
|
|
35
|
+
_chunkW65LBPLTjs.__privateAdd.call(void 0, this, _setRequestedChainsIds);
|
|
36
|
+
_chunkW65LBPLTjs.__privateAdd.call(void 0, this, _getRequestedChainsIds);
|
|
37
|
+
_chunkW65LBPLTjs.__privateAdd.call(void 0, this, _getNamespaceChainsIds);
|
|
38
|
+
_chunkW65LBPLTjs.__privateAdd.call(void 0, this, _getNamespaceMethods);
|
|
39
39
|
this.id = "walletConnect";
|
|
40
40
|
this.name = "WalletConnect";
|
|
41
41
|
this.ready = true;
|
|
42
|
-
__privateAdd(this, _provider, void 0);
|
|
43
|
-
__privateAdd(this, _initProviderPromise, void 0);
|
|
42
|
+
_chunkW65LBPLTjs.__privateAdd.call(void 0, this, _provider, void 0);
|
|
43
|
+
_chunkW65LBPLTjs.__privateAdd.call(void 0, this, _initProviderPromise, void 0);
|
|
44
44
|
this.onAccountsChanged = (accounts) => {
|
|
45
45
|
if (accounts.length === 0)
|
|
46
46
|
this.emit("disconnect");
|
|
47
47
|
else
|
|
48
|
-
this.emit("change", { account: getAddress(accounts[0]) });
|
|
48
|
+
this.emit("change", { account: _viem.getAddress.call(void 0, accounts[0]) });
|
|
49
49
|
};
|
|
50
50
|
this.onChainChanged = (chainId) => {
|
|
51
51
|
const id = Number(chainId);
|
|
@@ -53,7 +53,7 @@ var WalletConnectConnector = class extends Connector {
|
|
|
53
53
|
this.emit("change", { chain: { id, unsupported } });
|
|
54
54
|
};
|
|
55
55
|
this.onDisconnect = () => {
|
|
56
|
-
__privateMethod(this, _setRequestedChainsIds, setRequestedChainsIds_fn).call(this, []);
|
|
56
|
+
_chunkW65LBPLTjs.__privateMethod.call(void 0, this, _setRequestedChainsIds, setRequestedChainsIds_fn).call(this, []);
|
|
57
57
|
this.emit("disconnect");
|
|
58
58
|
};
|
|
59
59
|
this.onDisplayUri = (uri) => {
|
|
@@ -62,24 +62,24 @@ var WalletConnectConnector = class extends Connector {
|
|
|
62
62
|
this.onConnect = () => {
|
|
63
63
|
this.emit("connect", {});
|
|
64
64
|
};
|
|
65
|
-
__privateMethod(this, _createProvider, createProvider_fn).call(this);
|
|
65
|
+
_chunkW65LBPLTjs.__privateMethod.call(void 0, this, _createProvider, createProvider_fn).call(this);
|
|
66
66
|
}
|
|
67
67
|
async connect({ chainId, pairingTopic } = {}) {
|
|
68
68
|
try {
|
|
69
69
|
let targetChainId = chainId;
|
|
70
70
|
if (!targetChainId) {
|
|
71
|
-
const store = this.storage
|
|
72
|
-
const lastUsedChainId = store
|
|
71
|
+
const store = _optionalChain([this, 'access', _ => _.storage, 'optionalAccess', _2 => _2.getItem, 'call', _3 => _3(STORE_KEY)]);
|
|
72
|
+
const lastUsedChainId = _optionalChain([store, 'optionalAccess', _4 => _4.state, 'optionalAccess', _5 => _5.data, 'optionalAccess', _6 => _6.chain, 'optionalAccess', _7 => _7.id]);
|
|
73
73
|
if (lastUsedChainId && !this.isChainUnsupported(lastUsedChainId))
|
|
74
74
|
targetChainId = lastUsedChainId;
|
|
75
75
|
else
|
|
76
|
-
targetChainId = this.chains[0]
|
|
76
|
+
targetChainId = _optionalChain([this, 'access', _8 => _8.chains, 'access', _9 => _9[0], 'optionalAccess', _10 => _10.id]);
|
|
77
77
|
}
|
|
78
78
|
if (!targetChainId)
|
|
79
79
|
throw new Error("No chains found on connector.");
|
|
80
80
|
const provider = await this.getProvider();
|
|
81
|
-
__privateMethod(this, _setupListeners, setupListeners_fn).call(this);
|
|
82
|
-
const isChainsStale = __privateMethod(this, _isChainsStale, isChainsStale_fn).call(this);
|
|
81
|
+
_chunkW65LBPLTjs.__privateMethod.call(void 0, this, _setupListeners, setupListeners_fn).call(this);
|
|
82
|
+
const isChainsStale = _chunkW65LBPLTjs.__privateMethod.call(void 0, this, _isChainsStale, isChainsStale_fn).call(this);
|
|
83
83
|
if (provider.session && isChainsStale)
|
|
84
84
|
await provider.disconnect();
|
|
85
85
|
if (!provider.session || isChainsStale) {
|
|
@@ -89,10 +89,10 @@ var WalletConnectConnector = class extends Connector {
|
|
|
89
89
|
pairingTopic,
|
|
90
90
|
optionalChains: [targetChainId, ...optionalChains]
|
|
91
91
|
});
|
|
92
|
-
__privateMethod(this, _setRequestedChainsIds, setRequestedChainsIds_fn).call(this, this.chains.map(({ id: id2 }) => id2));
|
|
92
|
+
_chunkW65LBPLTjs.__privateMethod.call(void 0, this, _setRequestedChainsIds, setRequestedChainsIds_fn).call(this, this.chains.map(({ id: id2 }) => id2));
|
|
93
93
|
}
|
|
94
94
|
const accounts = await provider.enable();
|
|
95
|
-
const account = getAddress(accounts[0]);
|
|
95
|
+
const account = _viem.getAddress.call(void 0, accounts[0]);
|
|
96
96
|
const id = await this.getChainId();
|
|
97
97
|
const unsupported = this.isChainUnsupported(id);
|
|
98
98
|
return {
|
|
@@ -100,8 +100,8 @@ var WalletConnectConnector = class extends Connector {
|
|
|
100
100
|
chain: { id, unsupported }
|
|
101
101
|
};
|
|
102
102
|
} catch (error) {
|
|
103
|
-
if (/user rejected/i.test(error
|
|
104
|
-
throw new UserRejectedRequestError(error);
|
|
103
|
+
if (/user rejected/i.test(_optionalChain([error, 'optionalAccess', _11 => _11.message]))) {
|
|
104
|
+
throw new (0, _viem.UserRejectedRequestError)(error);
|
|
105
105
|
}
|
|
106
106
|
throw error;
|
|
107
107
|
}
|
|
@@ -114,24 +114,24 @@ var WalletConnectConnector = class extends Connector {
|
|
|
114
114
|
if (!/No matching key/i.test(error.message))
|
|
115
115
|
throw error;
|
|
116
116
|
} finally {
|
|
117
|
-
__privateMethod(this, _removeListeners, removeListeners_fn).call(this);
|
|
118
|
-
__privateMethod(this, _setRequestedChainsIds, setRequestedChainsIds_fn).call(this, []);
|
|
117
|
+
_chunkW65LBPLTjs.__privateMethod.call(void 0, this, _removeListeners, removeListeners_fn).call(this);
|
|
118
|
+
_chunkW65LBPLTjs.__privateMethod.call(void 0, this, _setRequestedChainsIds, setRequestedChainsIds_fn).call(this, []);
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
async getAccount() {
|
|
122
122
|
const { accounts } = await this.getProvider();
|
|
123
|
-
return getAddress(accounts[0]);
|
|
123
|
+
return _viem.getAddress.call(void 0, accounts[0]);
|
|
124
124
|
}
|
|
125
125
|
async getChainId() {
|
|
126
126
|
const { chainId } = await this.getProvider();
|
|
127
127
|
return chainId;
|
|
128
128
|
}
|
|
129
129
|
async getProvider({ chainId } = {}) {
|
|
130
|
-
if (!__privateGet(this, _provider))
|
|
131
|
-
await __privateMethod(this, _createProvider, createProvider_fn).call(this);
|
|
130
|
+
if (!_chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider))
|
|
131
|
+
await _chunkW65LBPLTjs.__privateMethod.call(void 0, this, _createProvider, createProvider_fn).call(this);
|
|
132
132
|
if (chainId)
|
|
133
133
|
await this.switchChain(chainId);
|
|
134
|
-
return __privateGet(this, _provider);
|
|
134
|
+
return _chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider);
|
|
135
135
|
}
|
|
136
136
|
async getWalletClient({
|
|
137
137
|
chainId
|
|
@@ -143,10 +143,10 @@ var WalletConnectConnector = class extends Connector {
|
|
|
143
143
|
const chain = this.chains.find((x) => x.id === chainId);
|
|
144
144
|
if (!provider)
|
|
145
145
|
throw new Error("provider is required.");
|
|
146
|
-
return createWalletClient({
|
|
146
|
+
return _viem.createWalletClient.call(void 0, {
|
|
147
147
|
account,
|
|
148
148
|
chain,
|
|
149
|
-
transport: custom(provider)
|
|
149
|
+
transport: _viem.custom.call(void 0, provider)
|
|
150
150
|
});
|
|
151
151
|
}
|
|
152
152
|
async isAuthorized() {
|
|
@@ -155,58 +155,58 @@ var WalletConnectConnector = class extends Connector {
|
|
|
155
155
|
this.getAccount(),
|
|
156
156
|
this.getProvider()
|
|
157
157
|
]);
|
|
158
|
-
const isChainsStale = __privateMethod(this, _isChainsStale, isChainsStale_fn).call(this);
|
|
158
|
+
const isChainsStale = _chunkW65LBPLTjs.__privateMethod.call(void 0, this, _isChainsStale, isChainsStale_fn).call(this);
|
|
159
159
|
if (!account)
|
|
160
160
|
return false;
|
|
161
161
|
if (isChainsStale && provider.session) {
|
|
162
162
|
try {
|
|
163
163
|
await provider.disconnect();
|
|
164
|
-
} catch {
|
|
164
|
+
} catch (e) {
|
|
165
165
|
}
|
|
166
166
|
return false;
|
|
167
167
|
}
|
|
168
168
|
return true;
|
|
169
|
-
} catch {
|
|
169
|
+
} catch (e2) {
|
|
170
170
|
return false;
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
173
|
async switchChain(chainId) {
|
|
174
174
|
const chain = this.chains.find((chain2) => chain2.id === chainId);
|
|
175
175
|
if (!chain)
|
|
176
|
-
throw new SwitchChainError(new Error("chain not found on connector."));
|
|
176
|
+
throw new (0, _viem.SwitchChainError)(new Error("chain not found on connector."));
|
|
177
177
|
try {
|
|
178
178
|
const provider = await this.getProvider();
|
|
179
|
-
const namespaceChains = __privateMethod(this, _getNamespaceChainsIds, getNamespaceChainsIds_fn).call(this);
|
|
180
|
-
const namespaceMethods = __privateMethod(this, _getNamespaceMethods, getNamespaceMethods_fn).call(this);
|
|
179
|
+
const namespaceChains = _chunkW65LBPLTjs.__privateMethod.call(void 0, this, _getNamespaceChainsIds, getNamespaceChainsIds_fn).call(this);
|
|
180
|
+
const namespaceMethods = _chunkW65LBPLTjs.__privateMethod.call(void 0, this, _getNamespaceMethods, getNamespaceMethods_fn).call(this);
|
|
181
181
|
const isChainApproved = namespaceChains.includes(chainId);
|
|
182
182
|
if (!isChainApproved && namespaceMethods.includes(ADD_ETH_CHAIN_METHOD)) {
|
|
183
183
|
await provider.request({
|
|
184
184
|
method: ADD_ETH_CHAIN_METHOD,
|
|
185
185
|
params: [
|
|
186
186
|
{
|
|
187
|
-
chainId: numberToHex(chain.id),
|
|
188
|
-
blockExplorerUrls: [chain.blockExplorers
|
|
187
|
+
chainId: _viem.numberToHex.call(void 0, chain.id),
|
|
188
|
+
blockExplorerUrls: [_optionalChain([chain, 'access', _12 => _12.blockExplorers, 'optionalAccess', _13 => _13.default, 'optionalAccess', _14 => _14.url])],
|
|
189
189
|
chainName: chain.name,
|
|
190
190
|
nativeCurrency: chain.nativeCurrency,
|
|
191
191
|
rpcUrls: [...chain.rpcUrls.default.http]
|
|
192
192
|
}
|
|
193
193
|
]
|
|
194
194
|
});
|
|
195
|
-
const requestedChains = __privateMethod(this, _getRequestedChainsIds, getRequestedChainsIds_fn).call(this);
|
|
195
|
+
const requestedChains = _chunkW65LBPLTjs.__privateMethod.call(void 0, this, _getRequestedChainsIds, getRequestedChainsIds_fn).call(this);
|
|
196
196
|
requestedChains.push(chainId);
|
|
197
|
-
__privateMethod(this, _setRequestedChainsIds, setRequestedChainsIds_fn).call(this, requestedChains);
|
|
197
|
+
_chunkW65LBPLTjs.__privateMethod.call(void 0, this, _setRequestedChainsIds, setRequestedChainsIds_fn).call(this, requestedChains);
|
|
198
198
|
}
|
|
199
199
|
await provider.request({
|
|
200
200
|
method: "wallet_switchEthereumChain",
|
|
201
|
-
params: [{ chainId: numberToHex(chainId) }]
|
|
201
|
+
params: [{ chainId: _viem.numberToHex.call(void 0, chainId) }]
|
|
202
202
|
});
|
|
203
203
|
return chain;
|
|
204
204
|
} catch (error) {
|
|
205
|
-
const message = typeof error === "string" ? error : error
|
|
205
|
+
const message = typeof error === "string" ? error : _optionalChain([error, 'optionalAccess', _15 => _15.message]);
|
|
206
206
|
if (/user rejected request/i.test(message)) {
|
|
207
|
-
throw new UserRejectedRequestError(error);
|
|
207
|
+
throw new (0, _viem.UserRejectedRequestError)(error);
|
|
208
208
|
}
|
|
209
|
-
throw new SwitchChainError(error);
|
|
209
|
+
throw new (0, _viem.SwitchChainError)(error);
|
|
210
210
|
}
|
|
211
211
|
}
|
|
212
212
|
};
|
|
@@ -214,14 +214,14 @@ _provider = new WeakMap();
|
|
|
214
214
|
_initProviderPromise = new WeakMap();
|
|
215
215
|
_createProvider = new WeakSet();
|
|
216
216
|
createProvider_fn = async function() {
|
|
217
|
-
if (!__privateGet(this, _initProviderPromise) && typeof window !== "undefined") {
|
|
218
|
-
__privateSet(this, _initProviderPromise, __privateMethod(this, _initProvider, initProvider_fn).call(this));
|
|
217
|
+
if (!_chunkW65LBPLTjs.__privateGet.call(void 0, this, _initProviderPromise) && typeof window !== "undefined") {
|
|
218
|
+
_chunkW65LBPLTjs.__privateSet.call(void 0, this, _initProviderPromise, _chunkW65LBPLTjs.__privateMethod.call(void 0, this, _initProvider, initProvider_fn).call(this));
|
|
219
219
|
}
|
|
220
|
-
return __privateGet(this, _initProviderPromise);
|
|
220
|
+
return _chunkW65LBPLTjs.__privateGet.call(void 0, this, _initProviderPromise);
|
|
221
221
|
};
|
|
222
222
|
_initProvider = new WeakSet();
|
|
223
223
|
initProvider_fn = async function() {
|
|
224
|
-
const { EthereumProvider } = await
|
|
224
|
+
const { EthereumProvider } = await Promise.resolve().then(() => _interopRequireWildcard(require("@walletconnect/ethereum-provider")));
|
|
225
225
|
const optionalChains = this.chains.map(({ id }) => id);
|
|
226
226
|
if (optionalChains.length) {
|
|
227
227
|
const {
|
|
@@ -231,7 +231,7 @@ initProvider_fn = async function() {
|
|
|
231
231
|
metadata,
|
|
232
232
|
relayUrl
|
|
233
233
|
} = this.options;
|
|
234
|
-
__privateSet(this, _provider, await EthereumProvider.init({
|
|
234
|
+
_chunkW65LBPLTjs.__privateSet.call(void 0, this, _provider, await EthereumProvider.init({
|
|
235
235
|
showQrModal,
|
|
236
236
|
qrModalOptions,
|
|
237
237
|
projectId,
|
|
@@ -249,73 +249,73 @@ initProvider_fn = async function() {
|
|
|
249
249
|
};
|
|
250
250
|
_isChainsStale = new WeakSet();
|
|
251
251
|
isChainsStale_fn = function() {
|
|
252
|
-
const namespaceMethods = __privateMethod(this, _getNamespaceMethods, getNamespaceMethods_fn).call(this);
|
|
252
|
+
const namespaceMethods = _chunkW65LBPLTjs.__privateMethod.call(void 0, this, _getNamespaceMethods, getNamespaceMethods_fn).call(this);
|
|
253
253
|
if (namespaceMethods.includes(ADD_ETH_CHAIN_METHOD))
|
|
254
254
|
return false;
|
|
255
255
|
if (!this.options.isNewChainsStale)
|
|
256
256
|
return false;
|
|
257
|
-
const requestedChains = __privateMethod(this, _getRequestedChainsIds, getRequestedChainsIds_fn).call(this);
|
|
257
|
+
const requestedChains = _chunkW65LBPLTjs.__privateMethod.call(void 0, this, _getRequestedChainsIds, getRequestedChainsIds_fn).call(this);
|
|
258
258
|
const connectorChains = this.chains.map(({ id }) => id);
|
|
259
|
-
const namespaceChains = __privateMethod(this, _getNamespaceChainsIds, getNamespaceChainsIds_fn).call(this);
|
|
259
|
+
const namespaceChains = _chunkW65LBPLTjs.__privateMethod.call(void 0, this, _getNamespaceChainsIds, getNamespaceChainsIds_fn).call(this);
|
|
260
260
|
if (namespaceChains.length && !namespaceChains.some((id) => connectorChains.includes(id)))
|
|
261
261
|
return false;
|
|
262
262
|
return !connectorChains.every((id) => requestedChains.includes(id));
|
|
263
263
|
};
|
|
264
264
|
_setupListeners = new WeakSet();
|
|
265
265
|
setupListeners_fn = function() {
|
|
266
|
-
if (!__privateGet(this, _provider))
|
|
266
|
+
if (!_chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider))
|
|
267
267
|
return;
|
|
268
|
-
__privateMethod(this, _removeListeners, removeListeners_fn).call(this);
|
|
269
|
-
__privateGet(this, _provider).on("accountsChanged", this.onAccountsChanged);
|
|
270
|
-
__privateGet(this, _provider).on("chainChanged", this.onChainChanged);
|
|
271
|
-
__privateGet(this, _provider).on("disconnect", this.onDisconnect);
|
|
272
|
-
__privateGet(this, _provider).on("session_delete", this.onDisconnect);
|
|
273
|
-
__privateGet(this, _provider).on("display_uri", this.onDisplayUri);
|
|
274
|
-
__privateGet(this, _provider).on("connect", this.onConnect);
|
|
268
|
+
_chunkW65LBPLTjs.__privateMethod.call(void 0, this, _removeListeners, removeListeners_fn).call(this);
|
|
269
|
+
_chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider).on("accountsChanged", this.onAccountsChanged);
|
|
270
|
+
_chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider).on("chainChanged", this.onChainChanged);
|
|
271
|
+
_chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider).on("disconnect", this.onDisconnect);
|
|
272
|
+
_chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider).on("session_delete", this.onDisconnect);
|
|
273
|
+
_chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider).on("display_uri", this.onDisplayUri);
|
|
274
|
+
_chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider).on("connect", this.onConnect);
|
|
275
275
|
};
|
|
276
276
|
_removeListeners = new WeakSet();
|
|
277
277
|
removeListeners_fn = function() {
|
|
278
|
-
if (!__privateGet(this, _provider))
|
|
278
|
+
if (!_chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider))
|
|
279
279
|
return;
|
|
280
|
-
__privateGet(this, _provider).removeListener("accountsChanged", this.onAccountsChanged);
|
|
281
|
-
__privateGet(this, _provider).removeListener("chainChanged", this.onChainChanged);
|
|
282
|
-
__privateGet(this, _provider).removeListener("disconnect", this.onDisconnect);
|
|
283
|
-
__privateGet(this, _provider).removeListener("session_delete", this.onDisconnect);
|
|
284
|
-
__privateGet(this, _provider).removeListener("display_uri", this.onDisplayUri);
|
|
285
|
-
__privateGet(this, _provider).removeListener("connect", this.onConnect);
|
|
280
|
+
_chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider).removeListener("accountsChanged", this.onAccountsChanged);
|
|
281
|
+
_chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider).removeListener("chainChanged", this.onChainChanged);
|
|
282
|
+
_chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider).removeListener("disconnect", this.onDisconnect);
|
|
283
|
+
_chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider).removeListener("session_delete", this.onDisconnect);
|
|
284
|
+
_chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider).removeListener("display_uri", this.onDisplayUri);
|
|
285
|
+
_chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider).removeListener("connect", this.onConnect);
|
|
286
286
|
};
|
|
287
287
|
_setRequestedChainsIds = new WeakSet();
|
|
288
288
|
setRequestedChainsIds_fn = function(chains) {
|
|
289
|
-
this.storage
|
|
289
|
+
_optionalChain([this, 'access', _16 => _16.storage, 'optionalAccess', _17 => _17.setItem, 'call', _18 => _18(REQUESTED_CHAINS_KEY, chains)]);
|
|
290
290
|
};
|
|
291
291
|
_getRequestedChainsIds = new WeakSet();
|
|
292
292
|
getRequestedChainsIds_fn = function() {
|
|
293
|
-
return this.storage
|
|
293
|
+
return _nullishCoalesce(_optionalChain([this, 'access', _19 => _19.storage, 'optionalAccess', _20 => _20.getItem, 'call', _21 => _21(REQUESTED_CHAINS_KEY)]), () => ( []));
|
|
294
294
|
};
|
|
295
295
|
_getNamespaceChainsIds = new WeakSet();
|
|
296
296
|
getNamespaceChainsIds_fn = function() {
|
|
297
|
-
if (!__privateGet(this, _provider))
|
|
297
|
+
if (!_chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider))
|
|
298
298
|
return [];
|
|
299
|
-
const namespaces = __privateGet(this, _provider).session
|
|
299
|
+
const namespaces = _optionalChain([_chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider), 'access', _22 => _22.session, 'optionalAccess', _23 => _23.namespaces]);
|
|
300
300
|
if (!namespaces)
|
|
301
301
|
return [];
|
|
302
|
-
const normalizedNamespaces = normalizeNamespaces(namespaces);
|
|
303
|
-
const chainIds = normalizedNamespaces[NAMESPACE]
|
|
302
|
+
const normalizedNamespaces = _utils.normalizeNamespaces.call(void 0, namespaces);
|
|
303
|
+
const chainIds = _optionalChain([normalizedNamespaces, 'access', _24 => _24[NAMESPACE], 'optionalAccess', _25 => _25.chains, 'optionalAccess', _26 => _26.map, 'call', _27 => _27(
|
|
304
304
|
(chain) => parseInt(chain.split(":")[1] || "")
|
|
305
|
-
);
|
|
306
|
-
return chainIds
|
|
305
|
+
)]);
|
|
306
|
+
return _nullishCoalesce(chainIds, () => ( []));
|
|
307
307
|
};
|
|
308
308
|
_getNamespaceMethods = new WeakSet();
|
|
309
309
|
getNamespaceMethods_fn = function() {
|
|
310
|
-
if (!__privateGet(this, _provider))
|
|
310
|
+
if (!_chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider))
|
|
311
311
|
return [];
|
|
312
|
-
const namespaces = __privateGet(this, _provider).session
|
|
312
|
+
const namespaces = _optionalChain([_chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider), 'access', _28 => _28.session, 'optionalAccess', _29 => _29.namespaces]);
|
|
313
313
|
if (!namespaces)
|
|
314
314
|
return [];
|
|
315
|
-
const normalizedNamespaces = normalizeNamespaces(namespaces);
|
|
316
|
-
const methods = normalizedNamespaces[NAMESPACE]
|
|
317
|
-
return methods
|
|
318
|
-
};
|
|
319
|
-
export {
|
|
320
|
-
WalletConnectConnector
|
|
315
|
+
const normalizedNamespaces = _utils.normalizeNamespaces.call(void 0, namespaces);
|
|
316
|
+
const methods = _optionalChain([normalizedNamespaces, 'access', _30 => _30[NAMESPACE], 'optionalAccess', _31 => _31.methods]);
|
|
317
|
+
return _nullishCoalesce(methods, () => ( []));
|
|
321
318
|
};
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
exports.WalletConnectConnector = WalletConnectConnector;
|
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } 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 _chunkOQILYQDOjs = require('./chunk-OQILYQDO.js');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
var _chunkW65LBPLTjs = require('./chunk-W65LBPLT.js');
|
|
11
11
|
|
|
12
12
|
// src/walletConnectLegacy.ts
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
var _viem = require('viem');
|
|
21
21
|
var switchChainAllowedRegex = /(imtoken|metamask|rainbow|trust wallet|uniswap wallet|ledger)/i;
|
|
22
22
|
var _provider, _switchChain, switchChain_fn;
|
|
23
|
-
var WalletConnectLegacyConnector = class extends Connector {
|
|
23
|
+
var WalletConnectLegacyConnector = class extends _chunkW65LBPLTjs.Connector {
|
|
24
24
|
constructor() {
|
|
25
25
|
super(...arguments);
|
|
26
|
-
__privateAdd(this, _switchChain);
|
|
26
|
+
_chunkW65LBPLTjs.__privateAdd.call(void 0, this, _switchChain);
|
|
27
27
|
this.id = "walletConnectLegacy";
|
|
28
28
|
this.name = "WalletConnectLegacy";
|
|
29
29
|
this.ready = true;
|
|
30
|
-
__privateAdd(this, _provider, void 0);
|
|
30
|
+
_chunkW65LBPLTjs.__privateAdd.call(void 0, this, _provider, void 0);
|
|
31
31
|
this.onAccountsChanged = (accounts) => {
|
|
32
32
|
if (accounts.length === 0)
|
|
33
33
|
this.emit("disconnect");
|
|
34
34
|
else
|
|
35
|
-
this.emit("change", { account: getAddress(accounts[0]) });
|
|
35
|
+
this.emit("change", { account: _viem.getAddress.call(void 0, accounts[0]) });
|
|
36
36
|
};
|
|
37
37
|
this.onChainChanged = (chainId) => {
|
|
38
|
-
const id = normalizeChainId(chainId);
|
|
38
|
+
const id = _chunkOQILYQDOjs.normalizeChainId.call(void 0, chainId);
|
|
39
39
|
const unsupported = this.isChainUnsupported(id);
|
|
40
40
|
this.emit("change", { chain: { id, unsupported } });
|
|
41
41
|
};
|
|
@@ -47,8 +47,8 @@ var WalletConnectLegacyConnector = class extends Connector {
|
|
|
47
47
|
try {
|
|
48
48
|
let targetChainId = chainId;
|
|
49
49
|
if (!targetChainId) {
|
|
50
|
-
const store = this.storage
|
|
51
|
-
const lastUsedChainId = store
|
|
50
|
+
const store = _optionalChain([this, 'access', _ => _.storage, 'optionalAccess', _2 => _2.getItem, 'call', _3 => _3("store")]);
|
|
51
|
+
const lastUsedChainId = _optionalChain([store, 'optionalAccess', _4 => _4.state, 'optionalAccess', _5 => _5.data, 'optionalAccess', _6 => _6.chain, 'optionalAccess', _7 => _7.id]);
|
|
52
52
|
if (lastUsedChainId && !this.isChainUnsupported(lastUsedChainId))
|
|
53
53
|
targetChainId = lastUsedChainId;
|
|
54
54
|
}
|
|
@@ -61,19 +61,19 @@ var WalletConnectLegacyConnector = class extends Connector {
|
|
|
61
61
|
provider.on("disconnect", this.onDisconnect);
|
|
62
62
|
setTimeout(() => this.emit("message", { type: "connecting" }), 0);
|
|
63
63
|
const accounts = await provider.enable();
|
|
64
|
-
const account = getAddress(accounts[0]);
|
|
64
|
+
const account = _viem.getAddress.call(void 0, accounts[0]);
|
|
65
65
|
const id = await this.getChainId();
|
|
66
66
|
const unsupported = this.isChainUnsupported(id);
|
|
67
|
-
const walletName = provider.connector
|
|
67
|
+
const walletName = _nullishCoalesce(_optionalChain([provider, 'access', _8 => _8.connector, 'optionalAccess', _9 => _9.peerMeta, 'optionalAccess', _10 => _10.name]), () => ( ""));
|
|
68
68
|
if (switchChainAllowedRegex.test(walletName))
|
|
69
|
-
this.switchChain = __privateMethod(this, _switchChain, switchChain_fn);
|
|
69
|
+
this.switchChain = _chunkW65LBPLTjs.__privateMethod.call(void 0, this, _switchChain, switchChain_fn);
|
|
70
70
|
return {
|
|
71
71
|
account,
|
|
72
72
|
chain: { id, unsupported }
|
|
73
73
|
};
|
|
74
74
|
} catch (error) {
|
|
75
75
|
if (/user closed modal/i.test(error.message))
|
|
76
|
-
throw new UserRejectedRequestError(error);
|
|
76
|
+
throw new (0, _viem.UserRejectedRequestError)(error);
|
|
77
77
|
throw error;
|
|
78
78
|
}
|
|
79
79
|
}
|
|
@@ -88,34 +88,34 @@ var WalletConnectLegacyConnector = class extends Connector {
|
|
|
88
88
|
async getAccount() {
|
|
89
89
|
const provider = await this.getProvider();
|
|
90
90
|
const accounts = provider.accounts;
|
|
91
|
-
return getAddress(accounts[0]);
|
|
91
|
+
return _viem.getAddress.call(void 0, accounts[0]);
|
|
92
92
|
}
|
|
93
93
|
async getChainId() {
|
|
94
94
|
const provider = await this.getProvider();
|
|
95
|
-
const chainId = normalizeChainId(provider.chainId);
|
|
95
|
+
const chainId = _chunkOQILYQDOjs.normalizeChainId.call(void 0, provider.chainId);
|
|
96
96
|
return chainId;
|
|
97
97
|
}
|
|
98
98
|
async getProvider({
|
|
99
99
|
chainId,
|
|
100
100
|
create
|
|
101
101
|
} = {}) {
|
|
102
|
-
if (!__privateGet(this, _provider) || chainId || create) {
|
|
103
|
-
const rpc = !this.options
|
|
102
|
+
if (!_chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider) || chainId || create) {
|
|
103
|
+
const rpc = !_optionalChain([this, 'access', _11 => _11.options, 'optionalAccess', _12 => _12.infuraId]) ? this.chains.reduce(
|
|
104
104
|
(rpc2, chain) => ({
|
|
105
105
|
...rpc2,
|
|
106
106
|
[chain.id]: chain.rpcUrls.default.http[0]
|
|
107
107
|
}),
|
|
108
108
|
{}
|
|
109
109
|
) : {};
|
|
110
|
-
const WalletConnectProvider = (await
|
|
111
|
-
__privateSet(this, _provider, new WalletConnectProvider({
|
|
110
|
+
const WalletConnectProvider = (await Promise.resolve().then(() => _interopRequireWildcard(require("@walletconnect/legacy-provider")))).default;
|
|
111
|
+
_chunkW65LBPLTjs.__privateSet.call(void 0, this, _provider, new WalletConnectProvider({
|
|
112
112
|
...this.options,
|
|
113
113
|
chainId,
|
|
114
|
-
rpc: { ...rpc, ...this.options
|
|
114
|
+
rpc: { ...rpc, ..._optionalChain([this, 'access', _13 => _13.options, 'optionalAccess', _14 => _14.rpc]) }
|
|
115
115
|
}));
|
|
116
|
-
__privateGet(this, _provider).http = await __privateGet(this, _provider).setHttpProvider(chainId);
|
|
116
|
+
_chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider).http = await _chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider).setHttpProvider(chainId);
|
|
117
117
|
}
|
|
118
|
-
return __privateGet(this, _provider);
|
|
118
|
+
return _chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider);
|
|
119
119
|
}
|
|
120
120
|
async getWalletClient({
|
|
121
121
|
chainId
|
|
@@ -127,17 +127,17 @@ var WalletConnectLegacyConnector = class extends Connector {
|
|
|
127
127
|
const chain = this.chains.find((x) => x.id === chainId);
|
|
128
128
|
if (!provider)
|
|
129
129
|
throw new Error("provider is required.");
|
|
130
|
-
return createWalletClient({
|
|
130
|
+
return _viem.createWalletClient.call(void 0, {
|
|
131
131
|
account,
|
|
132
132
|
chain,
|
|
133
|
-
transport: custom(provider)
|
|
133
|
+
transport: _viem.custom.call(void 0, provider)
|
|
134
134
|
});
|
|
135
135
|
}
|
|
136
136
|
async isAuthorized() {
|
|
137
137
|
try {
|
|
138
138
|
const account = await this.getAccount();
|
|
139
139
|
return !!account;
|
|
140
|
-
} catch {
|
|
140
|
+
} catch (e) {
|
|
141
141
|
return false;
|
|
142
142
|
}
|
|
143
143
|
}
|
|
@@ -146,7 +146,7 @@ _provider = new WeakMap();
|
|
|
146
146
|
_switchChain = new WeakSet();
|
|
147
147
|
switchChain_fn = async function(chainId) {
|
|
148
148
|
const provider = await this.getProvider();
|
|
149
|
-
const id = numberToHex(chainId);
|
|
149
|
+
const id = _viem.numberToHex.call(void 0, chainId);
|
|
150
150
|
try {
|
|
151
151
|
await Promise.race([
|
|
152
152
|
provider.request({
|
|
@@ -155,25 +155,25 @@ switchChain_fn = async function(chainId) {
|
|
|
155
155
|
}),
|
|
156
156
|
new Promise(
|
|
157
157
|
(res) => this.on("change", ({ chain }) => {
|
|
158
|
-
if (chain
|
|
158
|
+
if (_optionalChain([chain, 'optionalAccess', _15 => _15.id]) === chainId)
|
|
159
159
|
res(chainId);
|
|
160
160
|
})
|
|
161
161
|
)
|
|
162
162
|
]);
|
|
163
|
-
return this.chains.find((x) => x.id === chainId)
|
|
163
|
+
return _nullishCoalesce(this.chains.find((x) => x.id === chainId), () => ( {
|
|
164
164
|
id: chainId,
|
|
165
165
|
name: `Chain ${id}`,
|
|
166
166
|
network: `${id}`,
|
|
167
167
|
nativeCurrency: { name: "Ether", decimals: 18, symbol: "ETH" },
|
|
168
168
|
rpcUrls: { default: { http: [""] }, public: { http: [""] } }
|
|
169
|
-
};
|
|
169
|
+
}));
|
|
170
170
|
} catch (error) {
|
|
171
|
-
const message = typeof error === "string" ? error : error
|
|
171
|
+
const message = typeof error === "string" ? error : _optionalChain([error, 'optionalAccess', _16 => _16.message]);
|
|
172
172
|
if (/user rejected request/i.test(message))
|
|
173
|
-
throw new UserRejectedRequestError(error);
|
|
174
|
-
throw new SwitchChainError(error);
|
|
173
|
+
throw new (0, _viem.UserRejectedRequestError)(error);
|
|
174
|
+
throw new (0, _viem.SwitchChainError)(error);
|
|
175
175
|
}
|
|
176
176
|
};
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
exports.WalletConnectLegacyConnector = WalletConnectLegacyConnector;
|
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": "3.1.
|
|
5
|
+
"version": "3.1.11-cjs",
|
|
6
6
|
"peerDependencies": {
|
|
7
7
|
"typescript": ">=5.0.4",
|
|
8
8
|
"viem": ">=0.3.35"
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"@coinbase/wallet-sdk": "^3.6.6",
|
|
17
17
|
"@safe-global/safe-apps-provider": "^0.18.1",
|
|
18
18
|
"@safe-global/safe-apps-sdk": "^8.1.0",
|
|
19
|
-
"@walletconnect/ethereum-provider": "2.
|
|
20
|
-
"@walletconnect/utils": "2.
|
|
19
|
+
"@walletconnect/ethereum-provider": "2.11.0",
|
|
20
|
+
"@walletconnect/utils": "2.11.0",
|
|
21
21
|
"@walletconnect/legacy-provider": "^2.0.0",
|
|
22
22
|
"@walletconnect/modal": "2.6.2",
|
|
23
23
|
"abitype": "0.8.7",
|
|
@@ -26,7 +26,6 @@
|
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"viem": "^1.0.0"
|
|
28
28
|
},
|
|
29
|
-
"type": "module",
|
|
30
29
|
"main": "dist/index.js",
|
|
31
30
|
"types": "dist/index.d.ts",
|
|
32
31
|
"exports": {
|