@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
|
@@ -1,41 +1,41 @@
|
|
|
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/walletConnectLegacy.ts
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
import {
|
|
14
|
+
SwitchChainError,
|
|
15
|
+
UserRejectedRequestError,
|
|
16
|
+
createWalletClient,
|
|
17
|
+
custom,
|
|
18
|
+
getAddress,
|
|
19
|
+
numberToHex
|
|
20
|
+
} from "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
|
|
23
|
+
var WalletConnectLegacyConnector = class extends Connector {
|
|
24
24
|
constructor() {
|
|
25
25
|
super(...arguments);
|
|
26
|
-
|
|
26
|
+
__privateAdd(this, _switchChain);
|
|
27
27
|
this.id = "walletConnectLegacy";
|
|
28
28
|
this.name = "WalletConnectLegacy";
|
|
29
29
|
this.ready = true;
|
|
30
|
-
|
|
30
|
+
__privateAdd(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:
|
|
35
|
+
this.emit("change", { account: getAddress(accounts[0]) });
|
|
36
36
|
};
|
|
37
37
|
this.onChainChanged = (chainId) => {
|
|
38
|
-
const id =
|
|
38
|
+
const id = normalizeChainId(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 _chunkW65LBPLTjs.Connector {
|
|
|
47
47
|
try {
|
|
48
48
|
let targetChainId = chainId;
|
|
49
49
|
if (!targetChainId) {
|
|
50
|
-
const store =
|
|
51
|
-
const lastUsedChainId =
|
|
50
|
+
const store = this.storage?.getItem("store");
|
|
51
|
+
const lastUsedChainId = store?.state?.data?.chain?.id;
|
|
52
52
|
if (lastUsedChainId && !this.isChainUnsupported(lastUsedChainId))
|
|
53
53
|
targetChainId = lastUsedChainId;
|
|
54
54
|
}
|
|
@@ -61,19 +61,19 @@ var WalletConnectLegacyConnector = class extends _chunkW65LBPLTjs.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 =
|
|
64
|
+
const account = getAddress(accounts[0]);
|
|
65
65
|
const id = await this.getChainId();
|
|
66
66
|
const unsupported = this.isChainUnsupported(id);
|
|
67
|
-
const walletName =
|
|
67
|
+
const walletName = provider.connector?.peerMeta?.name ?? "";
|
|
68
68
|
if (switchChainAllowedRegex.test(walletName))
|
|
69
|
-
this.switchChain =
|
|
69
|
+
this.switchChain = __privateMethod(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
|
|
76
|
+
throw new UserRejectedRequestError(error);
|
|
77
77
|
throw error;
|
|
78
78
|
}
|
|
79
79
|
}
|
|
@@ -88,34 +88,34 @@ var WalletConnectLegacyConnector = class extends _chunkW65LBPLTjs.Connector {
|
|
|
88
88
|
async getAccount() {
|
|
89
89
|
const provider = await this.getProvider();
|
|
90
90
|
const accounts = provider.accounts;
|
|
91
|
-
return
|
|
91
|
+
return getAddress(accounts[0]);
|
|
92
92
|
}
|
|
93
93
|
async getChainId() {
|
|
94
94
|
const provider = await this.getProvider();
|
|
95
|
-
const chainId =
|
|
95
|
+
const chainId = normalizeChainId(provider.chainId);
|
|
96
96
|
return chainId;
|
|
97
97
|
}
|
|
98
98
|
async getProvider({
|
|
99
99
|
chainId,
|
|
100
100
|
create
|
|
101
101
|
} = {}) {
|
|
102
|
-
if (!
|
|
103
|
-
const rpc = !
|
|
102
|
+
if (!__privateGet(this, _provider) || chainId || create) {
|
|
103
|
+
const rpc = !this.options?.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
|
-
|
|
110
|
+
const WalletConnectProvider = (await import("@walletconnect/legacy-provider")).default;
|
|
111
|
+
__privateSet(this, _provider, new WalletConnectProvider({
|
|
112
112
|
...this.options,
|
|
113
113
|
chainId,
|
|
114
|
-
rpc: { ...rpc, ...
|
|
114
|
+
rpc: { ...rpc, ...this.options?.rpc }
|
|
115
115
|
}));
|
|
116
|
-
|
|
116
|
+
__privateGet(this, _provider).http = await __privateGet(this, _provider).setHttpProvider(chainId);
|
|
117
117
|
}
|
|
118
|
-
return
|
|
118
|
+
return __privateGet(this, _provider);
|
|
119
119
|
}
|
|
120
120
|
async getWalletClient({
|
|
121
121
|
chainId
|
|
@@ -127,17 +127,17 @@ var WalletConnectLegacyConnector = class extends _chunkW65LBPLTjs.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
|
|
130
|
+
return createWalletClient({
|
|
131
131
|
account,
|
|
132
132
|
chain,
|
|
133
|
-
transport:
|
|
133
|
+
transport: custom(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 {
|
|
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 =
|
|
149
|
+
const id = numberToHex(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 (
|
|
158
|
+
if (chain?.id === chainId)
|
|
159
159
|
res(chainId);
|
|
160
160
|
})
|
|
161
161
|
)
|
|
162
162
|
]);
|
|
163
|
-
return
|
|
163
|
+
return 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 :
|
|
171
|
+
const message = typeof error === "string" ? error : error?.message;
|
|
172
172
|
if (/user rejected request/i.test(message))
|
|
173
|
-
throw new
|
|
174
|
-
throw new
|
|
173
|
+
throw new UserRejectedRequestError(error);
|
|
174
|
+
throw new SwitchChainError(error);
|
|
175
175
|
}
|
|
176
176
|
};
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
177
|
+
export {
|
|
178
|
+
WalletConnectLegacyConnector
|
|
179
|
+
};
|
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.2
|
|
5
|
+
"version": "3.1.2",
|
|
6
6
|
"peerDependencies": {
|
|
7
7
|
"typescript": ">=5.0.4",
|
|
8
8
|
"viem": ">=0.3.35"
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"viem": "^1.0.0"
|
|
29
29
|
},
|
|
30
|
+
"type": "module",
|
|
30
31
|
"main": "dist/index.js",
|
|
31
32
|
"types": "dist/index.d.ts",
|
|
32
33
|
"exports": {
|