@wagmi/connectors 2.3.0-cjs → 2.4.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/coinbaseWallet/package.json +1 -1
- package/dist/{base-0473abd3.d.ts → base-2dd7facf.d.ts} +1 -0
- package/dist/chunk-OQILYQDO.js +4 -4
- package/dist/chunk-QYMCVNHT.js +14 -14
- package/dist/{chunk-4BSCIAHY.js → chunk-Z2P63ELM.js} +75 -73
- package/dist/chunk-ZCAPXGBX.js +10 -10
- package/dist/coinbaseWallet.d.ts +1 -1
- package/dist/coinbaseWallet.js +58 -58
- package/dist/index.d.ts +4 -2
- package/dist/index.js +16 -12
- package/dist/injected.d.ts +1 -1
- package/dist/injected.js +9 -9
- package/dist/ledger.d.ts +33 -6
- package/dist/ledger.js +194 -126
- package/dist/metaMask.d.ts +1 -1
- package/dist/metaMask.js +37 -37
- package/dist/mock/index.d.ts +1 -1
- package/dist/mock/index.js +63 -63
- package/dist/safe.d.ts +1 -1
- package/dist/safe.js +46 -46
- package/dist/walletConnect.d.ts +1 -1
- package/dist/walletConnect.js +105 -105
- package/dist/walletConnectLegacy.d.ts +1 -1
- package/dist/walletConnectLegacy.js +58 -58
- package/injected/package.json +1 -1
- package/ledger/package.json +1 -1
- package/metaMask/package.json +1 -1
- package/mock/package.json +1 -1
- package/package.json +46 -6
- package/safe/package.json +1 -1
- package/walletConnect/package.json +1 -1
- package/walletConnectLegacy/package.json +1 -1
package/dist/ledger.js
CHANGED
|
@@ -1,103 +1,120 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import {
|
|
2
|
+
normalizeChainId
|
|
3
|
+
} from "./chunk-OQILYQDO.js";
|
|
4
|
+
import {
|
|
5
|
+
Connector,
|
|
6
|
+
__privateAdd,
|
|
7
|
+
__privateGet,
|
|
8
|
+
__privateMethod,
|
|
9
|
+
__privateSet,
|
|
10
|
+
__publicField
|
|
11
|
+
} from "./chunk-QYMCVNHT.js";
|
|
12
12
|
|
|
13
13
|
// src/ledger.ts
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
var _provider,
|
|
27
|
-
var LedgerConnector = class extends
|
|
28
|
-
constructor({
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
14
|
+
import {
|
|
15
|
+
SupportedProviders,
|
|
16
|
+
loadConnectKit
|
|
17
|
+
} from "@ledgerhq/connect-kit-loader";
|
|
18
|
+
import {
|
|
19
|
+
SwitchChainError,
|
|
20
|
+
UserRejectedRequestError,
|
|
21
|
+
createWalletClient,
|
|
22
|
+
custom,
|
|
23
|
+
getAddress,
|
|
24
|
+
numberToHex
|
|
25
|
+
} from "viem";
|
|
26
|
+
var _provider, _initProviderPromise, _isV1, _createProvider, createProvider_fn, _initProvider, initProvider_fn, _setupListeners, setupListeners_fn, _removeListeners, removeListeners_fn;
|
|
27
|
+
var LedgerConnector = class extends Connector {
|
|
28
|
+
constructor(config) {
|
|
29
|
+
super({
|
|
30
|
+
...config,
|
|
31
|
+
options: { ...config.options }
|
|
32
|
+
});
|
|
33
|
+
__privateAdd(this, _createProvider);
|
|
34
|
+
__privateAdd(this, _initProvider);
|
|
35
|
+
__privateAdd(this, _setupListeners);
|
|
36
|
+
__privateAdd(this, _removeListeners);
|
|
37
|
+
__publicField(this, "id", "ledger");
|
|
38
|
+
__publicField(this, "name", "Ledger");
|
|
39
|
+
__publicField(this, "ready", true);
|
|
40
|
+
__privateAdd(this, _provider, void 0);
|
|
41
|
+
__privateAdd(this, _initProviderPromise, void 0);
|
|
42
|
+
__privateAdd(this, _isV1, void 0);
|
|
43
|
+
__publicField(this, "onAccountsChanged", (accounts) => {
|
|
39
44
|
if (accounts.length === 0)
|
|
40
45
|
this.emit("disconnect");
|
|
41
46
|
else
|
|
42
|
-
this.emit("change", { account:
|
|
47
|
+
this.emit("change", { account: getAddress(accounts[0]) });
|
|
43
48
|
});
|
|
44
|
-
|
|
45
|
-
const id =
|
|
49
|
+
__publicField(this, "onChainChanged", (chainId) => {
|
|
50
|
+
const id = normalizeChainId(chainId);
|
|
46
51
|
const unsupported = this.isChainUnsupported(id);
|
|
47
52
|
this.emit("change", { chain: { id, unsupported } });
|
|
48
53
|
});
|
|
49
|
-
|
|
54
|
+
__publicField(this, "onDisconnect", () => {
|
|
50
55
|
this.emit("disconnect");
|
|
51
56
|
});
|
|
57
|
+
__publicField(this, "onConnect", () => {
|
|
58
|
+
this.emit("connect", {});
|
|
59
|
+
});
|
|
60
|
+
__privateSet(this, _isV1, this.walletConnectVersion === 1);
|
|
61
|
+
}
|
|
62
|
+
get walletConnectVersion() {
|
|
63
|
+
if (this.options.walletConnectVersion)
|
|
64
|
+
return this.options.walletConnectVersion;
|
|
65
|
+
else if (this.options.projectId)
|
|
66
|
+
return 2;
|
|
67
|
+
return 1;
|
|
52
68
|
}
|
|
53
|
-
async connect() {
|
|
69
|
+
async connect({ chainId } = {}) {
|
|
54
70
|
try {
|
|
55
71
|
const provider = await this.getProvider({ create: true });
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
provider.
|
|
72
|
+
__privateMethod(this, _setupListeners, setupListeners_fn).call(this);
|
|
73
|
+
if (!provider.session) {
|
|
74
|
+
this.emit("message", { type: "connecting" });
|
|
75
|
+
await provider.request({
|
|
76
|
+
method: "eth_requestAccounts"
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
const account = await this.getAccount();
|
|
80
|
+
let id = await this.getChainId();
|
|
81
|
+
let unsupported = this.isChainUnsupported(id);
|
|
82
|
+
if (chainId && id !== chainId) {
|
|
83
|
+
const chain = await this.switchChain(chainId);
|
|
84
|
+
id = chain.id;
|
|
85
|
+
unsupported = this.isChainUnsupported(id);
|
|
60
86
|
}
|
|
61
|
-
this.emit("message", { type: "connecting" });
|
|
62
|
-
const accounts = await provider.request({
|
|
63
|
-
method: "eth_requestAccounts"
|
|
64
|
-
});
|
|
65
|
-
const account = _viem.getAddress.call(void 0, accounts[0]);
|
|
66
|
-
const id = await this.getChainId();
|
|
67
|
-
const unsupported = this.isChainUnsupported(id);
|
|
68
|
-
this.switchChain = _chunkQYMCVNHTjs.__privateMethod.call(void 0, this, _switchChain, switchChain_fn);
|
|
69
87
|
return {
|
|
70
88
|
account,
|
|
71
|
-
chain: { id, unsupported }
|
|
89
|
+
chain: { id, unsupported },
|
|
90
|
+
provider
|
|
72
91
|
};
|
|
73
92
|
} catch (error) {
|
|
74
|
-
if (error
|
|
75
|
-
throw new
|
|
76
|
-
}
|
|
77
|
-
if (error.code === -32002) {
|
|
78
|
-
throw error instanceof Error ? error : new Error(String(error));
|
|
93
|
+
if (/user rejected/i.test(error?.message)) {
|
|
94
|
+
throw new UserRejectedRequestError(error);
|
|
79
95
|
}
|
|
80
96
|
throw error;
|
|
81
97
|
}
|
|
82
98
|
}
|
|
83
99
|
async disconnect() {
|
|
84
100
|
const provider = await this.getProvider();
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
101
|
+
try {
|
|
102
|
+
if (provider?.disconnect)
|
|
103
|
+
await provider.disconnect();
|
|
104
|
+
} catch (error) {
|
|
105
|
+
if (!/No matching key/i.test(error.message))
|
|
106
|
+
throw error;
|
|
107
|
+
} finally {
|
|
108
|
+
__privateMethod(this, _removeListeners, removeListeners_fn).call(this);
|
|
109
|
+
__privateGet(this, _isV1) && typeof localStorage !== "undefined" && localStorage.removeItem("walletconnect");
|
|
92
110
|
}
|
|
93
|
-
typeof localStorage !== "undefined" && localStorage.removeItem("walletconnect");
|
|
94
111
|
}
|
|
95
112
|
async getAccount() {
|
|
96
113
|
const provider = await this.getProvider();
|
|
97
114
|
const accounts = await provider.request({
|
|
98
115
|
method: "eth_accounts"
|
|
99
116
|
});
|
|
100
|
-
const account =
|
|
117
|
+
const account = getAddress(accounts[0]);
|
|
101
118
|
return account;
|
|
102
119
|
}
|
|
103
120
|
async getChainId() {
|
|
@@ -105,32 +122,17 @@ var LedgerConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
|
105
122
|
const chainId = await provider.request({
|
|
106
123
|
method: "eth_chainId"
|
|
107
124
|
});
|
|
108
|
-
return
|
|
125
|
+
return normalizeChainId(chainId);
|
|
109
126
|
}
|
|
110
127
|
async getProvider({ chainId, create } = {
|
|
111
128
|
create: false
|
|
112
129
|
}) {
|
|
113
|
-
if (!
|
|
114
|
-
|
|
115
|
-
if (this.options.enableDebugLogs) {
|
|
116
|
-
connectKit.enableDebugLogs();
|
|
117
|
-
}
|
|
118
|
-
const rpc = this.chains.reduce(
|
|
119
|
-
(rpc2, chain) => ({
|
|
120
|
-
...rpc2,
|
|
121
|
-
[chain.id]: chain.rpcUrls.default.http[0]
|
|
122
|
-
}),
|
|
123
|
-
{}
|
|
124
|
-
);
|
|
125
|
-
connectKit.checkSupport({
|
|
126
|
-
bridge: this.options.bridge,
|
|
127
|
-
providerType: _connectkitloader.SupportedProviders.Ethereum,
|
|
128
|
-
chainId: chainId || this.options.chainId,
|
|
129
|
-
rpc: { ...rpc, ..._optionalChain([this, 'access', _3 => _3.options, 'optionalAccess', _4 => _4.rpc]) }
|
|
130
|
-
});
|
|
131
|
-
_chunkQYMCVNHTjs.__privateSet.call(void 0, this, _provider, await connectKit.getProvider());
|
|
130
|
+
if (!__privateGet(this, _provider) || __privateGet(this, _isV1) && create) {
|
|
131
|
+
await __privateMethod(this, _createProvider, createProvider_fn).call(this);
|
|
132
132
|
}
|
|
133
|
-
|
|
133
|
+
if (chainId)
|
|
134
|
+
await this.switchChain(chainId);
|
|
135
|
+
return __privateGet(this, _provider);
|
|
134
136
|
}
|
|
135
137
|
async getWalletClient({ chainId } = {}) {
|
|
136
138
|
const [provider, account] = await Promise.all([
|
|
@@ -140,53 +142,119 @@ var LedgerConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
|
140
142
|
const chain = this.chains.find((x) => x.id === chainId);
|
|
141
143
|
if (!provider)
|
|
142
144
|
throw new Error("provider is required.");
|
|
143
|
-
return
|
|
144
|
-
account,
|
|
145
|
-
chain,
|
|
146
|
-
transport: _viem.custom.call(void 0, provider)
|
|
147
|
-
});
|
|
145
|
+
return createWalletClient({ account, chain, transport: custom(provider) });
|
|
148
146
|
}
|
|
149
147
|
async isAuthorized() {
|
|
150
148
|
try {
|
|
151
149
|
const account = await this.getAccount();
|
|
152
150
|
return !!account;
|
|
153
|
-
} catch
|
|
151
|
+
} catch {
|
|
154
152
|
return false;
|
|
155
153
|
}
|
|
156
154
|
}
|
|
155
|
+
async switchChain(chainId) {
|
|
156
|
+
const chain = this.chains.find((chain2) => chain2.id === chainId);
|
|
157
|
+
if (!chain)
|
|
158
|
+
throw new SwitchChainError(new Error("chain not found on connector."));
|
|
159
|
+
try {
|
|
160
|
+
const provider = await this.getProvider();
|
|
161
|
+
await provider.request({
|
|
162
|
+
method: "wallet_switchEthereumChain",
|
|
163
|
+
params: [{ chainId: numberToHex(chainId) }]
|
|
164
|
+
});
|
|
165
|
+
return chain;
|
|
166
|
+
} catch (error) {
|
|
167
|
+
const message = typeof error === "string" ? error : error?.message;
|
|
168
|
+
if (/user rejected request/i.test(message)) {
|
|
169
|
+
throw new UserRejectedRequestError(error);
|
|
170
|
+
}
|
|
171
|
+
throw new SwitchChainError(error);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
157
174
|
};
|
|
158
175
|
_provider = new WeakMap();
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
176
|
+
_initProviderPromise = new WeakMap();
|
|
177
|
+
_isV1 = new WeakMap();
|
|
178
|
+
_createProvider = new WeakSet();
|
|
179
|
+
createProvider_fn = async function() {
|
|
180
|
+
if (!__privateGet(this, _initProviderPromise) && typeof window !== "undefined") {
|
|
181
|
+
__privateSet(this, _initProviderPromise, __privateMethod(this, _initProvider, initProvider_fn).call(this));
|
|
182
|
+
}
|
|
183
|
+
return __privateGet(this, _initProviderPromise);
|
|
184
|
+
};
|
|
185
|
+
_initProvider = new WeakSet();
|
|
186
|
+
initProvider_fn = async function() {
|
|
187
|
+
const connectKit = await loadConnectKit();
|
|
188
|
+
if (this.options.enableDebugLogs) {
|
|
189
|
+
connectKit.enableDebugLogs();
|
|
190
|
+
}
|
|
191
|
+
let checkSupportOptions;
|
|
192
|
+
if (__privateGet(this, _isV1)) {
|
|
193
|
+
const { chainId, bridge } = this.options;
|
|
194
|
+
checkSupportOptions = {
|
|
195
|
+
providerType: SupportedProviders.Ethereum,
|
|
196
|
+
walletConnectVersion: 1,
|
|
197
|
+
chainId,
|
|
198
|
+
bridge,
|
|
199
|
+
rpc: Object.fromEntries(
|
|
200
|
+
this.chains.map((chain) => [
|
|
201
|
+
chain.id,
|
|
202
|
+
chain.rpcUrls.default.http[0]
|
|
203
|
+
])
|
|
174
204
|
)
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
205
|
+
};
|
|
206
|
+
} else {
|
|
207
|
+
const {
|
|
208
|
+
projectId,
|
|
209
|
+
requiredChains,
|
|
210
|
+
requiredMethods,
|
|
211
|
+
optionalMethods,
|
|
212
|
+
requiredEvents,
|
|
213
|
+
optionalEvents
|
|
214
|
+
} = this.options;
|
|
215
|
+
const optionalChains = this.chains.map(({ id }) => id);
|
|
216
|
+
checkSupportOptions = {
|
|
217
|
+
providerType: SupportedProviders.Ethereum,
|
|
218
|
+
walletConnectVersion: 2,
|
|
219
|
+
projectId,
|
|
220
|
+
chains: requiredChains,
|
|
221
|
+
optionalChains,
|
|
222
|
+
methods: requiredMethods,
|
|
223
|
+
optionalMethods,
|
|
224
|
+
events: requiredEvents,
|
|
225
|
+
optionalEvents,
|
|
226
|
+
rpcMap: Object.fromEntries(
|
|
227
|
+
this.chains.map((chain) => [
|
|
228
|
+
chain.id,
|
|
229
|
+
chain.rpcUrls.default.http[0]
|
|
230
|
+
])
|
|
231
|
+
)
|
|
232
|
+
};
|
|
188
233
|
}
|
|
234
|
+
connectKit.checkSupport(checkSupportOptions);
|
|
235
|
+
__privateSet(this, _provider, await connectKit.getProvider());
|
|
236
|
+
};
|
|
237
|
+
_setupListeners = new WeakSet();
|
|
238
|
+
setupListeners_fn = function() {
|
|
239
|
+
if (!__privateGet(this, _provider))
|
|
240
|
+
return;
|
|
241
|
+
__privateMethod(this, _removeListeners, removeListeners_fn).call(this);
|
|
242
|
+
__privateGet(this, _provider).on("accountsChanged", this.onAccountsChanged);
|
|
243
|
+
__privateGet(this, _provider).on("chainChanged", this.onChainChanged);
|
|
244
|
+
__privateGet(this, _provider).on("disconnect", this.onDisconnect);
|
|
245
|
+
__privateGet(this, _provider).on("session_delete", this.onDisconnect);
|
|
246
|
+
__privateGet(this, _provider).on("connect", this.onConnect);
|
|
247
|
+
};
|
|
248
|
+
_removeListeners = new WeakSet();
|
|
249
|
+
removeListeners_fn = function() {
|
|
250
|
+
if (!__privateGet(this, _provider))
|
|
251
|
+
return;
|
|
252
|
+
__privateGet(this, _provider).removeListener("accountsChanged", this.onAccountsChanged);
|
|
253
|
+
__privateGet(this, _provider).removeListener("chainChanged", this.onChainChanged);
|
|
254
|
+
__privateGet(this, _provider).removeListener("disconnect", this.onDisconnect);
|
|
255
|
+
__privateGet(this, _provider).removeListener("session_delete", this.onDisconnect);
|
|
256
|
+
__privateGet(this, _provider).removeListener("connect", this.onConnect);
|
|
257
|
+
};
|
|
258
|
+
export {
|
|
259
|
+
LedgerConnector
|
|
189
260
|
};
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
exports.LedgerConnector = LedgerConnector;
|
package/dist/metaMask.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Chain } from '@wagmi/chains';
|
|
2
2
|
import { InjectedConnectorOptions, InjectedConnector } from './injected.js';
|
|
3
|
-
import { W as WindowProvider } from './base-
|
|
3
|
+
import { W as WindowProvider } from './base-2dd7facf.js';
|
|
4
4
|
import 'viem';
|
|
5
5
|
import 'eventemitter3';
|
|
6
6
|
|
package/dist/metaMask.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import {
|
|
2
|
+
InjectedConnector
|
|
3
|
+
} from "./chunk-Z2P63ELM.js";
|
|
4
|
+
import {
|
|
5
|
+
ConnectorNotFoundError
|
|
6
|
+
} from "./chunk-ZCAPXGBX.js";
|
|
7
|
+
import "./chunk-OQILYQDO.js";
|
|
8
|
+
import {
|
|
9
|
+
__privateAdd,
|
|
10
|
+
__privateGet,
|
|
11
|
+
__privateSet,
|
|
12
|
+
__publicField
|
|
13
|
+
} from "./chunk-QYMCVNHT.js";
|
|
14
14
|
|
|
15
15
|
// src/metaMask.ts
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
import {
|
|
17
|
+
ResourceUnavailableRpcError,
|
|
18
|
+
UserRejectedRequestError,
|
|
19
|
+
getAddress
|
|
20
|
+
} from "viem";
|
|
21
21
|
var _UNSTABLE_shimOnConnectSelectAccount;
|
|
22
|
-
var MetaMaskConnector = class extends
|
|
22
|
+
var MetaMaskConnector = class extends InjectedConnector {
|
|
23
23
|
constructor({
|
|
24
24
|
chains,
|
|
25
25
|
options: options_
|
|
@@ -29,7 +29,7 @@ var MetaMaskConnector = class extends _chunk4BSCIAHYjs.InjectedConnector {
|
|
|
29
29
|
shimDisconnect: true,
|
|
30
30
|
getProvider() {
|
|
31
31
|
function getReady(ethereum2) {
|
|
32
|
-
const isMetaMask = !!
|
|
32
|
+
const isMetaMask = !!ethereum2?.isMetaMask;
|
|
33
33
|
if (!isMetaMask)
|
|
34
34
|
return;
|
|
35
35
|
if (ethereum2.isBraveWallet && !ethereum2._events && !ethereum2._state)
|
|
@@ -67,23 +67,23 @@ var MetaMaskConnector = class extends _chunk4BSCIAHYjs.InjectedConnector {
|
|
|
67
67
|
if (typeof window === "undefined")
|
|
68
68
|
return;
|
|
69
69
|
const ethereum = window.ethereum;
|
|
70
|
-
if (
|
|
70
|
+
if (ethereum?.providers)
|
|
71
71
|
return ethereum.providers.find(getReady);
|
|
72
72
|
return getReady(ethereum);
|
|
73
73
|
},
|
|
74
74
|
...options_
|
|
75
75
|
};
|
|
76
76
|
super({ chains, options });
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
77
|
+
__publicField(this, "id", "metaMask");
|
|
78
|
+
__publicField(this, "shimDisconnectKey", `${this.id}.shimDisconnect`);
|
|
79
|
+
__privateAdd(this, _UNSTABLE_shimOnConnectSelectAccount, void 0);
|
|
80
|
+
__privateSet(this, _UNSTABLE_shimOnConnectSelectAccount, options.UNSTABLE_shimOnConnectSelectAccount);
|
|
81
81
|
}
|
|
82
82
|
async connect({ chainId } = {}) {
|
|
83
83
|
try {
|
|
84
84
|
const provider = await this.getProvider();
|
|
85
85
|
if (!provider)
|
|
86
|
-
throw new
|
|
86
|
+
throw new ConnectorNotFoundError();
|
|
87
87
|
if (provider.on) {
|
|
88
88
|
provider.on("accountsChanged", this.onAccountsChanged);
|
|
89
89
|
provider.on("chainChanged", this.onChainChanged);
|
|
@@ -91,7 +91,7 @@ var MetaMaskConnector = class extends _chunk4BSCIAHYjs.InjectedConnector {
|
|
|
91
91
|
}
|
|
92
92
|
this.emit("message", { type: "connecting" });
|
|
93
93
|
let account = null;
|
|
94
|
-
if (
|
|
94
|
+
if (__privateGet(this, _UNSTABLE_shimOnConnectSelectAccount) && this.options?.shimDisconnect && !this.storage?.getItem(this.shimDisconnectKey)) {
|
|
95
95
|
account = await this.getAccount().catch(() => null);
|
|
96
96
|
const isConnected = !!account;
|
|
97
97
|
if (isConnected)
|
|
@@ -103,8 +103,8 @@ var MetaMaskConnector = class extends _chunk4BSCIAHYjs.InjectedConnector {
|
|
|
103
103
|
account = await this.getAccount();
|
|
104
104
|
} catch (error) {
|
|
105
105
|
if (this.isUserRejectedRequestError(error))
|
|
106
|
-
throw new
|
|
107
|
-
if (error.code === new
|
|
106
|
+
throw new UserRejectedRequestError(error);
|
|
107
|
+
if (error.code === new ResourceUnavailableRpcError(error).code)
|
|
108
108
|
throw error;
|
|
109
109
|
}
|
|
110
110
|
}
|
|
@@ -112,7 +112,7 @@ var MetaMaskConnector = class extends _chunk4BSCIAHYjs.InjectedConnector {
|
|
|
112
112
|
const accounts = await provider.request({
|
|
113
113
|
method: "eth_requestAccounts"
|
|
114
114
|
});
|
|
115
|
-
account =
|
|
115
|
+
account = getAddress(accounts[0]);
|
|
116
116
|
}
|
|
117
117
|
let id = await this.getChainId();
|
|
118
118
|
let unsupported = this.isChainUnsupported(id);
|
|
@@ -121,19 +121,19 @@ var MetaMaskConnector = class extends _chunk4BSCIAHYjs.InjectedConnector {
|
|
|
121
121
|
id = chain.id;
|
|
122
122
|
unsupported = this.isChainUnsupported(id);
|
|
123
123
|
}
|
|
124
|
-
if (
|
|
125
|
-
|
|
124
|
+
if (this.options?.shimDisconnect)
|
|
125
|
+
this.storage?.setItem(this.shimDisconnectKey, true);
|
|
126
126
|
return { account, chain: { id, unsupported }, provider };
|
|
127
127
|
} catch (error) {
|
|
128
128
|
if (this.isUserRejectedRequestError(error))
|
|
129
|
-
throw new
|
|
129
|
+
throw new UserRejectedRequestError(error);
|
|
130
130
|
if (error.code === -32002)
|
|
131
|
-
throw new
|
|
131
|
+
throw new ResourceUnavailableRpcError(error);
|
|
132
132
|
throw error;
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
};
|
|
136
136
|
_UNSTABLE_shimOnConnectSelectAccount = new WeakMap();
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
137
|
+
export {
|
|
138
|
+
MetaMaskConnector
|
|
139
|
+
};
|
package/dist/mock/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as viem from 'viem';
|
|
2
2
|
import { Chain } from '@wagmi/chains';
|
|
3
|
-
import { c as WalletClient, C as Connector, a as ConnectorData } from '../base-
|
|
3
|
+
import { c as WalletClient, C as Connector, a as ConnectorData } from '../base-2dd7facf.js';
|
|
4
4
|
import EventEmitter from 'eventemitter3';
|
|
5
5
|
|
|
6
6
|
type MockProviderOptions = {
|