@wagmi/core 0.8.2 → 0.8.3
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/connectors/injected/package.json +4 -0
- package/connectors/ledger/package.json +4 -0
- package/connectors/mock/package.json +1 -1
- package/connectors/package.json +4 -0
- package/dist/{chunk-63RNYADG.js → chunk-37HX2X4M.js} +13 -327
- package/dist/chunk-BVC4KGLQ.js +8 -0
- package/dist/chunk-EQOEZP46.js +6 -0
- package/dist/chunk-KFW652VN.js +7 -0
- package/dist/{chunk-J6DUE3KA.js → chunk-KX4UEHS5.js} +0 -0
- package/dist/connectors/coinbaseWallet.d.ts +1 -60
- package/dist/connectors/coinbaseWallet.js +2 -213
- package/dist/connectors/index.d.ts +2 -0
- package/dist/connectors/index.js +9 -0
- package/dist/connectors/injected.d.ts +1 -0
- package/dist/connectors/injected.js +7 -0
- package/dist/connectors/ledger.d.ts +1 -0
- package/dist/connectors/ledger.js +7 -0
- package/dist/connectors/metaMask.d.ts +1 -34
- package/dist/connectors/metaMask.js +2 -110
- package/dist/connectors/mock.d.ts +1 -0
- package/dist/connectors/mock.js +9 -0
- package/dist/connectors/walletConnect.d.ts +1 -45
- package/dist/connectors/walletConnect.js +2 -167
- package/dist/index.d.ts +3 -4
- package/dist/index.js +8 -4
- package/dist/internal/index.js +2 -2
- package/dist/internal/test.js +5 -3
- package/package.json +14 -5
- package/dist/base-a82112a9.d.ts +0 -65
- package/dist/chunk-6E4ZWCDO.js +0 -203
- package/dist/connectors/mock/index.d.ts +0 -82
- package/dist/connectors/mock/index.js +0 -11
- package/dist/injected-27788d9f.d.ts +0 -71
|
@@ -1,218 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
AddChainError,
|
|
3
|
-
ChainNotConfiguredError,
|
|
4
|
-
Connector,
|
|
5
|
-
SwitchChainError,
|
|
6
|
-
UserRejectedRequestError,
|
|
7
|
-
normalizeChainId
|
|
8
|
-
} from "../chunk-63RNYADG.js";
|
|
9
|
-
import "../chunk-6KG5TOAU.js";
|
|
10
|
-
import {
|
|
11
|
-
__privateAdd,
|
|
12
|
-
__privateGet,
|
|
13
|
-
__privateMethod,
|
|
14
|
-
__privateSet
|
|
15
|
-
} from "../chunk-MQXBDTVK.js";
|
|
1
|
+
import "../chunk-MQXBDTVK.js";
|
|
16
2
|
|
|
17
3
|
// src/connectors/coinbaseWallet.ts
|
|
18
|
-
import {
|
|
19
|
-
import { getAddress, hexValue } from "ethers/lib/utils.js";
|
|
20
|
-
var _client, _provider, _isUserRejectedRequestError, isUserRejectedRequestError_fn;
|
|
21
|
-
var CoinbaseWalletConnector = class extends Connector {
|
|
22
|
-
constructor({ chains, options }) {
|
|
23
|
-
super({
|
|
24
|
-
chains,
|
|
25
|
-
options: {
|
|
26
|
-
reloadOnDisconnect: false,
|
|
27
|
-
...options
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
__privateAdd(this, _isUserRejectedRequestError);
|
|
31
|
-
this.id = "coinbaseWallet";
|
|
32
|
-
this.name = "Coinbase Wallet";
|
|
33
|
-
this.ready = true;
|
|
34
|
-
__privateAdd(this, _client, void 0);
|
|
35
|
-
__privateAdd(this, _provider, void 0);
|
|
36
|
-
this.onAccountsChanged = (accounts) => {
|
|
37
|
-
if (accounts.length === 0)
|
|
38
|
-
this.emit("disconnect");
|
|
39
|
-
else
|
|
40
|
-
this.emit("change", { account: getAddress(accounts[0]) });
|
|
41
|
-
};
|
|
42
|
-
this.onChainChanged = (chainId) => {
|
|
43
|
-
const id = normalizeChainId(chainId);
|
|
44
|
-
const unsupported = this.isChainUnsupported(id);
|
|
45
|
-
this.emit("change", { chain: { id, unsupported } });
|
|
46
|
-
};
|
|
47
|
-
this.onDisconnect = () => {
|
|
48
|
-
this.emit("disconnect");
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
async connect({ chainId } = {}) {
|
|
52
|
-
try {
|
|
53
|
-
const provider = await this.getProvider();
|
|
54
|
-
provider.on("accountsChanged", this.onAccountsChanged);
|
|
55
|
-
provider.on("chainChanged", this.onChainChanged);
|
|
56
|
-
provider.on("disconnect", this.onDisconnect);
|
|
57
|
-
this.emit("message", { type: "connecting" });
|
|
58
|
-
const accounts = await provider.enable();
|
|
59
|
-
const account = getAddress(accounts[0]);
|
|
60
|
-
let id = await this.getChainId();
|
|
61
|
-
let unsupported = this.isChainUnsupported(id);
|
|
62
|
-
if (chainId && id !== chainId) {
|
|
63
|
-
const chain = await this.switchChain(chainId);
|
|
64
|
-
id = chain.id;
|
|
65
|
-
unsupported = this.isChainUnsupported(id);
|
|
66
|
-
}
|
|
67
|
-
return {
|
|
68
|
-
account,
|
|
69
|
-
chain: { id, unsupported },
|
|
70
|
-
provider: new providers.Web3Provider(
|
|
71
|
-
provider
|
|
72
|
-
)
|
|
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 getSigner({ chainId } = {}) {
|
|
125
|
-
const [provider, account] = await Promise.all([
|
|
126
|
-
this.getProvider(),
|
|
127
|
-
this.getAccount()
|
|
128
|
-
]);
|
|
129
|
-
return new providers.Web3Provider(
|
|
130
|
-
provider,
|
|
131
|
-
chainId
|
|
132
|
-
).getSigner(account);
|
|
133
|
-
}
|
|
134
|
-
async isAuthorized() {
|
|
135
|
-
try {
|
|
136
|
-
const account = await this.getAccount();
|
|
137
|
-
return !!account;
|
|
138
|
-
} catch {
|
|
139
|
-
return false;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
async switchChain(chainId) {
|
|
143
|
-
const provider = await this.getProvider();
|
|
144
|
-
const id = hexValue(chainId);
|
|
145
|
-
try {
|
|
146
|
-
await provider.request({
|
|
147
|
-
method: "wallet_switchEthereumChain",
|
|
148
|
-
params: [{ chainId: id }]
|
|
149
|
-
});
|
|
150
|
-
return this.chains.find((x) => x.id === chainId) ?? {
|
|
151
|
-
id: chainId,
|
|
152
|
-
name: `Chain ${id}`,
|
|
153
|
-
network: `${id}`,
|
|
154
|
-
nativeCurrency: { name: "Ether", decimals: 18, symbol: "ETH" },
|
|
155
|
-
rpcUrls: { default: { http: [""] } }
|
|
156
|
-
};
|
|
157
|
-
} catch (error) {
|
|
158
|
-
const chain = this.chains.find((x) => x.id === chainId);
|
|
159
|
-
if (!chain)
|
|
160
|
-
throw new ChainNotConfiguredError({ chainId, connectorId: this.id });
|
|
161
|
-
if (error.code === 4902) {
|
|
162
|
-
try {
|
|
163
|
-
await provider.request({
|
|
164
|
-
method: "wallet_addEthereumChain",
|
|
165
|
-
params: [
|
|
166
|
-
{
|
|
167
|
-
chainId: id,
|
|
168
|
-
chainName: chain.name,
|
|
169
|
-
nativeCurrency: chain.nativeCurrency,
|
|
170
|
-
rpcUrls: [
|
|
171
|
-
chain.rpcUrls.public?.http[0] ?? chain.rpcUrls.default.http[0]
|
|
172
|
-
],
|
|
173
|
-
blockExplorerUrls: this.getBlockExplorerUrls(chain)
|
|
174
|
-
}
|
|
175
|
-
]
|
|
176
|
-
});
|
|
177
|
-
return chain;
|
|
178
|
-
} catch (addError) {
|
|
179
|
-
if (__privateMethod(this, _isUserRejectedRequestError, isUserRejectedRequestError_fn).call(this, addError))
|
|
180
|
-
throw new UserRejectedRequestError(addError);
|
|
181
|
-
throw new AddChainError();
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
if (__privateMethod(this, _isUserRejectedRequestError, isUserRejectedRequestError_fn).call(this, error))
|
|
185
|
-
throw new UserRejectedRequestError(error);
|
|
186
|
-
throw new SwitchChainError(error);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
async watchAsset({
|
|
190
|
-
address,
|
|
191
|
-
decimals = 18,
|
|
192
|
-
image,
|
|
193
|
-
symbol
|
|
194
|
-
}) {
|
|
195
|
-
const provider = await this.getProvider();
|
|
196
|
-
return provider.request({
|
|
197
|
-
method: "wallet_watchAsset",
|
|
198
|
-
params: {
|
|
199
|
-
type: "ERC20",
|
|
200
|
-
options: {
|
|
201
|
-
address,
|
|
202
|
-
decimals,
|
|
203
|
-
image,
|
|
204
|
-
symbol
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
};
|
|
210
|
-
_client = new WeakMap();
|
|
211
|
-
_provider = new WeakMap();
|
|
212
|
-
_isUserRejectedRequestError = new WeakSet();
|
|
213
|
-
isUserRejectedRequestError_fn = function(error) {
|
|
214
|
-
return /(user rejected)/i.test(error.message);
|
|
215
|
-
};
|
|
4
|
+
import { CoinbaseWalletConnector } from "@wagmi/connectors/coinbaseWallet";
|
|
216
5
|
export {
|
|
217
6
|
CoinbaseWalletConnector
|
|
218
7
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { InjectedConnector, InjectedConnectorOptions } from '@wagmi/connectors/injected';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { LedgerConnector } from '@wagmi/connectors/ledger';
|
|
@@ -1,34 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { E as Ethereum } from '../index-37d6352e.js';
|
|
3
|
-
import { a as InjectedConnectorOptions, I as InjectedConnector } from '../injected-27788d9f.js';
|
|
4
|
-
import 'abitype';
|
|
5
|
-
import 'ethers';
|
|
6
|
-
import '../base-a82112a9.js';
|
|
7
|
-
import 'eventemitter3';
|
|
8
|
-
|
|
9
|
-
type MetaMaskConnectorOptions = Pick<InjectedConnectorOptions, 'shimChainChangedDisconnect' | 'shimDisconnect'> & {
|
|
10
|
-
/**
|
|
11
|
-
* While "disconnected" with `shimDisconnect`, allows user to select a different MetaMask account (than the currently connected account) when trying to connect.
|
|
12
|
-
*/
|
|
13
|
-
UNSTABLE_shimOnConnectSelectAccount?: boolean;
|
|
14
|
-
};
|
|
15
|
-
declare class MetaMaskConnector extends InjectedConnector {
|
|
16
|
-
#private;
|
|
17
|
-
readonly id = "metaMask";
|
|
18
|
-
constructor({ chains, options: options_, }?: {
|
|
19
|
-
chains?: Chain[];
|
|
20
|
-
options?: MetaMaskConnectorOptions;
|
|
21
|
-
});
|
|
22
|
-
connect({ chainId }?: {
|
|
23
|
-
chainId?: number;
|
|
24
|
-
}): Promise<{
|
|
25
|
-
account: `0x${string}`;
|
|
26
|
-
chain: {
|
|
27
|
-
id: number;
|
|
28
|
-
unsupported: boolean;
|
|
29
|
-
};
|
|
30
|
-
provider: Ethereum;
|
|
31
|
-
}>;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export { MetaMaskConnector, MetaMaskConnectorOptions };
|
|
1
|
+
export { MetaMaskConnector, MetaMaskConnectorOptions } from '@wagmi/connectors/metaMask';
|
|
@@ -1,115 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
ConnectorNotFoundError,
|
|
3
|
-
InjectedConnector,
|
|
4
|
-
ResourceUnavailableError,
|
|
5
|
-
UserRejectedRequestError,
|
|
6
|
-
getClient
|
|
7
|
-
} from "../chunk-63RNYADG.js";
|
|
8
|
-
import "../chunk-6KG5TOAU.js";
|
|
9
|
-
import {
|
|
10
|
-
__privateAdd,
|
|
11
|
-
__privateGet,
|
|
12
|
-
__privateSet
|
|
13
|
-
} from "../chunk-MQXBDTVK.js";
|
|
1
|
+
import "../chunk-MQXBDTVK.js";
|
|
14
2
|
|
|
15
3
|
// src/connectors/metaMask.ts
|
|
16
|
-
import {
|
|
17
|
-
var _UNSTABLE_shimOnConnectSelectAccount;
|
|
18
|
-
var MetaMaskConnector = class extends InjectedConnector {
|
|
19
|
-
constructor({
|
|
20
|
-
chains,
|
|
21
|
-
options: options_
|
|
22
|
-
} = {}) {
|
|
23
|
-
const options = {
|
|
24
|
-
name: "MetaMask",
|
|
25
|
-
shimDisconnect: true,
|
|
26
|
-
shimChainChangedDisconnect: true,
|
|
27
|
-
getProvider() {
|
|
28
|
-
function getReady(ethereum) {
|
|
29
|
-
const isMetaMask = !!ethereum?.isMetaMask;
|
|
30
|
-
if (!isMetaMask)
|
|
31
|
-
return;
|
|
32
|
-
if (ethereum.isBraveWallet && !ethereum._events && !ethereum._state)
|
|
33
|
-
return;
|
|
34
|
-
if (ethereum.isAvalanche)
|
|
35
|
-
return;
|
|
36
|
-
if (ethereum.isKuCoinWallet)
|
|
37
|
-
return;
|
|
38
|
-
if (ethereum.isPhantom)
|
|
39
|
-
return;
|
|
40
|
-
if (ethereum.isPortal)
|
|
41
|
-
return;
|
|
42
|
-
if (ethereum.isTokenPocket)
|
|
43
|
-
return;
|
|
44
|
-
if (ethereum.isTokenary)
|
|
45
|
-
return;
|
|
46
|
-
return ethereum;
|
|
47
|
-
}
|
|
48
|
-
if (typeof window === "undefined")
|
|
49
|
-
return;
|
|
50
|
-
if (window.ethereum?.providers)
|
|
51
|
-
return window.ethereum.providers.find(getReady);
|
|
52
|
-
return getReady(window.ethereum);
|
|
53
|
-
},
|
|
54
|
-
...options_
|
|
55
|
-
};
|
|
56
|
-
super({ chains, options });
|
|
57
|
-
this.id = "metaMask";
|
|
58
|
-
__privateAdd(this, _UNSTABLE_shimOnConnectSelectAccount, void 0);
|
|
59
|
-
__privateSet(this, _UNSTABLE_shimOnConnectSelectAccount, options.UNSTABLE_shimOnConnectSelectAccount);
|
|
60
|
-
}
|
|
61
|
-
async connect({ chainId } = {}) {
|
|
62
|
-
try {
|
|
63
|
-
const provider = await this.getProvider();
|
|
64
|
-
if (!provider)
|
|
65
|
-
throw new ConnectorNotFoundError();
|
|
66
|
-
if (provider.on) {
|
|
67
|
-
provider.on("accountsChanged", this.onAccountsChanged);
|
|
68
|
-
provider.on("chainChanged", this.onChainChanged);
|
|
69
|
-
provider.on("disconnect", this.onDisconnect);
|
|
70
|
-
}
|
|
71
|
-
this.emit("message", { type: "connecting" });
|
|
72
|
-
let account = null;
|
|
73
|
-
if (__privateGet(this, _UNSTABLE_shimOnConnectSelectAccount) && this.options?.shimDisconnect && !getClient().storage?.getItem(this.shimDisconnectKey)) {
|
|
74
|
-
account = await this.getAccount().catch(() => null);
|
|
75
|
-
const isConnected = !!account;
|
|
76
|
-
if (isConnected)
|
|
77
|
-
try {
|
|
78
|
-
await provider.request({
|
|
79
|
-
method: "wallet_requestPermissions",
|
|
80
|
-
params: [{ eth_accounts: {} }]
|
|
81
|
-
});
|
|
82
|
-
} catch (error) {
|
|
83
|
-
if (this.isUserRejectedRequestError(error))
|
|
84
|
-
throw new UserRejectedRequestError(error);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
if (!account) {
|
|
88
|
-
const accounts = await provider.request({
|
|
89
|
-
method: "eth_requestAccounts"
|
|
90
|
-
});
|
|
91
|
-
account = getAddress(accounts[0]);
|
|
92
|
-
}
|
|
93
|
-
let id = await this.getChainId();
|
|
94
|
-
let unsupported = this.isChainUnsupported(id);
|
|
95
|
-
if (chainId && id !== chainId) {
|
|
96
|
-
const chain = await this.switchChain(chainId);
|
|
97
|
-
id = chain.id;
|
|
98
|
-
unsupported = this.isChainUnsupported(id);
|
|
99
|
-
}
|
|
100
|
-
if (this.options?.shimDisconnect)
|
|
101
|
-
getClient().storage?.setItem(this.shimDisconnectKey, true);
|
|
102
|
-
return { account, chain: { id, unsupported }, provider };
|
|
103
|
-
} catch (error) {
|
|
104
|
-
if (this.isUserRejectedRequestError(error))
|
|
105
|
-
throw new UserRejectedRequestError(error);
|
|
106
|
-
if (error.code === -32002)
|
|
107
|
-
throw new ResourceUnavailableError(error);
|
|
108
|
-
throw error;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
_UNSTABLE_shimOnConnectSelectAccount = new WeakMap();
|
|
4
|
+
import { MetaMaskConnector } from "@wagmi/connectors/metaMask";
|
|
113
5
|
export {
|
|
114
6
|
MetaMaskConnector
|
|
115
7
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { MockConnector, MockProvider, MockProviderOptions } from '@wagmi/connectors/mock';
|
|
@@ -1,45 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { providers } from 'ethers';
|
|
3
|
-
import { Chain } from '@wagmi/chains';
|
|
4
|
-
import { C as Connector } from '../base-a82112a9.js';
|
|
5
|
-
import 'abitype';
|
|
6
|
-
import 'eventemitter3';
|
|
7
|
-
|
|
8
|
-
type WalletConnectOptions = ConstructorParameters<typeof WalletConnectProvider>[0];
|
|
9
|
-
type WalletConnectSigner = providers.JsonRpcSigner;
|
|
10
|
-
declare class WalletConnectConnector extends Connector<WalletConnectProvider, WalletConnectOptions, WalletConnectSigner> {
|
|
11
|
-
#private;
|
|
12
|
-
readonly id = "walletConnect";
|
|
13
|
-
readonly name = "WalletConnect";
|
|
14
|
-
readonly ready = true;
|
|
15
|
-
constructor(config: {
|
|
16
|
-
chains?: Chain[];
|
|
17
|
-
options: WalletConnectOptions;
|
|
18
|
-
});
|
|
19
|
-
connect({ chainId }?: {
|
|
20
|
-
chainId?: number;
|
|
21
|
-
}): Promise<{
|
|
22
|
-
account: `0x${string}`;
|
|
23
|
-
chain: {
|
|
24
|
-
id: number;
|
|
25
|
-
unsupported: boolean;
|
|
26
|
-
};
|
|
27
|
-
provider: providers.Web3Provider;
|
|
28
|
-
}>;
|
|
29
|
-
disconnect(): Promise<void>;
|
|
30
|
-
getAccount(): Promise<`0x${string}`>;
|
|
31
|
-
getChainId(): Promise<number>;
|
|
32
|
-
getProvider({ chainId, create, }?: {
|
|
33
|
-
chainId?: number;
|
|
34
|
-
create?: boolean;
|
|
35
|
-
}): Promise<WalletConnectProvider>;
|
|
36
|
-
getSigner({ chainId }?: {
|
|
37
|
-
chainId?: number;
|
|
38
|
-
}): Promise<providers.JsonRpcSigner>;
|
|
39
|
-
isAuthorized(): Promise<boolean>;
|
|
40
|
-
protected onAccountsChanged: (accounts: string[]) => void;
|
|
41
|
-
protected onChainChanged: (chainId: number | string) => void;
|
|
42
|
-
protected onDisconnect: () => void;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export { WalletConnectConnector };
|
|
1
|
+
export { WalletConnectConnector } from '@wagmi/connectors/walletConnect';
|
|
@@ -1,172 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
Connector,
|
|
3
|
-
SwitchChainError,
|
|
4
|
-
UserRejectedRequestError,
|
|
5
|
-
getClient,
|
|
6
|
-
normalizeChainId
|
|
7
|
-
} from "../chunk-63RNYADG.js";
|
|
8
|
-
import "../chunk-6KG5TOAU.js";
|
|
9
|
-
import {
|
|
10
|
-
__privateAdd,
|
|
11
|
-
__privateGet,
|
|
12
|
-
__privateMethod,
|
|
13
|
-
__privateSet
|
|
14
|
-
} from "../chunk-MQXBDTVK.js";
|
|
1
|
+
import "../chunk-MQXBDTVK.js";
|
|
15
2
|
|
|
16
3
|
// src/connectors/walletConnect.ts
|
|
17
|
-
import {
|
|
18
|
-
import { getAddress, hexValue } from "ethers/lib/utils.js";
|
|
19
|
-
var switchChainAllowedRegex = /(imtoken|metamask|rainbow|trust wallet)/i;
|
|
20
|
-
var _provider, _switchChain, switchChain_fn;
|
|
21
|
-
var WalletConnectConnector = class extends Connector {
|
|
22
|
-
constructor(config) {
|
|
23
|
-
super(config);
|
|
24
|
-
__privateAdd(this, _switchChain);
|
|
25
|
-
this.id = "walletConnect";
|
|
26
|
-
this.name = "WalletConnect";
|
|
27
|
-
this.ready = true;
|
|
28
|
-
__privateAdd(this, _provider, void 0);
|
|
29
|
-
this.onAccountsChanged = (accounts) => {
|
|
30
|
-
if (accounts.length === 0)
|
|
31
|
-
this.emit("disconnect");
|
|
32
|
-
else
|
|
33
|
-
this.emit("change", { account: getAddress(accounts[0]) });
|
|
34
|
-
};
|
|
35
|
-
this.onChainChanged = (chainId) => {
|
|
36
|
-
const id = normalizeChainId(chainId);
|
|
37
|
-
const unsupported = this.isChainUnsupported(id);
|
|
38
|
-
this.emit("change", { chain: { id, unsupported } });
|
|
39
|
-
};
|
|
40
|
-
this.onDisconnect = () => {
|
|
41
|
-
this.emit("disconnect");
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
async connect({ chainId } = {}) {
|
|
45
|
-
try {
|
|
46
|
-
let targetChainId = chainId;
|
|
47
|
-
if (!targetChainId) {
|
|
48
|
-
const lastUsedChainId = getClient().lastUsedChainId;
|
|
49
|
-
if (lastUsedChainId && !this.isChainUnsupported(lastUsedChainId))
|
|
50
|
-
targetChainId = lastUsedChainId;
|
|
51
|
-
}
|
|
52
|
-
const provider = await this.getProvider({
|
|
53
|
-
chainId: targetChainId,
|
|
54
|
-
create: true
|
|
55
|
-
});
|
|
56
|
-
provider.on("accountsChanged", this.onAccountsChanged);
|
|
57
|
-
provider.on("chainChanged", this.onChainChanged);
|
|
58
|
-
provider.on("disconnect", this.onDisconnect);
|
|
59
|
-
setTimeout(() => this.emit("message", { type: "connecting" }), 0);
|
|
60
|
-
const accounts = await provider.enable();
|
|
61
|
-
const account = getAddress(accounts[0]);
|
|
62
|
-
const id = await this.getChainId();
|
|
63
|
-
const unsupported = this.isChainUnsupported(id);
|
|
64
|
-
const walletName = provider.connector?.peerMeta?.name ?? "";
|
|
65
|
-
if (switchChainAllowedRegex.test(walletName))
|
|
66
|
-
this.switchChain = __privateMethod(this, _switchChain, switchChain_fn);
|
|
67
|
-
return {
|
|
68
|
-
account,
|
|
69
|
-
chain: { id, unsupported },
|
|
70
|
-
provider: new providers.Web3Provider(
|
|
71
|
-
provider
|
|
72
|
-
)
|
|
73
|
-
};
|
|
74
|
-
} catch (error) {
|
|
75
|
-
if (/user closed modal/i.test(error.message))
|
|
76
|
-
throw new UserRejectedRequestError(error);
|
|
77
|
-
throw error;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
async disconnect() {
|
|
81
|
-
const provider = await this.getProvider();
|
|
82
|
-
await provider.disconnect();
|
|
83
|
-
provider.removeListener("accountsChanged", this.onAccountsChanged);
|
|
84
|
-
provider.removeListener("chainChanged", this.onChainChanged);
|
|
85
|
-
provider.removeListener("disconnect", this.onDisconnect);
|
|
86
|
-
typeof localStorage !== "undefined" && localStorage.removeItem("walletconnect");
|
|
87
|
-
}
|
|
88
|
-
async getAccount() {
|
|
89
|
-
const provider = await this.getProvider();
|
|
90
|
-
const accounts = provider.accounts;
|
|
91
|
-
return getAddress(accounts[0]);
|
|
92
|
-
}
|
|
93
|
-
async getChainId() {
|
|
94
|
-
const provider = await this.getProvider();
|
|
95
|
-
const chainId = normalizeChainId(provider.chainId);
|
|
96
|
-
return chainId;
|
|
97
|
-
}
|
|
98
|
-
async getProvider({
|
|
99
|
-
chainId,
|
|
100
|
-
create
|
|
101
|
-
} = {}) {
|
|
102
|
-
if (!__privateGet(this, _provider) || chainId || create) {
|
|
103
|
-
const rpc = !this.options?.infuraId ? this.chains.reduce(
|
|
104
|
-
(rpc2, chain) => ({
|
|
105
|
-
...rpc2,
|
|
106
|
-
[chain.id]: chain.rpcUrls.default.http[0]
|
|
107
|
-
}),
|
|
108
|
-
{}
|
|
109
|
-
) : {};
|
|
110
|
-
const WalletConnectProvider = (await import("@walletconnect/ethereum-provider")).default;
|
|
111
|
-
__privateSet(this, _provider, new WalletConnectProvider({
|
|
112
|
-
...this.options,
|
|
113
|
-
chainId,
|
|
114
|
-
rpc: { ...rpc, ...this.options?.rpc }
|
|
115
|
-
}));
|
|
116
|
-
}
|
|
117
|
-
return __privateGet(this, _provider);
|
|
118
|
-
}
|
|
119
|
-
async getSigner({ chainId } = {}) {
|
|
120
|
-
const [provider, account] = await Promise.all([
|
|
121
|
-
this.getProvider({ chainId }),
|
|
122
|
-
this.getAccount()
|
|
123
|
-
]);
|
|
124
|
-
return new providers.Web3Provider(
|
|
125
|
-
provider,
|
|
126
|
-
chainId
|
|
127
|
-
).getSigner(account);
|
|
128
|
-
}
|
|
129
|
-
async isAuthorized() {
|
|
130
|
-
try {
|
|
131
|
-
const account = await this.getAccount();
|
|
132
|
-
return !!account;
|
|
133
|
-
} catch {
|
|
134
|
-
return false;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
_provider = new WeakMap();
|
|
139
|
-
_switchChain = new WeakSet();
|
|
140
|
-
switchChain_fn = async function(chainId) {
|
|
141
|
-
const provider = await this.getProvider();
|
|
142
|
-
const id = hexValue(chainId);
|
|
143
|
-
try {
|
|
144
|
-
await Promise.race([
|
|
145
|
-
provider.request({
|
|
146
|
-
method: "wallet_switchEthereumChain",
|
|
147
|
-
params: [{ chainId: id }]
|
|
148
|
-
}),
|
|
149
|
-
new Promise(
|
|
150
|
-
(res) => this.on("change", ({ chain }) => {
|
|
151
|
-
if (chain?.id === chainId)
|
|
152
|
-
res(chainId);
|
|
153
|
-
})
|
|
154
|
-
)
|
|
155
|
-
]);
|
|
156
|
-
return this.chains.find((x) => x.id === chainId) ?? {
|
|
157
|
-
id: chainId,
|
|
158
|
-
name: `Chain ${id}`,
|
|
159
|
-
network: `${id}`,
|
|
160
|
-
nativeCurrency: { name: "Ether", decimals: 18, symbol: "ETH" },
|
|
161
|
-
rpcUrls: { default: { http: [""] } }
|
|
162
|
-
};
|
|
163
|
-
} catch (error) {
|
|
164
|
-
const message = typeof error === "string" ? error : error?.message;
|
|
165
|
-
if (/user rejected request/i.test(message))
|
|
166
|
-
throw new UserRejectedRequestError(error);
|
|
167
|
-
throw new SwitchChainError(error);
|
|
168
|
-
}
|
|
169
|
-
};
|
|
4
|
+
import { WalletConnectConnector } from "@wagmi/connectors/walletConnect";
|
|
170
5
|
export {
|
|
171
6
|
WalletConnectConnector
|
|
172
7
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -2,18 +2,17 @@ import * as _wagmi_chains from '@wagmi/chains';
|
|
|
2
2
|
import { Chain } from '@wagmi/chains';
|
|
3
3
|
export { Chain, goerli, mainnet } from '@wagmi/chains';
|
|
4
4
|
import { Mutate, StoreApi } from 'zustand/vanilla';
|
|
5
|
+
import { Connector, ConnectorData } from '@wagmi/connectors';
|
|
6
|
+
export { Connector, ConnectorData, ConnectorEvents } from '@wagmi/connectors';
|
|
5
7
|
import { P as Provider, W as WebSocketProvider, U as Unit, S as Signer, H as Hash, C as ChainProviderFn, a as ProviderWithFallbackConfig } from './index-37d6352e.js';
|
|
6
8
|
export { C as ChainProviderFn, E as Ethereum, F as FallbackProviderConfig, H as Hash, P as Provider, a as ProviderWithFallbackConfig, S as Signer, U as Unit, W as WebSocketProvider, u as units } from './index-37d6352e.js';
|
|
7
|
-
import { C as Connector, a as ConnectorData } from './base-a82112a9.js';
|
|
8
|
-
export { C as Connector, a as ConnectorData, b as ConnectorEvents } from './base-a82112a9.js';
|
|
9
9
|
import { Address, ResolvedConfig, TypedDataDomain, Narrow, TypedData, TypedDataToPrimitiveTypes, Abi, ExtractAbiFunction, ExtractAbiEventNames, AbiParametersToPrimitiveTypes, ExtractAbiEvent, AbiFunction, AbiParameter, AbiParameterToPrimitiveType, AbiEvent, ExtractAbiFunctionNames } from 'abitype';
|
|
10
10
|
export { Address } from 'abitype';
|
|
11
11
|
import { PopulatedTransaction, Signer as Signer$1, providers, Contract as Contract$1, ethers, ContractInterface } from 'ethers';
|
|
12
12
|
import { O as Options$2, D as DefaultOptions, G as GetConfig$1, a as GetOverridesForAbiStateMutability, U as UnionToIntersection, C as CountOccurrences, A as AbiItemName, I as IsUnknown, E as Event, b as ContractsConfig, c as ContractsResult, d as GetReturnType, e as Or, f as IsNever, N as NotEqual } from './contracts-3880ee54.js';
|
|
13
13
|
import { TransactionResponse } from '@ethersproject/providers';
|
|
14
|
-
export {
|
|
14
|
+
export { InjectedConnector, InjectedConnectorOptions } from '@wagmi/connectors/injected';
|
|
15
15
|
import * as abitype_dist_abi_b1bae27f from 'abitype/dist/abi-b1bae27f';
|
|
16
|
-
import 'eventemitter3';
|
|
17
16
|
|
|
18
17
|
type BaseStorage = Pick<Storage, 'getItem' | 'setItem' | 'removeItem'>;
|
|
19
18
|
type ClientStorage = {
|