@wagmi/connectors 2.3.0-cjs → 2.3.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/chunk-4BSCIAHY.js +73 -73
- package/dist/chunk-OQILYQDO.js +4 -4
- package/dist/chunk-QYMCVNHT.js +14 -14
- package/dist/chunk-ZCAPXGBX.js +10 -10
- package/dist/coinbaseWallet.js +58 -58
- package/dist/index.js +12 -12
- package/dist/injected.js +9 -9
- package/dist/ledger.js +60 -60
- package/dist/metaMask.js +37 -37
- package/dist/mock/index.js +63 -63
- package/dist/safe.js +46 -46
- package/dist/walletConnect.js +105 -105
- 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 +42 -2
- package/safe/package.json +1 -1
- package/walletConnect/package.json +1 -1
- package/walletConnectLegacy/package.json +1 -1
package/dist/coinbaseWallet.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import {
|
|
2
|
+
ChainNotConfiguredForConnectorError
|
|
3
|
+
} from "./chunk-ZCAPXGBX.js";
|
|
4
|
+
import {
|
|
5
|
+
normalizeChainId
|
|
6
|
+
} from "./chunk-OQILYQDO.js";
|
|
7
|
+
import {
|
|
8
|
+
Connector,
|
|
9
|
+
__privateAdd,
|
|
10
|
+
__privateGet,
|
|
11
|
+
__privateSet,
|
|
12
|
+
__publicField
|
|
13
|
+
} from "./chunk-QYMCVNHT.js";
|
|
14
14
|
|
|
15
15
|
// src/coinbaseWallet.ts
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
import {
|
|
17
|
+
SwitchChainError,
|
|
18
|
+
UserRejectedRequestError,
|
|
19
|
+
createWalletClient,
|
|
20
|
+
custom,
|
|
21
|
+
getAddress,
|
|
22
|
+
numberToHex
|
|
23
|
+
} from "viem";
|
|
24
24
|
var _client, _provider;
|
|
25
|
-
var CoinbaseWalletConnector = class extends
|
|
25
|
+
var CoinbaseWalletConnector = class extends Connector {
|
|
26
26
|
constructor({ chains, options }) {
|
|
27
27
|
super({
|
|
28
28
|
chains,
|
|
@@ -31,23 +31,23 @@ var CoinbaseWalletConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
|
31
31
|
...options
|
|
32
32
|
}
|
|
33
33
|
});
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
__publicField(this, "id", "coinbaseWallet");
|
|
35
|
+
__publicField(this, "name", "Coinbase Wallet");
|
|
36
|
+
__publicField(this, "ready", true);
|
|
37
|
+
__privateAdd(this, _client, void 0);
|
|
38
|
+
__privateAdd(this, _provider, void 0);
|
|
39
|
+
__publicField(this, "onAccountsChanged", (accounts) => {
|
|
40
40
|
if (accounts.length === 0)
|
|
41
41
|
this.emit("disconnect");
|
|
42
42
|
else
|
|
43
|
-
this.emit("change", { account:
|
|
43
|
+
this.emit("change", { account: getAddress(accounts[0]) });
|
|
44
44
|
});
|
|
45
|
-
|
|
46
|
-
const id =
|
|
45
|
+
__publicField(this, "onChainChanged", (chainId) => {
|
|
46
|
+
const id = normalizeChainId(chainId);
|
|
47
47
|
const unsupported = this.isChainUnsupported(id);
|
|
48
48
|
this.emit("change", { chain: { id, unsupported } });
|
|
49
49
|
});
|
|
50
|
-
|
|
50
|
+
__publicField(this, "onDisconnect", () => {
|
|
51
51
|
this.emit("disconnect");
|
|
52
52
|
});
|
|
53
53
|
}
|
|
@@ -59,7 +59,7 @@ var CoinbaseWalletConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
|
59
59
|
provider.on("disconnect", this.onDisconnect);
|
|
60
60
|
this.emit("message", { type: "connecting" });
|
|
61
61
|
const accounts = await provider.enable();
|
|
62
|
-
const account =
|
|
62
|
+
const account = getAddress(accounts[0]);
|
|
63
63
|
let id = await this.getChainId();
|
|
64
64
|
let unsupported = this.isChainUnsupported(id);
|
|
65
65
|
if (chainId && id !== chainId) {
|
|
@@ -75,12 +75,12 @@ var CoinbaseWalletConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
|
75
75
|
if (/(user closed modal|accounts received is empty)/i.test(
|
|
76
76
|
error.message
|
|
77
77
|
))
|
|
78
|
-
throw new
|
|
78
|
+
throw new UserRejectedRequestError(error);
|
|
79
79
|
throw error;
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
async disconnect() {
|
|
83
|
-
if (!
|
|
83
|
+
if (!__privateGet(this, _provider))
|
|
84
84
|
return;
|
|
85
85
|
const provider = await this.getProvider();
|
|
86
86
|
provider.removeListener("accountsChanged", this.onAccountsChanged);
|
|
@@ -94,32 +94,32 @@ var CoinbaseWalletConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
|
94
94
|
const accounts = await provider.request({
|
|
95
95
|
method: "eth_accounts"
|
|
96
96
|
});
|
|
97
|
-
return
|
|
97
|
+
return getAddress(accounts[0]);
|
|
98
98
|
}
|
|
99
99
|
async getChainId() {
|
|
100
100
|
const provider = await this.getProvider();
|
|
101
|
-
const chainId =
|
|
101
|
+
const chainId = normalizeChainId(provider.chainId);
|
|
102
102
|
return chainId;
|
|
103
103
|
}
|
|
104
104
|
async getProvider() {
|
|
105
|
-
if (!
|
|
106
|
-
let CoinbaseWalletSDK = (await
|
|
105
|
+
if (!__privateGet(this, _provider)) {
|
|
106
|
+
let CoinbaseWalletSDK = (await import("@coinbase/wallet-sdk")).default;
|
|
107
107
|
if (typeof CoinbaseWalletSDK !== "function" && typeof CoinbaseWalletSDK.default === "function")
|
|
108
108
|
CoinbaseWalletSDK = CoinbaseWalletSDK.default;
|
|
109
|
-
|
|
109
|
+
__privateSet(this, _client, new CoinbaseWalletSDK(this.options));
|
|
110
110
|
class WalletProvider {
|
|
111
111
|
}
|
|
112
112
|
class Client {
|
|
113
113
|
}
|
|
114
|
-
const walletExtensionChainId =
|
|
114
|
+
const walletExtensionChainId = __privateGet(this, _client).walletExtension?.getChainId();
|
|
115
115
|
const chain = this.chains.find(
|
|
116
116
|
(chain2) => this.options.chainId ? chain2.id === this.options.chainId : chain2.id === walletExtensionChainId
|
|
117
117
|
) || this.chains[0];
|
|
118
|
-
const chainId = this.options.chainId ||
|
|
119
|
-
const jsonRpcUrl = this.options.jsonRpcUrl ||
|
|
120
|
-
|
|
118
|
+
const chainId = this.options.chainId || chain?.id;
|
|
119
|
+
const jsonRpcUrl = this.options.jsonRpcUrl || chain?.rpcUrls.default.http[0];
|
|
120
|
+
__privateSet(this, _provider, __privateGet(this, _client).makeWeb3Provider(jsonRpcUrl, chainId));
|
|
121
121
|
}
|
|
122
|
-
return
|
|
122
|
+
return __privateGet(this, _provider);
|
|
123
123
|
}
|
|
124
124
|
async getWalletClient({ chainId } = {}) {
|
|
125
125
|
const [provider, account] = await Promise.all([
|
|
@@ -129,39 +129,39 @@ var CoinbaseWalletConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
|
129
129
|
const chain = this.chains.find((x) => x.id === chainId);
|
|
130
130
|
if (!provider)
|
|
131
131
|
throw new Error("provider is required.");
|
|
132
|
-
return
|
|
132
|
+
return createWalletClient({
|
|
133
133
|
account,
|
|
134
134
|
chain,
|
|
135
|
-
transport:
|
|
135
|
+
transport: custom(provider)
|
|
136
136
|
});
|
|
137
137
|
}
|
|
138
138
|
async isAuthorized() {
|
|
139
139
|
try {
|
|
140
140
|
const account = await this.getAccount();
|
|
141
141
|
return !!account;
|
|
142
|
-
} catch
|
|
142
|
+
} catch {
|
|
143
143
|
return false;
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
146
|
async switchChain(chainId) {
|
|
147
147
|
const provider = await this.getProvider();
|
|
148
|
-
const id =
|
|
148
|
+
const id = numberToHex(chainId);
|
|
149
149
|
try {
|
|
150
150
|
await provider.request({
|
|
151
151
|
method: "wallet_switchEthereumChain",
|
|
152
152
|
params: [{ chainId: id }]
|
|
153
153
|
});
|
|
154
|
-
return
|
|
154
|
+
return this.chains.find((x) => x.id === chainId) ?? {
|
|
155
155
|
id: chainId,
|
|
156
156
|
name: `Chain ${id}`,
|
|
157
157
|
network: `${id}`,
|
|
158
158
|
nativeCurrency: { name: "Ether", decimals: 18, symbol: "ETH" },
|
|
159
159
|
rpcUrls: { default: { http: [""] }, public: { http: [""] } }
|
|
160
|
-
}
|
|
160
|
+
};
|
|
161
161
|
} catch (error) {
|
|
162
162
|
const chain = this.chains.find((x) => x.id === chainId);
|
|
163
163
|
if (!chain)
|
|
164
|
-
throw new
|
|
164
|
+
throw new ChainNotConfiguredForConnectorError({
|
|
165
165
|
chainId,
|
|
166
166
|
connectorId: this.id
|
|
167
167
|
});
|
|
@@ -174,17 +174,17 @@ var CoinbaseWalletConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
|
174
174
|
chainId: id,
|
|
175
175
|
chainName: chain.name,
|
|
176
176
|
nativeCurrency: chain.nativeCurrency,
|
|
177
|
-
rpcUrls: [
|
|
177
|
+
rpcUrls: [chain.rpcUrls.public?.http[0] ?? ""],
|
|
178
178
|
blockExplorerUrls: this.getBlockExplorerUrls(chain)
|
|
179
179
|
}
|
|
180
180
|
]
|
|
181
181
|
});
|
|
182
182
|
return chain;
|
|
183
183
|
} catch (error2) {
|
|
184
|
-
throw new
|
|
184
|
+
throw new UserRejectedRequestError(error2);
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
|
-
throw new
|
|
187
|
+
throw new SwitchChainError(error);
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
190
|
async watchAsset({
|
|
@@ -210,6 +210,6 @@ var CoinbaseWalletConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
|
210
210
|
};
|
|
211
211
|
_client = new WeakMap();
|
|
212
212
|
_provider = new WeakMap();
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
213
|
+
export {
|
|
214
|
+
CoinbaseWalletConnector
|
|
215
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import {
|
|
2
|
+
ChainNotConfiguredForConnectorError,
|
|
3
|
+
ConnectorNotFoundError
|
|
4
|
+
} from "./chunk-ZCAPXGBX.js";
|
|
5
|
+
import {
|
|
6
|
+
Connector
|
|
7
|
+
} from "./chunk-QYMCVNHT.js";
|
|
8
|
+
export {
|
|
9
|
+
ChainNotConfiguredForConnectorError,
|
|
10
|
+
Connector,
|
|
11
|
+
ConnectorNotFoundError
|
|
12
|
+
};
|
package/dist/injected.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import {
|
|
2
|
+
InjectedConnector
|
|
3
|
+
} from "./chunk-4BSCIAHY.js";
|
|
4
|
+
import "./chunk-ZCAPXGBX.js";
|
|
5
|
+
import "./chunk-OQILYQDO.js";
|
|
6
|
+
import "./chunk-QYMCVNHT.js";
|
|
7
|
+
export {
|
|
8
|
+
InjectedConnector
|
|
9
|
+
};
|
package/dist/ledger.js
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
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
|
-
|
|
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
26
|
var _provider, _switchChain, switchChain_fn;
|
|
27
|
-
var LedgerConnector = class extends
|
|
27
|
+
var LedgerConnector = class extends Connector {
|
|
28
28
|
constructor({
|
|
29
29
|
chains,
|
|
30
30
|
options = { enableDebugLogs: false }
|
|
31
31
|
} = {}) {
|
|
32
32
|
super({ chains, options });
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
__privateAdd(this, _switchChain);
|
|
34
|
+
__publicField(this, "id", "ledger");
|
|
35
|
+
__publicField(this, "name", "Ledger");
|
|
36
|
+
__publicField(this, "ready", true);
|
|
37
|
+
__privateAdd(this, _provider, void 0);
|
|
38
|
+
__publicField(this, "onAccountsChanged", (accounts) => {
|
|
39
39
|
if (accounts.length === 0)
|
|
40
40
|
this.emit("disconnect");
|
|
41
41
|
else
|
|
42
|
-
this.emit("change", { account:
|
|
42
|
+
this.emit("change", { account: getAddress(accounts[0]) });
|
|
43
43
|
});
|
|
44
|
-
|
|
45
|
-
const id =
|
|
44
|
+
__publicField(this, "onChainChanged", (chainId) => {
|
|
45
|
+
const id = normalizeChainId(chainId);
|
|
46
46
|
const unsupported = this.isChainUnsupported(id);
|
|
47
47
|
this.emit("change", { chain: { id, unsupported } });
|
|
48
48
|
});
|
|
49
|
-
|
|
49
|
+
__publicField(this, "onDisconnect", () => {
|
|
50
50
|
this.emit("disconnect");
|
|
51
51
|
});
|
|
52
52
|
}
|
|
@@ -62,17 +62,17 @@ var LedgerConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
|
62
62
|
const accounts = await provider.request({
|
|
63
63
|
method: "eth_requestAccounts"
|
|
64
64
|
});
|
|
65
|
-
const account =
|
|
65
|
+
const account = getAddress(accounts[0]);
|
|
66
66
|
const id = await this.getChainId();
|
|
67
67
|
const unsupported = this.isChainUnsupported(id);
|
|
68
|
-
this.switchChain =
|
|
68
|
+
this.switchChain = __privateMethod(this, _switchChain, switchChain_fn);
|
|
69
69
|
return {
|
|
70
70
|
account,
|
|
71
71
|
chain: { id, unsupported }
|
|
72
72
|
};
|
|
73
73
|
} catch (error) {
|
|
74
74
|
if (error.code === 4001) {
|
|
75
|
-
throw new
|
|
75
|
+
throw new UserRejectedRequestError(error);
|
|
76
76
|
}
|
|
77
77
|
if (error.code === -32002) {
|
|
78
78
|
throw error instanceof Error ? error : new Error(String(error));
|
|
@@ -82,10 +82,10 @@ var LedgerConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
|
82
82
|
}
|
|
83
83
|
async disconnect() {
|
|
84
84
|
const provider = await this.getProvider();
|
|
85
|
-
if (
|
|
85
|
+
if (provider?.disconnect) {
|
|
86
86
|
await provider.disconnect();
|
|
87
87
|
}
|
|
88
|
-
if (
|
|
88
|
+
if (provider?.removeListener) {
|
|
89
89
|
provider.removeListener("accountsChanged", this.onAccountsChanged);
|
|
90
90
|
provider.removeListener("chainChanged", this.onChainChanged);
|
|
91
91
|
provider.removeListener("disconnect", this.onDisconnect);
|
|
@@ -97,7 +97,7 @@ var LedgerConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
|
97
97
|
const accounts = await provider.request({
|
|
98
98
|
method: "eth_accounts"
|
|
99
99
|
});
|
|
100
|
-
const account =
|
|
100
|
+
const account = getAddress(accounts[0]);
|
|
101
101
|
return account;
|
|
102
102
|
}
|
|
103
103
|
async getChainId() {
|
|
@@ -105,13 +105,13 @@ var LedgerConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
|
105
105
|
const chainId = await provider.request({
|
|
106
106
|
method: "eth_chainId"
|
|
107
107
|
});
|
|
108
|
-
return
|
|
108
|
+
return normalizeChainId(chainId);
|
|
109
109
|
}
|
|
110
110
|
async getProvider({ chainId, create } = {
|
|
111
111
|
create: false
|
|
112
112
|
}) {
|
|
113
|
-
if (!
|
|
114
|
-
const connectKit = await
|
|
113
|
+
if (!__privateGet(this, _provider) || chainId || create) {
|
|
114
|
+
const connectKit = await loadConnectKit();
|
|
115
115
|
if (this.options.enableDebugLogs) {
|
|
116
116
|
connectKit.enableDebugLogs();
|
|
117
117
|
}
|
|
@@ -124,13 +124,13 @@ var LedgerConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
|
124
124
|
);
|
|
125
125
|
connectKit.checkSupport({
|
|
126
126
|
bridge: this.options.bridge,
|
|
127
|
-
providerType:
|
|
127
|
+
providerType: SupportedProviders.Ethereum,
|
|
128
128
|
chainId: chainId || this.options.chainId,
|
|
129
|
-
rpc: { ...rpc, ...
|
|
129
|
+
rpc: { ...rpc, ...this.options?.rpc }
|
|
130
130
|
});
|
|
131
|
-
|
|
131
|
+
__privateSet(this, _provider, await connectKit.getProvider());
|
|
132
132
|
}
|
|
133
|
-
return
|
|
133
|
+
return __privateGet(this, _provider);
|
|
134
134
|
}
|
|
135
135
|
async getWalletClient({ chainId } = {}) {
|
|
136
136
|
const [provider, account] = await Promise.all([
|
|
@@ -140,17 +140,17 @@ var LedgerConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
|
140
140
|
const chain = this.chains.find((x) => x.id === chainId);
|
|
141
141
|
if (!provider)
|
|
142
142
|
throw new Error("provider is required.");
|
|
143
|
-
return
|
|
143
|
+
return createWalletClient({
|
|
144
144
|
account,
|
|
145
145
|
chain,
|
|
146
|
-
transport:
|
|
146
|
+
transport: custom(provider)
|
|
147
147
|
});
|
|
148
148
|
}
|
|
149
149
|
async isAuthorized() {
|
|
150
150
|
try {
|
|
151
151
|
const account = await this.getAccount();
|
|
152
152
|
return !!account;
|
|
153
|
-
} catch
|
|
153
|
+
} catch {
|
|
154
154
|
return false;
|
|
155
155
|
}
|
|
156
156
|
}
|
|
@@ -159,7 +159,7 @@ _provider = new WeakMap();
|
|
|
159
159
|
_switchChain = new WeakSet();
|
|
160
160
|
switchChain_fn = async function(chainId) {
|
|
161
161
|
const provider = await this.getProvider();
|
|
162
|
-
const id =
|
|
162
|
+
const id = numberToHex(chainId);
|
|
163
163
|
try {
|
|
164
164
|
await Promise.race([
|
|
165
165
|
provider.request({
|
|
@@ -168,25 +168,25 @@ switchChain_fn = async function(chainId) {
|
|
|
168
168
|
}),
|
|
169
169
|
new Promise(
|
|
170
170
|
(res) => this.on("change", ({ chain }) => {
|
|
171
|
-
if (
|
|
171
|
+
if (chain?.id === chainId)
|
|
172
172
|
res(chainId);
|
|
173
173
|
})
|
|
174
174
|
)
|
|
175
175
|
]);
|
|
176
|
-
return
|
|
176
|
+
return this.chains.find((x) => x.id === chainId) ?? {
|
|
177
177
|
id: chainId,
|
|
178
178
|
name: `Chain ${id}`,
|
|
179
179
|
network: `${id}`,
|
|
180
180
|
nativeCurrency: { name: "Ether", decimals: 18, symbol: "ETH" },
|
|
181
181
|
rpcUrls: { default: { http: [""] }, public: { http: [""] } }
|
|
182
|
-
}
|
|
182
|
+
};
|
|
183
183
|
} catch (error) {
|
|
184
|
-
const message = typeof error === "string" ? error :
|
|
184
|
+
const message = typeof error === "string" ? error : error?.message;
|
|
185
185
|
if (/user rejected request/i.test(message))
|
|
186
|
-
throw new
|
|
187
|
-
throw new
|
|
186
|
+
throw new UserRejectedRequestError(error);
|
|
187
|
+
throw new SwitchChainError(error);
|
|
188
188
|
}
|
|
189
189
|
};
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
190
|
+
export {
|
|
191
|
+
LedgerConnector
|
|
192
|
+
};
|
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-4BSCIAHY.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
|
+
};
|