@wagmi/connectors 1.0.0-next.4 → 1.0.0-next.6
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/base-a11da01a.d.ts +132 -0
- package/dist/chunk-K4TVWOJP.js +370 -0
- package/dist/chunk-OQILYQDO.js +15 -0
- package/dist/chunk-QYMCVNHT.js +68 -0
- package/dist/chunk-ZCAPXGBX.js +26 -0
- package/dist/coinbaseWallet.d.ts +831 -1
- package/dist/coinbaseWallet.js +215 -0
- package/dist/index.d.ts +19 -1
- package/dist/index.js +12 -0
- package/dist/injected.d.ts +833 -1
- package/dist/injected.js +9 -0
- package/dist/ledger.d.ts +810 -1
- package/dist/ledger.js +192 -0
- package/dist/metaMask.d.ts +37 -1
- package/dist/metaMask.js +139 -0
- package/dist/mock/index.d.ts +1578 -1
- package/dist/mock/index.js +202 -0
- package/dist/safe.d.ts +822 -1
- package/dist/safe.js +128 -0
- package/dist/walletConnect.d.ts +917 -1
- package/dist/walletConnect.js +311 -0
- package/dist/walletConnectLegacy.d.ts +811 -1
- package/dist/walletConnectLegacy.js +178 -0
- package/package.json +9 -9
|
@@ -0,0 +1,215 @@
|
|
|
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
|
+
|
|
15
|
+
// src/coinbaseWallet.ts
|
|
16
|
+
import {
|
|
17
|
+
SwitchChainError,
|
|
18
|
+
UserRejectedRequestError,
|
|
19
|
+
createWalletClient,
|
|
20
|
+
custom,
|
|
21
|
+
getAddress,
|
|
22
|
+
numberToHex
|
|
23
|
+
} from "viem";
|
|
24
|
+
var _client, _provider;
|
|
25
|
+
var CoinbaseWalletConnector = class extends Connector {
|
|
26
|
+
constructor({ chains, options }) {
|
|
27
|
+
super({
|
|
28
|
+
chains,
|
|
29
|
+
options: {
|
|
30
|
+
reloadOnDisconnect: false,
|
|
31
|
+
...options
|
|
32
|
+
}
|
|
33
|
+
});
|
|
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
|
+
if (accounts.length === 0)
|
|
41
|
+
this.emit("disconnect");
|
|
42
|
+
else
|
|
43
|
+
this.emit("change", { account: getAddress(accounts[0]) });
|
|
44
|
+
});
|
|
45
|
+
__publicField(this, "onChainChanged", (chainId) => {
|
|
46
|
+
const id = normalizeChainId(chainId);
|
|
47
|
+
const unsupported = this.isChainUnsupported(id);
|
|
48
|
+
this.emit("change", { chain: { id, unsupported } });
|
|
49
|
+
});
|
|
50
|
+
__publicField(this, "onDisconnect", () => {
|
|
51
|
+
this.emit("disconnect");
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
async connect({ chainId } = {}) {
|
|
55
|
+
try {
|
|
56
|
+
const provider = await this.getProvider();
|
|
57
|
+
provider.on("accountsChanged", this.onAccountsChanged);
|
|
58
|
+
provider.on("chainChanged", this.onChainChanged);
|
|
59
|
+
provider.on("disconnect", this.onDisconnect);
|
|
60
|
+
this.emit("message", { type: "connecting" });
|
|
61
|
+
const accounts = await provider.enable();
|
|
62
|
+
const account = getAddress(accounts[0]);
|
|
63
|
+
let id = await this.getChainId();
|
|
64
|
+
let unsupported = this.isChainUnsupported(id);
|
|
65
|
+
if (chainId && id !== chainId) {
|
|
66
|
+
const chain = await this.switchChain(chainId);
|
|
67
|
+
id = chain.id;
|
|
68
|
+
unsupported = this.isChainUnsupported(id);
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
account,
|
|
72
|
+
chain: { id, unsupported }
|
|
73
|
+
};
|
|
74
|
+
} catch (error) {
|
|
75
|
+
if (/(user closed modal|accounts received is empty)/i.test(
|
|
76
|
+
error.message
|
|
77
|
+
))
|
|
78
|
+
throw new UserRejectedRequestError(error);
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
async disconnect() {
|
|
83
|
+
if (!__privateGet(this, _provider))
|
|
84
|
+
return;
|
|
85
|
+
const provider = await this.getProvider();
|
|
86
|
+
provider.removeListener("accountsChanged", this.onAccountsChanged);
|
|
87
|
+
provider.removeListener("chainChanged", this.onChainChanged);
|
|
88
|
+
provider.removeListener("disconnect", this.onDisconnect);
|
|
89
|
+
provider.disconnect();
|
|
90
|
+
provider.close();
|
|
91
|
+
}
|
|
92
|
+
async getAccount() {
|
|
93
|
+
const provider = await this.getProvider();
|
|
94
|
+
const accounts = await provider.request({
|
|
95
|
+
method: "eth_accounts"
|
|
96
|
+
});
|
|
97
|
+
return getAddress(accounts[0]);
|
|
98
|
+
}
|
|
99
|
+
async getChainId() {
|
|
100
|
+
const provider = await this.getProvider();
|
|
101
|
+
const chainId = normalizeChainId(provider.chainId);
|
|
102
|
+
return chainId;
|
|
103
|
+
}
|
|
104
|
+
async getProvider() {
|
|
105
|
+
if (!__privateGet(this, _provider)) {
|
|
106
|
+
let CoinbaseWalletSDK = (await import("@coinbase/wallet-sdk")).default;
|
|
107
|
+
if (typeof CoinbaseWalletSDK !== "function" && typeof CoinbaseWalletSDK.default === "function")
|
|
108
|
+
CoinbaseWalletSDK = CoinbaseWalletSDK.default;
|
|
109
|
+
__privateSet(this, _client, new CoinbaseWalletSDK(this.options));
|
|
110
|
+
class WalletProvider {
|
|
111
|
+
}
|
|
112
|
+
class Client {
|
|
113
|
+
}
|
|
114
|
+
const walletExtensionChainId = __privateGet(this, _client).walletExtension?.getChainId();
|
|
115
|
+
const chain = this.chains.find(
|
|
116
|
+
(chain2) => this.options.chainId ? chain2.id === this.options.chainId : chain2.id === walletExtensionChainId
|
|
117
|
+
) || this.chains[0];
|
|
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
|
+
}
|
|
122
|
+
return __privateGet(this, _provider);
|
|
123
|
+
}
|
|
124
|
+
async getWalletClient({ chainId } = {}) {
|
|
125
|
+
const [provider, account] = await Promise.all([
|
|
126
|
+
this.getProvider(),
|
|
127
|
+
this.getAccount()
|
|
128
|
+
]);
|
|
129
|
+
const chain = this.chains.find((x) => x.id === chainId) || this.chains[0];
|
|
130
|
+
if (!provider)
|
|
131
|
+
throw new Error("provider is required.");
|
|
132
|
+
return createWalletClient({
|
|
133
|
+
account,
|
|
134
|
+
chain,
|
|
135
|
+
transport: custom(provider)
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
async isAuthorized() {
|
|
139
|
+
try {
|
|
140
|
+
const account = await this.getAccount();
|
|
141
|
+
return !!account;
|
|
142
|
+
} catch {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
async switchChain(chainId) {
|
|
147
|
+
const provider = await this.getProvider();
|
|
148
|
+
const id = numberToHex(chainId);
|
|
149
|
+
try {
|
|
150
|
+
await provider.request({
|
|
151
|
+
method: "wallet_switchEthereumChain",
|
|
152
|
+
params: [{ chainId: id }]
|
|
153
|
+
});
|
|
154
|
+
return this.chains.find((x) => x.id === chainId) ?? {
|
|
155
|
+
id: chainId,
|
|
156
|
+
name: `Chain ${id}`,
|
|
157
|
+
network: `${id}`,
|
|
158
|
+
nativeCurrency: { name: "Ether", decimals: 18, symbol: "ETH" },
|
|
159
|
+
rpcUrls: { default: { http: [""] }, public: { http: [""] } }
|
|
160
|
+
};
|
|
161
|
+
} catch (error) {
|
|
162
|
+
const chain = this.chains.find((x) => x.id === chainId);
|
|
163
|
+
if (!chain)
|
|
164
|
+
throw new ChainNotConfiguredForConnectorError({
|
|
165
|
+
chainId,
|
|
166
|
+
connectorId: this.id
|
|
167
|
+
});
|
|
168
|
+
if (error.code === 4902) {
|
|
169
|
+
try {
|
|
170
|
+
await provider.request({
|
|
171
|
+
method: "wallet_addEthereumChain",
|
|
172
|
+
params: [
|
|
173
|
+
{
|
|
174
|
+
chainId: id,
|
|
175
|
+
chainName: chain.name,
|
|
176
|
+
nativeCurrency: chain.nativeCurrency,
|
|
177
|
+
rpcUrls: [chain.rpcUrls.public?.http[0] ?? ""],
|
|
178
|
+
blockExplorerUrls: this.getBlockExplorerUrls(chain)
|
|
179
|
+
}
|
|
180
|
+
]
|
|
181
|
+
});
|
|
182
|
+
return chain;
|
|
183
|
+
} catch (error2) {
|
|
184
|
+
throw new UserRejectedRequestError(error2);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
throw new SwitchChainError(error);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
async watchAsset({
|
|
191
|
+
address,
|
|
192
|
+
decimals = 18,
|
|
193
|
+
image,
|
|
194
|
+
symbol
|
|
195
|
+
}) {
|
|
196
|
+
const provider = await this.getProvider();
|
|
197
|
+
return provider.request({
|
|
198
|
+
method: "wallet_watchAsset",
|
|
199
|
+
params: {
|
|
200
|
+
type: "ERC20",
|
|
201
|
+
options: {
|
|
202
|
+
address,
|
|
203
|
+
decimals,
|
|
204
|
+
image,
|
|
205
|
+
symbol
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
_client = new WeakMap();
|
|
212
|
+
_provider = new WeakMap();
|
|
213
|
+
export {
|
|
214
|
+
CoinbaseWalletConnector
|
|
215
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1,19 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { C as Connector, a as ConnectorData, b as ConnectorEvents, W as WindowProvider } from './base-a11da01a.js';
|
|
2
|
+
import '@wagmi/chains';
|
|
3
|
+
import 'abitype';
|
|
4
|
+
import 'eventemitter3';
|
|
5
|
+
import 'viem';
|
|
6
|
+
|
|
7
|
+
declare class ChainNotConfiguredForConnectorError extends Error {
|
|
8
|
+
name: string;
|
|
9
|
+
constructor({ chainId, connectorId, }: {
|
|
10
|
+
chainId: number;
|
|
11
|
+
connectorId?: string;
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
declare class ConnectorNotFoundError extends Error {
|
|
15
|
+
name: string;
|
|
16
|
+
message: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { ChainNotConfiguredForConnectorError, ConnectorNotFoundError };
|
package/dist/index.js
ADDED