@wagmi/connectors 3.1.2-cjs → 3.1.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-2UFLHRLT.js +65 -65
- package/dist/chunk-OQILYQDO.js +4 -4
- 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/ledger.js +75 -75
- 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 +2 -1
package/dist/ledger.js
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import {
|
|
2
|
+
normalizeChainId
|
|
3
|
+
} from "./chunk-OQILYQDO.js";
|
|
4
|
+
import {
|
|
5
|
+
Connector,
|
|
6
|
+
__privateAdd,
|
|
7
|
+
__privateGet,
|
|
8
|
+
__privateMethod,
|
|
9
|
+
__privateSet
|
|
10
|
+
} from "./chunk-W65LBPLT.js";
|
|
11
11
|
|
|
12
12
|
// src/ledger.ts
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
13
|
+
import {
|
|
14
|
+
SupportedProviders,
|
|
15
|
+
loadConnectKit
|
|
16
|
+
} from "@ledgerhq/connect-kit-loader";
|
|
17
|
+
import {
|
|
18
|
+
SwitchChainError,
|
|
19
|
+
UserRejectedRequestError,
|
|
20
|
+
createWalletClient,
|
|
21
|
+
custom,
|
|
22
|
+
getAddress,
|
|
23
|
+
numberToHex
|
|
24
|
+
} from "viem";
|
|
25
25
|
var _provider, _initProviderPromise, _isV1, _createProvider, createProvider_fn, _initProvider, initProvider_fn, _setupListeners, setupListeners_fn, _removeListeners, removeListeners_fn;
|
|
26
|
-
var LedgerConnector = class extends
|
|
26
|
+
var LedgerConnector = class extends Connector {
|
|
27
27
|
constructor(config) {
|
|
28
28
|
super({
|
|
29
29
|
...config,
|
|
30
30
|
options: { ...config.options }
|
|
31
31
|
});
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
__privateAdd(this, _createProvider);
|
|
33
|
+
__privateAdd(this, _initProvider);
|
|
34
|
+
__privateAdd(this, _setupListeners);
|
|
35
|
+
__privateAdd(this, _removeListeners);
|
|
36
36
|
this.id = "ledger";
|
|
37
37
|
this.name = "Ledger";
|
|
38
38
|
this.ready = true;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
__privateAdd(this, _provider, void 0);
|
|
40
|
+
__privateAdd(this, _initProviderPromise, void 0);
|
|
41
|
+
__privateAdd(this, _isV1, void 0);
|
|
42
42
|
this.onAccountsChanged = (accounts) => {
|
|
43
43
|
if (accounts.length === 0)
|
|
44
44
|
this.emit("disconnect");
|
|
45
45
|
else
|
|
46
|
-
this.emit("change", { account:
|
|
46
|
+
this.emit("change", { account: getAddress(accounts[0]) });
|
|
47
47
|
};
|
|
48
48
|
this.onChainChanged = (chainId) => {
|
|
49
|
-
const id =
|
|
49
|
+
const id = normalizeChainId(chainId);
|
|
50
50
|
const unsupported = this.isChainUnsupported(id);
|
|
51
51
|
this.emit("change", { chain: { id, unsupported } });
|
|
52
52
|
};
|
|
@@ -56,7 +56,7 @@ var LedgerConnector = class extends _chunkW65LBPLTjs.Connector {
|
|
|
56
56
|
this.onConnect = () => {
|
|
57
57
|
this.emit("connect", {});
|
|
58
58
|
};
|
|
59
|
-
|
|
59
|
+
__privateSet(this, _isV1, this.walletConnectVersion === 1);
|
|
60
60
|
}
|
|
61
61
|
get walletConnectVersion() {
|
|
62
62
|
if (this.options.walletConnectVersion)
|
|
@@ -68,7 +68,7 @@ var LedgerConnector = class extends _chunkW65LBPLTjs.Connector {
|
|
|
68
68
|
async connect({ chainId } = {}) {
|
|
69
69
|
try {
|
|
70
70
|
const provider = await this.getProvider({ create: true });
|
|
71
|
-
|
|
71
|
+
__privateMethod(this, _setupListeners, setupListeners_fn).call(this);
|
|
72
72
|
if (!provider.session) {
|
|
73
73
|
this.emit("message", { type: "connecting" });
|
|
74
74
|
await provider.request({
|
|
@@ -89,8 +89,8 @@ var LedgerConnector = class extends _chunkW65LBPLTjs.Connector {
|
|
|
89
89
|
provider
|
|
90
90
|
};
|
|
91
91
|
} catch (error) {
|
|
92
|
-
if (/user rejected/i.test(
|
|
93
|
-
throw new
|
|
92
|
+
if (/user rejected/i.test(error?.message)) {
|
|
93
|
+
throw new UserRejectedRequestError(error);
|
|
94
94
|
}
|
|
95
95
|
throw error;
|
|
96
96
|
}
|
|
@@ -98,14 +98,14 @@ var LedgerConnector = class extends _chunkW65LBPLTjs.Connector {
|
|
|
98
98
|
async disconnect() {
|
|
99
99
|
const provider = await this.getProvider();
|
|
100
100
|
try {
|
|
101
|
-
if (
|
|
101
|
+
if (provider?.disconnect)
|
|
102
102
|
await provider.disconnect();
|
|
103
103
|
} catch (error) {
|
|
104
104
|
if (!/No matching key/i.test(error.message))
|
|
105
105
|
throw error;
|
|
106
106
|
} finally {
|
|
107
|
-
|
|
108
|
-
|
|
107
|
+
__privateMethod(this, _removeListeners, removeListeners_fn).call(this);
|
|
108
|
+
__privateGet(this, _isV1) && typeof localStorage !== "undefined" && localStorage.removeItem("walletconnect");
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
async getAccount() {
|
|
@@ -113,7 +113,7 @@ var LedgerConnector = class extends _chunkW65LBPLTjs.Connector {
|
|
|
113
113
|
const accounts = await provider.request({
|
|
114
114
|
method: "eth_accounts"
|
|
115
115
|
});
|
|
116
|
-
const account =
|
|
116
|
+
const account = getAddress(accounts[0]);
|
|
117
117
|
return account;
|
|
118
118
|
}
|
|
119
119
|
async getChainId() {
|
|
@@ -121,17 +121,17 @@ var LedgerConnector = class extends _chunkW65LBPLTjs.Connector {
|
|
|
121
121
|
const chainId = await provider.request({
|
|
122
122
|
method: "eth_chainId"
|
|
123
123
|
});
|
|
124
|
-
return
|
|
124
|
+
return normalizeChainId(chainId);
|
|
125
125
|
}
|
|
126
126
|
async getProvider({ chainId, create } = {
|
|
127
127
|
create: false
|
|
128
128
|
}) {
|
|
129
|
-
if (!
|
|
130
|
-
await
|
|
129
|
+
if (!__privateGet(this, _provider) || __privateGet(this, _isV1) && create) {
|
|
130
|
+
await __privateMethod(this, _createProvider, createProvider_fn).call(this);
|
|
131
131
|
}
|
|
132
132
|
if (chainId)
|
|
133
133
|
await this.switchChain(chainId);
|
|
134
|
-
return
|
|
134
|
+
return __privateGet(this, _provider);
|
|
135
135
|
}
|
|
136
136
|
async getWalletClient({
|
|
137
137
|
chainId
|
|
@@ -143,33 +143,33 @@ var LedgerConnector = class extends _chunkW65LBPLTjs.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
|
|
146
|
+
return createWalletClient({ account, chain, transport: custom(provider) });
|
|
147
147
|
}
|
|
148
148
|
async isAuthorized() {
|
|
149
149
|
try {
|
|
150
150
|
const account = await this.getAccount();
|
|
151
151
|
return !!account;
|
|
152
|
-
} catch
|
|
152
|
+
} catch {
|
|
153
153
|
return false;
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
156
|
async switchChain(chainId) {
|
|
157
157
|
const chain = this.chains.find((chain2) => chain2.id === chainId);
|
|
158
158
|
if (!chain)
|
|
159
|
-
throw new
|
|
159
|
+
throw new SwitchChainError(new Error("chain not found on connector."));
|
|
160
160
|
try {
|
|
161
161
|
const provider = await this.getProvider();
|
|
162
162
|
await provider.request({
|
|
163
163
|
method: "wallet_switchEthereumChain",
|
|
164
|
-
params: [{ chainId:
|
|
164
|
+
params: [{ chainId: numberToHex(chainId) }]
|
|
165
165
|
});
|
|
166
166
|
return chain;
|
|
167
167
|
} catch (error) {
|
|
168
|
-
const message = typeof error === "string" ? error :
|
|
168
|
+
const message = typeof error === "string" ? error : error?.message;
|
|
169
169
|
if (/user rejected request/i.test(message)) {
|
|
170
|
-
throw new
|
|
170
|
+
throw new UserRejectedRequestError(error);
|
|
171
171
|
}
|
|
172
|
-
throw new
|
|
172
|
+
throw new SwitchChainError(error);
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
175
|
};
|
|
@@ -178,22 +178,22 @@ _initProviderPromise = new WeakMap();
|
|
|
178
178
|
_isV1 = new WeakMap();
|
|
179
179
|
_createProvider = new WeakSet();
|
|
180
180
|
createProvider_fn = async function() {
|
|
181
|
-
if (!
|
|
182
|
-
|
|
181
|
+
if (!__privateGet(this, _initProviderPromise) && typeof window !== "undefined") {
|
|
182
|
+
__privateSet(this, _initProviderPromise, __privateMethod(this, _initProvider, initProvider_fn).call(this));
|
|
183
183
|
}
|
|
184
|
-
return
|
|
184
|
+
return __privateGet(this, _initProviderPromise);
|
|
185
185
|
};
|
|
186
186
|
_initProvider = new WeakSet();
|
|
187
187
|
initProvider_fn = async function() {
|
|
188
|
-
const connectKit = await
|
|
188
|
+
const connectKit = await loadConnectKit();
|
|
189
189
|
if (this.options.enableDebugLogs) {
|
|
190
190
|
connectKit.enableDebugLogs();
|
|
191
191
|
}
|
|
192
192
|
let checkSupportOptions;
|
|
193
|
-
if (
|
|
193
|
+
if (__privateGet(this, _isV1)) {
|
|
194
194
|
const { chainId, bridge } = this.options;
|
|
195
195
|
checkSupportOptions = {
|
|
196
|
-
providerType:
|
|
196
|
+
providerType: SupportedProviders.Ethereum,
|
|
197
197
|
walletConnectVersion: 1,
|
|
198
198
|
chainId,
|
|
199
199
|
bridge,
|
|
@@ -215,7 +215,7 @@ initProvider_fn = async function() {
|
|
|
215
215
|
} = this.options;
|
|
216
216
|
const optionalChains = this.chains.map(({ id }) => id);
|
|
217
217
|
checkSupportOptions = {
|
|
218
|
-
providerType:
|
|
218
|
+
providerType: SupportedProviders.Ethereum,
|
|
219
219
|
walletConnectVersion: 2,
|
|
220
220
|
projectId,
|
|
221
221
|
chains: requiredChains,
|
|
@@ -233,29 +233,29 @@ initProvider_fn = async function() {
|
|
|
233
233
|
};
|
|
234
234
|
}
|
|
235
235
|
connectKit.checkSupport(checkSupportOptions);
|
|
236
|
-
|
|
236
|
+
__privateSet(this, _provider, await connectKit.getProvider());
|
|
237
237
|
};
|
|
238
238
|
_setupListeners = new WeakSet();
|
|
239
239
|
setupListeners_fn = function() {
|
|
240
|
-
if (!
|
|
240
|
+
if (!__privateGet(this, _provider))
|
|
241
241
|
return;
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
242
|
+
__privateMethod(this, _removeListeners, removeListeners_fn).call(this);
|
|
243
|
+
__privateGet(this, _provider).on("accountsChanged", this.onAccountsChanged);
|
|
244
|
+
__privateGet(this, _provider).on("chainChanged", this.onChainChanged);
|
|
245
|
+
__privateGet(this, _provider).on("disconnect", this.onDisconnect);
|
|
246
|
+
__privateGet(this, _provider).on("session_delete", this.onDisconnect);
|
|
247
|
+
__privateGet(this, _provider).on("connect", this.onConnect);
|
|
248
248
|
};
|
|
249
249
|
_removeListeners = new WeakSet();
|
|
250
250
|
removeListeners_fn = function() {
|
|
251
|
-
if (!
|
|
251
|
+
if (!__privateGet(this, _provider))
|
|
252
252
|
return;
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
253
|
+
__privateGet(this, _provider).removeListener("accountsChanged", this.onAccountsChanged);
|
|
254
|
+
__privateGet(this, _provider).removeListener("chainChanged", this.onChainChanged);
|
|
255
|
+
__privateGet(this, _provider).removeListener("disconnect", this.onDisconnect);
|
|
256
|
+
__privateGet(this, _provider).removeListener("session_delete", this.onDisconnect);
|
|
257
|
+
__privateGet(this, _provider).removeListener("connect", this.onConnect);
|
|
258
|
+
};
|
|
259
|
+
export {
|
|
260
|
+
LedgerConnector
|
|
258
261
|
};
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
exports.LedgerConnector = LedgerConnector;
|
package/dist/metaMask.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import {
|
|
2
|
+
InjectedConnector
|
|
3
|
+
} from "./chunk-2UFLHRLT.js";
|
|
4
|
+
import {
|
|
5
|
+
ConnectorNotFoundError
|
|
6
|
+
} from "./chunk-UGBGYVBH.js";
|
|
7
|
+
import "./chunk-OQILYQDO.js";
|
|
8
|
+
import {
|
|
9
|
+
__privateAdd,
|
|
10
|
+
__privateGet,
|
|
11
|
+
__privateSet
|
|
12
|
+
} from "./chunk-W65LBPLT.js";
|
|
13
13
|
|
|
14
14
|
// src/metaMask.ts
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
import {
|
|
16
|
+
ResourceUnavailableRpcError,
|
|
17
|
+
UserRejectedRequestError,
|
|
18
|
+
getAddress
|
|
19
|
+
} from "viem";
|
|
20
20
|
var _UNSTABLE_shimOnConnectSelectAccount;
|
|
21
|
-
var MetaMaskConnector = class extends
|
|
21
|
+
var MetaMaskConnector = class extends InjectedConnector {
|
|
22
22
|
constructor({
|
|
23
23
|
chains,
|
|
24
24
|
options: options_
|
|
@@ -28,7 +28,7 @@ var MetaMaskConnector = class extends _chunk2UFLHRLTjs.InjectedConnector {
|
|
|
28
28
|
shimDisconnect: true,
|
|
29
29
|
getProvider() {
|
|
30
30
|
function getReady(ethereum2) {
|
|
31
|
-
const isMetaMask = !!
|
|
31
|
+
const isMetaMask = !!ethereum2?.isMetaMask;
|
|
32
32
|
if (!isMetaMask)
|
|
33
33
|
return;
|
|
34
34
|
if (ethereum2.isBraveWallet && !ethereum2._events && !ethereum2._state)
|
|
@@ -72,7 +72,7 @@ var MetaMaskConnector = class extends _chunk2UFLHRLTjs.InjectedConnector {
|
|
|
72
72
|
if (typeof window === "undefined")
|
|
73
73
|
return;
|
|
74
74
|
const ethereum = window.ethereum;
|
|
75
|
-
if (
|
|
75
|
+
if (ethereum?.providers)
|
|
76
76
|
return ethereum.providers.find(getReady);
|
|
77
77
|
return getReady(ethereum);
|
|
78
78
|
},
|
|
@@ -81,14 +81,14 @@ var MetaMaskConnector = class extends _chunk2UFLHRLTjs.InjectedConnector {
|
|
|
81
81
|
super({ chains, options });
|
|
82
82
|
this.id = "metaMask";
|
|
83
83
|
this.shimDisconnectKey = `${this.id}.shimDisconnect`;
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
__privateAdd(this, _UNSTABLE_shimOnConnectSelectAccount, void 0);
|
|
85
|
+
__privateSet(this, _UNSTABLE_shimOnConnectSelectAccount, options.UNSTABLE_shimOnConnectSelectAccount);
|
|
86
86
|
}
|
|
87
87
|
async connect({ chainId } = {}) {
|
|
88
88
|
try {
|
|
89
89
|
const provider = await this.getProvider();
|
|
90
90
|
if (!provider)
|
|
91
|
-
throw new
|
|
91
|
+
throw new ConnectorNotFoundError();
|
|
92
92
|
if (provider.on) {
|
|
93
93
|
provider.on("accountsChanged", this.onAccountsChanged);
|
|
94
94
|
provider.on("chainChanged", this.onChainChanged);
|
|
@@ -96,7 +96,7 @@ var MetaMaskConnector = class extends _chunk2UFLHRLTjs.InjectedConnector {
|
|
|
96
96
|
}
|
|
97
97
|
this.emit("message", { type: "connecting" });
|
|
98
98
|
let account = null;
|
|
99
|
-
if (
|
|
99
|
+
if (__privateGet(this, _UNSTABLE_shimOnConnectSelectAccount) && this.options?.shimDisconnect && !this.storage?.getItem(this.shimDisconnectKey)) {
|
|
100
100
|
account = await this.getAccount().catch(() => null);
|
|
101
101
|
const isConnected = !!account;
|
|
102
102
|
if (isConnected)
|
|
@@ -108,8 +108,8 @@ var MetaMaskConnector = class extends _chunk2UFLHRLTjs.InjectedConnector {
|
|
|
108
108
|
account = await this.getAccount();
|
|
109
109
|
} catch (error) {
|
|
110
110
|
if (this.isUserRejectedRequestError(error))
|
|
111
|
-
throw new
|
|
112
|
-
if (error.code === new
|
|
111
|
+
throw new UserRejectedRequestError(error);
|
|
112
|
+
if (error.code === new ResourceUnavailableRpcError(error).code)
|
|
113
113
|
throw error;
|
|
114
114
|
}
|
|
115
115
|
}
|
|
@@ -117,7 +117,7 @@ var MetaMaskConnector = class extends _chunk2UFLHRLTjs.InjectedConnector {
|
|
|
117
117
|
const accounts = await provider.request({
|
|
118
118
|
method: "eth_requestAccounts"
|
|
119
119
|
});
|
|
120
|
-
account =
|
|
120
|
+
account = getAddress(accounts[0]);
|
|
121
121
|
}
|
|
122
122
|
let id = await this.getChainId();
|
|
123
123
|
let unsupported = this.isChainUnsupported(id);
|
|
@@ -126,19 +126,19 @@ var MetaMaskConnector = class extends _chunk2UFLHRLTjs.InjectedConnector {
|
|
|
126
126
|
id = chain.id;
|
|
127
127
|
unsupported = this.isChainUnsupported(id);
|
|
128
128
|
}
|
|
129
|
-
if (
|
|
130
|
-
|
|
129
|
+
if (this.options?.shimDisconnect)
|
|
130
|
+
this.storage?.setItem(this.shimDisconnectKey, true);
|
|
131
131
|
return { account, chain: { id, unsupported }, provider };
|
|
132
132
|
} catch (error) {
|
|
133
133
|
if (this.isUserRejectedRequestError(error))
|
|
134
|
-
throw new
|
|
134
|
+
throw new UserRejectedRequestError(error);
|
|
135
135
|
if (error.code === -32002)
|
|
136
|
-
throw new
|
|
136
|
+
throw new ResourceUnavailableRpcError(error);
|
|
137
137
|
throw error;
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
};
|
|
141
141
|
_UNSTABLE_shimOnConnectSelectAccount = new WeakMap();
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
142
|
+
export {
|
|
143
|
+
MetaMaskConnector
|
|
144
|
+
};
|
package/dist/mock/index.js
CHANGED
|
@@ -1,71 +1,71 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import {
|
|
2
|
+
normalizeChainId
|
|
3
|
+
} from "../chunk-OQILYQDO.js";
|
|
4
|
+
import {
|
|
5
|
+
Connector,
|
|
6
|
+
__privateAdd,
|
|
7
|
+
__privateGet,
|
|
8
|
+
__privateMethod,
|
|
9
|
+
__privateSet
|
|
10
|
+
} from "../chunk-W65LBPLT.js";
|
|
11
11
|
|
|
12
12
|
// src/mock/connector.ts
|
|
13
|
-
|
|
13
|
+
import { getAddress as getAddress2 } from "viem";
|
|
14
14
|
|
|
15
15
|
// src/mock/provider.ts
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
import { default as EventEmitter } from "eventemitter3";
|
|
17
|
+
import { UserRejectedRequestError, getAddress } from "viem";
|
|
18
18
|
var _options, _walletClient;
|
|
19
19
|
var MockProvider = class {
|
|
20
20
|
constructor(options) {
|
|
21
|
-
this.events = new (
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
this.events = new EventEmitter();
|
|
22
|
+
__privateAdd(this, _options, void 0);
|
|
23
|
+
__privateAdd(this, _walletClient, void 0);
|
|
24
24
|
this.chainId = options.chainId;
|
|
25
|
-
|
|
25
|
+
__privateSet(this, _options, options);
|
|
26
26
|
}
|
|
27
27
|
async enable() {
|
|
28
|
-
if (
|
|
29
|
-
throw new
|
|
30
|
-
if (!
|
|
31
|
-
|
|
32
|
-
const address =
|
|
28
|
+
if (__privateGet(this, _options).flags?.failConnect)
|
|
29
|
+
throw new UserRejectedRequestError(new Error("Failed to connect."));
|
|
30
|
+
if (!__privateGet(this, _walletClient))
|
|
31
|
+
__privateSet(this, _walletClient, __privateGet(this, _options).walletClient);
|
|
32
|
+
const address = __privateGet(this, _walletClient).account.address;
|
|
33
33
|
this.events.emit("accountsChanged", [address]);
|
|
34
34
|
return [address];
|
|
35
35
|
}
|
|
36
36
|
async disconnect() {
|
|
37
37
|
this.events.emit("disconnect");
|
|
38
|
-
|
|
38
|
+
__privateSet(this, _walletClient, void 0);
|
|
39
39
|
}
|
|
40
40
|
async getAccounts() {
|
|
41
|
-
const address =
|
|
41
|
+
const address = __privateGet(this, _walletClient)?.account.address;
|
|
42
42
|
if (!address)
|
|
43
43
|
return [];
|
|
44
|
-
return [
|
|
44
|
+
return [getAddress(address)];
|
|
45
45
|
}
|
|
46
46
|
getWalletClient() {
|
|
47
|
-
const walletClient =
|
|
47
|
+
const walletClient = __privateGet(this, _walletClient);
|
|
48
48
|
if (!walletClient)
|
|
49
49
|
throw new Error("walletClient not found");
|
|
50
50
|
return walletClient;
|
|
51
51
|
}
|
|
52
52
|
async switchChain(chainId) {
|
|
53
|
-
if (
|
|
54
|
-
throw new
|
|
55
|
-
|
|
53
|
+
if (__privateGet(this, _options).flags?.failSwitchChain)
|
|
54
|
+
throw new UserRejectedRequestError(new Error("Failed to switch chain."));
|
|
55
|
+
__privateGet(this, _options).chainId = chainId;
|
|
56
56
|
this.chainId = chainId;
|
|
57
57
|
this.events.emit("chainChanged", chainId);
|
|
58
58
|
}
|
|
59
59
|
async switchWalletClient(walletClient) {
|
|
60
60
|
const address = walletClient.account.address;
|
|
61
|
-
|
|
61
|
+
__privateSet(this, _walletClient, walletClient);
|
|
62
62
|
this.events.emit("accountsChanged", [address]);
|
|
63
63
|
}
|
|
64
64
|
async watchAsset(_asset) {
|
|
65
65
|
return true;
|
|
66
66
|
}
|
|
67
67
|
async request({ method, params }) {
|
|
68
|
-
return
|
|
68
|
+
return __privateGet(this, _walletClient)?.transport.request({ method, params });
|
|
69
69
|
}
|
|
70
70
|
on(event, listener) {
|
|
71
71
|
this.events.on(event, listener);
|
|
@@ -84,7 +84,7 @@ _walletClient = new WeakMap();
|
|
|
84
84
|
|
|
85
85
|
// src/mock/connector.ts
|
|
86
86
|
var _provider, _switchChain, switchChain_fn;
|
|
87
|
-
var MockConnector = class extends
|
|
87
|
+
var MockConnector = class extends Connector {
|
|
88
88
|
constructor({
|
|
89
89
|
chains,
|
|
90
90
|
options
|
|
@@ -93,22 +93,22 @@ var MockConnector = class extends _chunkW65LBPLTjs.Connector {
|
|
|
93
93
|
chains,
|
|
94
94
|
options: {
|
|
95
95
|
...options,
|
|
96
|
-
chainId:
|
|
96
|
+
chainId: options.chainId ?? chains?.[0]?.id
|
|
97
97
|
}
|
|
98
98
|
});
|
|
99
|
-
|
|
99
|
+
__privateAdd(this, _switchChain);
|
|
100
100
|
this.id = "mock";
|
|
101
101
|
this.name = "Mock";
|
|
102
102
|
this.ready = true;
|
|
103
|
-
|
|
103
|
+
__privateAdd(this, _provider, void 0);
|
|
104
104
|
this.onAccountsChanged = (accounts) => {
|
|
105
105
|
if (accounts.length === 0)
|
|
106
106
|
this.emit("disconnect");
|
|
107
107
|
else
|
|
108
|
-
this.emit("change", { account:
|
|
108
|
+
this.emit("change", { account: getAddress2(accounts[0]) });
|
|
109
109
|
};
|
|
110
110
|
this.onChainChanged = (chainId) => {
|
|
111
|
-
const id =
|
|
111
|
+
const id = normalizeChainId(chainId);
|
|
112
112
|
const unsupported = this.isChainUnsupported(id);
|
|
113
113
|
this.emit("change", { chain: { id, unsupported } });
|
|
114
114
|
};
|
|
@@ -123,12 +123,12 @@ var MockConnector = class extends _chunkW65LBPLTjs.Connector {
|
|
|
123
123
|
provider.on("disconnect", this.onDisconnect);
|
|
124
124
|
this.emit("message", { type: "connecting" });
|
|
125
125
|
const accounts = await provider.enable();
|
|
126
|
-
const account =
|
|
127
|
-
const id =
|
|
126
|
+
const account = getAddress2(accounts[0]);
|
|
127
|
+
const id = normalizeChainId(provider.chainId);
|
|
128
128
|
const unsupported = this.isChainUnsupported(id);
|
|
129
129
|
const data = { account, chain: { id, unsupported }, provider };
|
|
130
|
-
if (!
|
|
131
|
-
this.switchChain =
|
|
130
|
+
if (!this.options.flags?.noSwitchChain)
|
|
131
|
+
this.switchChain = __privateMethod(this, _switchChain, switchChain_fn);
|
|
132
132
|
return new Promise(
|
|
133
133
|
(res) => setTimeout(() => res(data), 100)
|
|
134
134
|
);
|
|
@@ -146,19 +146,19 @@ var MockConnector = class extends _chunkW65LBPLTjs.Connector {
|
|
|
146
146
|
const account = accounts[0];
|
|
147
147
|
if (!account)
|
|
148
148
|
throw new Error("Failed to get account");
|
|
149
|
-
return
|
|
149
|
+
return getAddress2(account);
|
|
150
150
|
}
|
|
151
151
|
async getChainId() {
|
|
152
152
|
const provider = await this.getProvider();
|
|
153
|
-
return
|
|
153
|
+
return normalizeChainId(provider.chainId);
|
|
154
154
|
}
|
|
155
155
|
async getProvider({ chainId } = {}) {
|
|
156
|
-
if (!
|
|
157
|
-
|
|
156
|
+
if (!__privateGet(this, _provider) || chainId)
|
|
157
|
+
__privateSet(this, _provider, new MockProvider({
|
|
158
158
|
...this.options,
|
|
159
|
-
chainId:
|
|
159
|
+
chainId: chainId ?? this.options.chainId ?? this.chains[0].id
|
|
160
160
|
}));
|
|
161
|
-
return
|
|
161
|
+
return __privateGet(this, _provider);
|
|
162
162
|
}
|
|
163
163
|
async getWalletClient() {
|
|
164
164
|
const provider = await this.getProvider();
|
|
@@ -168,8 +168,8 @@ var MockConnector = class extends _chunkW65LBPLTjs.Connector {
|
|
|
168
168
|
try {
|
|
169
169
|
const provider = await this.getProvider();
|
|
170
170
|
const account = await provider.getAccounts();
|
|
171
|
-
return
|
|
172
|
-
} catch
|
|
171
|
+
return this.options.flags?.isAuthorized ?? !!account;
|
|
172
|
+
} catch {
|
|
173
173
|
return false;
|
|
174
174
|
}
|
|
175
175
|
}
|
|
@@ -186,15 +186,15 @@ _switchChain = new WeakSet();
|
|
|
186
186
|
switchChain_fn = async function(chainId) {
|
|
187
187
|
const provider = await this.getProvider();
|
|
188
188
|
await provider.switchChain(chainId);
|
|
189
|
-
return
|
|
189
|
+
return this.chains.find((x) => x.id === chainId) ?? {
|
|
190
190
|
id: chainId,
|
|
191
191
|
name: `Chain ${chainId}`,
|
|
192
192
|
network: `${chainId}`,
|
|
193
193
|
nativeCurrency: { name: "Ether", decimals: 18, symbol: "ETH" },
|
|
194
194
|
rpcUrls: { default: { http: [""] }, public: { http: [""] } }
|
|
195
|
-
}
|
|
195
|
+
};
|
|
196
|
+
};
|
|
197
|
+
export {
|
|
198
|
+
MockConnector,
|
|
199
|
+
MockProvider
|
|
196
200
|
};
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
exports.MockConnector = MockConnector; exports.MockProvider = MockProvider;
|