@wagmi/connectors 3.1.1 → 4.0.0-alpha.1
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/README.md +6 -39
- package/dist/esm/coinbaseWallet.js +141 -0
- package/dist/esm/coinbaseWallet.js.map +1 -0
- package/dist/esm/exports/index.js +7 -0
- package/dist/esm/exports/index.js.map +1 -0
- package/dist/esm/exports/index.test-d.js +4 -0
- package/dist/esm/exports/index.test-d.js.map +1 -0
- package/dist/esm/injected.js +372 -0
- package/dist/esm/injected.js.map +1 -0
- package/dist/esm/ledger.js +162 -0
- package/dist/esm/ledger.js.map +1 -0
- package/dist/esm/safe.js +88 -0
- package/dist/esm/safe.js.map +1 -0
- package/dist/esm/tsconfig.build.tsbuildinfo +1 -0
- package/dist/esm/version.js +2 -0
- package/dist/esm/version.js.map +1 -0
- package/dist/esm/walletConnect.js +280 -0
- package/dist/esm/walletConnect.js.map +1 -0
- package/dist/types/coinbaseWallet.d.ts +21 -0
- package/dist/types/coinbaseWallet.d.ts.map +1 -0
- package/dist/types/exports/index.d.ts +7 -0
- package/dist/types/exports/index.d.ts.map +1 -0
- package/dist/types/exports/index.test-d.d.ts +2 -0
- package/dist/types/exports/index.test-d.d.ts.map +1 -0
- package/dist/types/injected.d.ts +382 -0
- package/dist/types/injected.d.ts.map +1 -0
- package/dist/types/ledger.d.ts +18 -0
- package/dist/types/ledger.d.ts.map +1 -0
- package/dist/types/safe.d.ts +18 -0
- package/dist/types/safe.d.ts.map +1 -0
- package/dist/types/version.d.ts +2 -0
- package/dist/types/version.d.ts.map +1 -0
- package/dist/types/walletConnect.d.ts +63 -0
- package/dist/types/walletConnect.d.ts.map +1 -0
- package/package.json +43 -82
- package/src/coinbaseWallet.ts +207 -0
- package/src/exports/index.ts +17 -0
- package/src/injected.ts +535 -0
- package/src/ledger.ts +210 -0
- package/src/safe.ts +114 -0
- package/src/version.ts +1 -0
- package/src/walletConnect.ts +394 -0
- package/coinbaseWallet/package.json +0 -4
- package/dist/base-70e3a8a9.d.ts +0 -142
- package/dist/chunk-2UFLHRLT.js +0 -391
- package/dist/chunk-OQILYQDO.js +0 -15
- package/dist/chunk-UGBGYVBH.js +0 -22
- package/dist/chunk-W65LBPLT.js +0 -58
- package/dist/coinbaseWallet.d.ts +0 -62
- package/dist/coinbaseWallet.js +0 -216
- package/dist/index.d.ts +0 -20
- package/dist/index.js +0 -16
- package/dist/injected.d.ts +0 -64
- package/dist/injected.js +0 -9
- package/dist/ledger.d.ts +0 -69
- package/dist/ledger.js +0 -261
- package/dist/metaMask.d.ts +0 -33
- package/dist/metaMask.js +0 -144
- package/dist/mock/index.d.ts +0 -80
- package/dist/mock/index.js +0 -200
- package/dist/safe.d.ts +0 -53
- package/dist/safe.js +0 -129
- package/dist/walletConnect.d.ts +0 -109
- package/dist/walletConnect.js +0 -325
- package/dist/walletConnectLegacy.d.ts +0 -38
- package/dist/walletConnectLegacy.js +0 -179
- package/injected/package.json +0 -4
- package/ledger/package.json +0 -4
- package/metaMask/package.json +0 -4
- package/mock/package.json +0 -4
- package/safe/package.json +0 -4
- package/walletConnect/package.json +0 -4
- package/walletConnectLegacy/package.json +0 -4
package/dist/walletConnect.d.ts
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import WalletConnectProvider from '@walletconnect/ethereum-provider';
|
|
2
|
-
import { EthereumProviderOptions } from '@walletconnect/ethereum-provider/dist/types/EthereumProvider';
|
|
3
|
-
import { Chain } from 'viem/chains';
|
|
4
|
-
import { C as Connector, c as WalletClient } from './base-70e3a8a9.js';
|
|
5
|
-
import 'eventemitter3';
|
|
6
|
-
import 'viem';
|
|
7
|
-
|
|
8
|
-
type WalletConnectOptions = {
|
|
9
|
-
/**
|
|
10
|
-
* WalletConnect Cloud Project ID.
|
|
11
|
-
* @link https://cloud.walletconnect.com/sign-in.
|
|
12
|
-
*/
|
|
13
|
-
projectId: EthereumProviderOptions['projectId'];
|
|
14
|
-
/**
|
|
15
|
-
* If a new chain is added to a previously existing configured connector `chains`, this flag
|
|
16
|
-
* will determine if that chain should be considered as stale. A stale chain is a chain that
|
|
17
|
-
* WalletConnect has yet to establish a relationship with (ie. the user has not approved or
|
|
18
|
-
* rejected the chain).
|
|
19
|
-
*
|
|
20
|
-
* Preface: Whereas WalletConnect v1 supported dynamic chain switching, WalletConnect v2 requires
|
|
21
|
-
* the user to pre-approve a set of chains up-front. This comes with consequent UX nuances (see below) when
|
|
22
|
-
* a user tries to switch to a chain that they have not approved.
|
|
23
|
-
*
|
|
24
|
-
* This flag mainly affects the behavior when a wallet does not support dynamic chain authorization
|
|
25
|
-
* with WalletConnect v2.
|
|
26
|
-
*
|
|
27
|
-
* If `true` (default), the new chain will be treated as a stale chain. If the user
|
|
28
|
-
* has yet to establish a relationship (approved/rejected) with this chain in their WalletConnect
|
|
29
|
-
* session, the connector will disconnect upon the dapp auto-connecting, and the user will have to
|
|
30
|
-
* reconnect to the dapp (revalidate the chain) in order to approve the newly added chain.
|
|
31
|
-
* This is the default behavior to avoid an unexpected error upon switching chains which may
|
|
32
|
-
* be a confusing user experience (ie. the user will not know they have to reconnect
|
|
33
|
-
* unless the dapp handles these types of errors).
|
|
34
|
-
*
|
|
35
|
-
* If `false`, the new chain will be treated as a validated chain. This means that if the user
|
|
36
|
-
* has yet to establish a relationship with the chain in their WalletConnect session, wagmi will successfully
|
|
37
|
-
* auto-connect the user. This comes with the trade-off that the connector will throw an error
|
|
38
|
-
* when attempting to switch to the unapproved chain. This may be useful in cases where a dapp constantly
|
|
39
|
-
* modifies their configured chains, and they do not want to disconnect the user upon
|
|
40
|
-
* auto-connecting. If the user decides to switch to the unapproved chain, it is important that the
|
|
41
|
-
* dapp handles this error and prompts the user to reconnect to the dapp in order to approve
|
|
42
|
-
* the newly added chain.
|
|
43
|
-
*
|
|
44
|
-
* @default true
|
|
45
|
-
*/
|
|
46
|
-
isNewChainsStale?: boolean;
|
|
47
|
-
/**
|
|
48
|
-
* Metadata for your app.
|
|
49
|
-
* @link https://docs.walletconnect.com/2.0/javascript/providers/ethereum#initialization
|
|
50
|
-
*/
|
|
51
|
-
metadata?: EthereumProviderOptions['metadata'];
|
|
52
|
-
/**
|
|
53
|
-
* Whether or not to show the QR code modal.
|
|
54
|
-
* @default true
|
|
55
|
-
* @link https://docs.walletconnect.com/2.0/javascript/providers/ethereum#initialization
|
|
56
|
-
*/
|
|
57
|
-
showQrModal?: EthereumProviderOptions['showQrModal'];
|
|
58
|
-
/**
|
|
59
|
-
* Options of QR code modal.
|
|
60
|
-
* @link https://docs.walletconnect.com/2.0/web/walletConnectModal/modal/options
|
|
61
|
-
*/
|
|
62
|
-
qrModalOptions?: EthereumProviderOptions['qrModalOptions'];
|
|
63
|
-
/**
|
|
64
|
-
* Option to override default relay url.
|
|
65
|
-
* @link https://docs.walletconnect.com/2.0/web/providers/ethereum
|
|
66
|
-
*/
|
|
67
|
-
relayUrl?: string;
|
|
68
|
-
};
|
|
69
|
-
type ConnectConfig = {
|
|
70
|
-
/** Target chain to connect to. */
|
|
71
|
-
chainId?: number;
|
|
72
|
-
/** If provided, will attempt to connect to an existing pairing. */
|
|
73
|
-
pairingTopic?: string;
|
|
74
|
-
};
|
|
75
|
-
declare class WalletConnectConnector extends Connector<WalletConnectProvider, WalletConnectOptions> {
|
|
76
|
-
#private;
|
|
77
|
-
readonly id = "walletConnect";
|
|
78
|
-
readonly name = "WalletConnect";
|
|
79
|
-
readonly ready = true;
|
|
80
|
-
constructor(config: {
|
|
81
|
-
chains?: Chain[];
|
|
82
|
-
options: WalletConnectOptions;
|
|
83
|
-
});
|
|
84
|
-
connect({ chainId, pairingTopic }?: ConnectConfig): Promise<{
|
|
85
|
-
account: `0x${string}`;
|
|
86
|
-
chain: {
|
|
87
|
-
id: number;
|
|
88
|
-
unsupported: boolean;
|
|
89
|
-
};
|
|
90
|
-
}>;
|
|
91
|
-
disconnect(): Promise<void>;
|
|
92
|
-
getAccount(): Promise<`0x${string}`>;
|
|
93
|
-
getChainId(): Promise<number>;
|
|
94
|
-
getProvider({ chainId }?: {
|
|
95
|
-
chainId?: number;
|
|
96
|
-
}): Promise<WalletConnectProvider>;
|
|
97
|
-
getWalletClient({ chainId, }?: {
|
|
98
|
-
chainId?: number;
|
|
99
|
-
}): Promise<WalletClient>;
|
|
100
|
-
isAuthorized(): Promise<boolean>;
|
|
101
|
-
switchChain(chainId: number): Promise<Chain>;
|
|
102
|
-
protected onAccountsChanged: (accounts: string[]) => void;
|
|
103
|
-
protected onChainChanged: (chainId: number | string) => void;
|
|
104
|
-
protected onDisconnect: () => void;
|
|
105
|
-
protected onDisplayUri: (uri: string) => void;
|
|
106
|
-
protected onConnect: () => void;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export { WalletConnectConnector };
|
package/dist/walletConnect.js
DELETED
|
@@ -1,325 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Connector,
|
|
3
|
-
__privateAdd,
|
|
4
|
-
__privateGet,
|
|
5
|
-
__privateMethod,
|
|
6
|
-
__privateSet
|
|
7
|
-
} from "./chunk-W65LBPLT.js";
|
|
8
|
-
|
|
9
|
-
// src/walletConnect.ts
|
|
10
|
-
import { normalizeNamespaces } from "@walletconnect/utils";
|
|
11
|
-
import {
|
|
12
|
-
SwitchChainError,
|
|
13
|
-
UserRejectedRequestError,
|
|
14
|
-
createWalletClient,
|
|
15
|
-
custom,
|
|
16
|
-
getAddress,
|
|
17
|
-
numberToHex
|
|
18
|
-
} from "viem";
|
|
19
|
-
var NAMESPACE = "eip155";
|
|
20
|
-
var STORE_KEY = "store";
|
|
21
|
-
var REQUESTED_CHAINS_KEY = "requestedChains";
|
|
22
|
-
var ADD_ETH_CHAIN_METHOD = "wallet_addEthereumChain";
|
|
23
|
-
var _provider, _initProviderPromise, _createProvider, createProvider_fn, _initProvider, initProvider_fn, _isChainsStale, isChainsStale_fn, _setupListeners, setupListeners_fn, _removeListeners, removeListeners_fn, _setRequestedChainsIds, setRequestedChainsIds_fn, _getRequestedChainsIds, getRequestedChainsIds_fn, _getNamespaceChainsIds, getNamespaceChainsIds_fn, _getNamespaceMethods, getNamespaceMethods_fn;
|
|
24
|
-
var WalletConnectConnector = class extends Connector {
|
|
25
|
-
constructor(config) {
|
|
26
|
-
super({
|
|
27
|
-
...config,
|
|
28
|
-
options: { isNewChainsStale: true, ...config.options }
|
|
29
|
-
});
|
|
30
|
-
__privateAdd(this, _createProvider);
|
|
31
|
-
__privateAdd(this, _initProvider);
|
|
32
|
-
__privateAdd(this, _isChainsStale);
|
|
33
|
-
__privateAdd(this, _setupListeners);
|
|
34
|
-
__privateAdd(this, _removeListeners);
|
|
35
|
-
__privateAdd(this, _setRequestedChainsIds);
|
|
36
|
-
__privateAdd(this, _getRequestedChainsIds);
|
|
37
|
-
__privateAdd(this, _getNamespaceChainsIds);
|
|
38
|
-
__privateAdd(this, _getNamespaceMethods);
|
|
39
|
-
this.id = "walletConnect";
|
|
40
|
-
this.name = "WalletConnect";
|
|
41
|
-
this.ready = true;
|
|
42
|
-
__privateAdd(this, _provider, void 0);
|
|
43
|
-
__privateAdd(this, _initProviderPromise, void 0);
|
|
44
|
-
this.onAccountsChanged = (accounts) => {
|
|
45
|
-
if (accounts.length === 0)
|
|
46
|
-
this.emit("disconnect");
|
|
47
|
-
else
|
|
48
|
-
this.emit("change", { account: getAddress(accounts[0]) });
|
|
49
|
-
};
|
|
50
|
-
this.onChainChanged = (chainId) => {
|
|
51
|
-
const id = Number(chainId);
|
|
52
|
-
const unsupported = this.isChainUnsupported(id);
|
|
53
|
-
this.emit("change", { chain: { id, unsupported } });
|
|
54
|
-
};
|
|
55
|
-
this.onDisconnect = () => {
|
|
56
|
-
__privateMethod(this, _setRequestedChainsIds, setRequestedChainsIds_fn).call(this, []);
|
|
57
|
-
this.emit("disconnect");
|
|
58
|
-
};
|
|
59
|
-
this.onDisplayUri = (uri) => {
|
|
60
|
-
this.emit("message", { type: "display_uri", data: uri });
|
|
61
|
-
};
|
|
62
|
-
this.onConnect = () => {
|
|
63
|
-
this.emit("connect", {});
|
|
64
|
-
};
|
|
65
|
-
__privateMethod(this, _createProvider, createProvider_fn).call(this);
|
|
66
|
-
}
|
|
67
|
-
async connect({ chainId, pairingTopic } = {}) {
|
|
68
|
-
try {
|
|
69
|
-
let targetChainId = chainId;
|
|
70
|
-
if (!targetChainId) {
|
|
71
|
-
const store = this.storage?.getItem(STORE_KEY);
|
|
72
|
-
const lastUsedChainId = store?.state?.data?.chain?.id;
|
|
73
|
-
if (lastUsedChainId && !this.isChainUnsupported(lastUsedChainId))
|
|
74
|
-
targetChainId = lastUsedChainId;
|
|
75
|
-
else
|
|
76
|
-
targetChainId = this.chains[0]?.id;
|
|
77
|
-
}
|
|
78
|
-
if (!targetChainId)
|
|
79
|
-
throw new Error("No chains found on connector.");
|
|
80
|
-
const provider = await this.getProvider();
|
|
81
|
-
__privateMethod(this, _setupListeners, setupListeners_fn).call(this);
|
|
82
|
-
const isChainsStale = __privateMethod(this, _isChainsStale, isChainsStale_fn).call(this);
|
|
83
|
-
if (provider.session && isChainsStale)
|
|
84
|
-
await provider.disconnect();
|
|
85
|
-
if (!provider.session || isChainsStale) {
|
|
86
|
-
const optionalChains = this.chains.filter((chain) => chain.id !== targetChainId).map((optionalChain) => optionalChain.id);
|
|
87
|
-
this.emit("message", { type: "connecting" });
|
|
88
|
-
await provider.connect({
|
|
89
|
-
pairingTopic,
|
|
90
|
-
chains: [targetChainId],
|
|
91
|
-
optionalChains: optionalChains.length ? optionalChains : void 0
|
|
92
|
-
});
|
|
93
|
-
__privateMethod(this, _setRequestedChainsIds, setRequestedChainsIds_fn).call(this, this.chains.map(({ id: id2 }) => id2));
|
|
94
|
-
}
|
|
95
|
-
const accounts = await provider.enable();
|
|
96
|
-
const account = getAddress(accounts[0]);
|
|
97
|
-
const id = await this.getChainId();
|
|
98
|
-
const unsupported = this.isChainUnsupported(id);
|
|
99
|
-
return {
|
|
100
|
-
account,
|
|
101
|
-
chain: { id, unsupported }
|
|
102
|
-
};
|
|
103
|
-
} catch (error) {
|
|
104
|
-
if (/user rejected/i.test(error?.message)) {
|
|
105
|
-
throw new UserRejectedRequestError(error);
|
|
106
|
-
}
|
|
107
|
-
throw error;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
async disconnect() {
|
|
111
|
-
const provider = await this.getProvider();
|
|
112
|
-
try {
|
|
113
|
-
await provider.disconnect();
|
|
114
|
-
} catch (error) {
|
|
115
|
-
if (!/No matching key/i.test(error.message))
|
|
116
|
-
throw error;
|
|
117
|
-
} finally {
|
|
118
|
-
__privateMethod(this, _removeListeners, removeListeners_fn).call(this);
|
|
119
|
-
__privateMethod(this, _setRequestedChainsIds, setRequestedChainsIds_fn).call(this, []);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
async getAccount() {
|
|
123
|
-
const { accounts } = await this.getProvider();
|
|
124
|
-
return getAddress(accounts[0]);
|
|
125
|
-
}
|
|
126
|
-
async getChainId() {
|
|
127
|
-
const { chainId } = await this.getProvider();
|
|
128
|
-
return chainId;
|
|
129
|
-
}
|
|
130
|
-
async getProvider({ chainId } = {}) {
|
|
131
|
-
if (!__privateGet(this, _provider))
|
|
132
|
-
await __privateMethod(this, _createProvider, createProvider_fn).call(this);
|
|
133
|
-
if (chainId)
|
|
134
|
-
await this.switchChain(chainId);
|
|
135
|
-
return __privateGet(this, _provider);
|
|
136
|
-
}
|
|
137
|
-
async getWalletClient({
|
|
138
|
-
chainId
|
|
139
|
-
} = {}) {
|
|
140
|
-
const [provider, account] = await Promise.all([
|
|
141
|
-
this.getProvider({ chainId }),
|
|
142
|
-
this.getAccount()
|
|
143
|
-
]);
|
|
144
|
-
const chain = this.chains.find((x) => x.id === chainId);
|
|
145
|
-
if (!provider)
|
|
146
|
-
throw new Error("provider is required.");
|
|
147
|
-
return createWalletClient({
|
|
148
|
-
account,
|
|
149
|
-
chain,
|
|
150
|
-
transport: custom(provider)
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
async isAuthorized() {
|
|
154
|
-
try {
|
|
155
|
-
const [account, provider] = await Promise.all([
|
|
156
|
-
this.getAccount(),
|
|
157
|
-
this.getProvider()
|
|
158
|
-
]);
|
|
159
|
-
const isChainsStale = __privateMethod(this, _isChainsStale, isChainsStale_fn).call(this);
|
|
160
|
-
if (!account)
|
|
161
|
-
return false;
|
|
162
|
-
if (isChainsStale && provider.session) {
|
|
163
|
-
try {
|
|
164
|
-
await provider.disconnect();
|
|
165
|
-
} catch {
|
|
166
|
-
}
|
|
167
|
-
return false;
|
|
168
|
-
}
|
|
169
|
-
return true;
|
|
170
|
-
} catch {
|
|
171
|
-
return false;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
async switchChain(chainId) {
|
|
175
|
-
const chain = this.chains.find((chain2) => chain2.id === chainId);
|
|
176
|
-
if (!chain)
|
|
177
|
-
throw new SwitchChainError(new Error("chain not found on connector."));
|
|
178
|
-
try {
|
|
179
|
-
const provider = await this.getProvider();
|
|
180
|
-
const namespaceChains = __privateMethod(this, _getNamespaceChainsIds, getNamespaceChainsIds_fn).call(this);
|
|
181
|
-
const namespaceMethods = __privateMethod(this, _getNamespaceMethods, getNamespaceMethods_fn).call(this);
|
|
182
|
-
const isChainApproved = namespaceChains.includes(chainId);
|
|
183
|
-
if (!isChainApproved && namespaceMethods.includes(ADD_ETH_CHAIN_METHOD)) {
|
|
184
|
-
await provider.request({
|
|
185
|
-
method: ADD_ETH_CHAIN_METHOD,
|
|
186
|
-
params: [
|
|
187
|
-
{
|
|
188
|
-
chainId: numberToHex(chain.id),
|
|
189
|
-
blockExplorerUrls: [chain.blockExplorers?.default?.url],
|
|
190
|
-
chainName: chain.name,
|
|
191
|
-
nativeCurrency: chain.nativeCurrency,
|
|
192
|
-
rpcUrls: [...chain.rpcUrls.default.http]
|
|
193
|
-
}
|
|
194
|
-
]
|
|
195
|
-
});
|
|
196
|
-
const requestedChains = __privateMethod(this, _getRequestedChainsIds, getRequestedChainsIds_fn).call(this);
|
|
197
|
-
requestedChains.push(chainId);
|
|
198
|
-
__privateMethod(this, _setRequestedChainsIds, setRequestedChainsIds_fn).call(this, requestedChains);
|
|
199
|
-
}
|
|
200
|
-
await provider.request({
|
|
201
|
-
method: "wallet_switchEthereumChain",
|
|
202
|
-
params: [{ chainId: numberToHex(chainId) }]
|
|
203
|
-
});
|
|
204
|
-
return chain;
|
|
205
|
-
} catch (error) {
|
|
206
|
-
const message = typeof error === "string" ? error : error?.message;
|
|
207
|
-
if (/user rejected request/i.test(message)) {
|
|
208
|
-
throw new UserRejectedRequestError(error);
|
|
209
|
-
}
|
|
210
|
-
throw new SwitchChainError(error);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
};
|
|
214
|
-
_provider = new WeakMap();
|
|
215
|
-
_initProviderPromise = new WeakMap();
|
|
216
|
-
_createProvider = new WeakSet();
|
|
217
|
-
createProvider_fn = async function() {
|
|
218
|
-
if (!__privateGet(this, _initProviderPromise) && typeof window !== "undefined") {
|
|
219
|
-
__privateSet(this, _initProviderPromise, __privateMethod(this, _initProvider, initProvider_fn).call(this));
|
|
220
|
-
}
|
|
221
|
-
return __privateGet(this, _initProviderPromise);
|
|
222
|
-
};
|
|
223
|
-
_initProvider = new WeakSet();
|
|
224
|
-
initProvider_fn = async function() {
|
|
225
|
-
const { EthereumProvider, OPTIONAL_EVENTS, OPTIONAL_METHODS } = await import("@walletconnect/ethereum-provider");
|
|
226
|
-
const [defaultChain, ...optionalChains] = this.chains.map(({ id }) => id);
|
|
227
|
-
if (defaultChain) {
|
|
228
|
-
const {
|
|
229
|
-
projectId,
|
|
230
|
-
showQrModal = true,
|
|
231
|
-
qrModalOptions,
|
|
232
|
-
metadata,
|
|
233
|
-
relayUrl
|
|
234
|
-
} = this.options;
|
|
235
|
-
__privateSet(this, _provider, await EthereumProvider.init({
|
|
236
|
-
showQrModal,
|
|
237
|
-
qrModalOptions,
|
|
238
|
-
projectId,
|
|
239
|
-
optionalMethods: OPTIONAL_METHODS,
|
|
240
|
-
optionalEvents: OPTIONAL_EVENTS,
|
|
241
|
-
chains: [defaultChain],
|
|
242
|
-
optionalChains: optionalChains.length ? optionalChains : void 0,
|
|
243
|
-
rpcMap: Object.fromEntries(
|
|
244
|
-
this.chains.map((chain) => [
|
|
245
|
-
chain.id,
|
|
246
|
-
chain.rpcUrls.default.http[0]
|
|
247
|
-
])
|
|
248
|
-
),
|
|
249
|
-
metadata,
|
|
250
|
-
relayUrl
|
|
251
|
-
}));
|
|
252
|
-
}
|
|
253
|
-
};
|
|
254
|
-
_isChainsStale = new WeakSet();
|
|
255
|
-
isChainsStale_fn = function() {
|
|
256
|
-
const namespaceMethods = __privateMethod(this, _getNamespaceMethods, getNamespaceMethods_fn).call(this);
|
|
257
|
-
if (namespaceMethods.includes(ADD_ETH_CHAIN_METHOD))
|
|
258
|
-
return false;
|
|
259
|
-
if (!this.options.isNewChainsStale)
|
|
260
|
-
return false;
|
|
261
|
-
const requestedChains = __privateMethod(this, _getRequestedChainsIds, getRequestedChainsIds_fn).call(this);
|
|
262
|
-
const connectorChains = this.chains.map(({ id }) => id);
|
|
263
|
-
const namespaceChains = __privateMethod(this, _getNamespaceChainsIds, getNamespaceChainsIds_fn).call(this);
|
|
264
|
-
if (namespaceChains.length && !namespaceChains.some((id) => connectorChains.includes(id)))
|
|
265
|
-
return false;
|
|
266
|
-
return !connectorChains.every((id) => requestedChains.includes(id));
|
|
267
|
-
};
|
|
268
|
-
_setupListeners = new WeakSet();
|
|
269
|
-
setupListeners_fn = function() {
|
|
270
|
-
if (!__privateGet(this, _provider))
|
|
271
|
-
return;
|
|
272
|
-
__privateMethod(this, _removeListeners, removeListeners_fn).call(this);
|
|
273
|
-
__privateGet(this, _provider).on("accountsChanged", this.onAccountsChanged);
|
|
274
|
-
__privateGet(this, _provider).on("chainChanged", this.onChainChanged);
|
|
275
|
-
__privateGet(this, _provider).on("disconnect", this.onDisconnect);
|
|
276
|
-
__privateGet(this, _provider).on("session_delete", this.onDisconnect);
|
|
277
|
-
__privateGet(this, _provider).on("display_uri", this.onDisplayUri);
|
|
278
|
-
__privateGet(this, _provider).on("connect", this.onConnect);
|
|
279
|
-
};
|
|
280
|
-
_removeListeners = new WeakSet();
|
|
281
|
-
removeListeners_fn = function() {
|
|
282
|
-
if (!__privateGet(this, _provider))
|
|
283
|
-
return;
|
|
284
|
-
__privateGet(this, _provider).removeListener("accountsChanged", this.onAccountsChanged);
|
|
285
|
-
__privateGet(this, _provider).removeListener("chainChanged", this.onChainChanged);
|
|
286
|
-
__privateGet(this, _provider).removeListener("disconnect", this.onDisconnect);
|
|
287
|
-
__privateGet(this, _provider).removeListener("session_delete", this.onDisconnect);
|
|
288
|
-
__privateGet(this, _provider).removeListener("display_uri", this.onDisplayUri);
|
|
289
|
-
__privateGet(this, _provider).removeListener("connect", this.onConnect);
|
|
290
|
-
};
|
|
291
|
-
_setRequestedChainsIds = new WeakSet();
|
|
292
|
-
setRequestedChainsIds_fn = function(chains) {
|
|
293
|
-
this.storage?.setItem(REQUESTED_CHAINS_KEY, chains);
|
|
294
|
-
};
|
|
295
|
-
_getRequestedChainsIds = new WeakSet();
|
|
296
|
-
getRequestedChainsIds_fn = function() {
|
|
297
|
-
return this.storage?.getItem(REQUESTED_CHAINS_KEY) ?? [];
|
|
298
|
-
};
|
|
299
|
-
_getNamespaceChainsIds = new WeakSet();
|
|
300
|
-
getNamespaceChainsIds_fn = function() {
|
|
301
|
-
if (!__privateGet(this, _provider))
|
|
302
|
-
return [];
|
|
303
|
-
const namespaces = __privateGet(this, _provider).session?.namespaces;
|
|
304
|
-
if (!namespaces)
|
|
305
|
-
return [];
|
|
306
|
-
const normalizedNamespaces = normalizeNamespaces(namespaces);
|
|
307
|
-
const chainIds = normalizedNamespaces[NAMESPACE]?.chains?.map(
|
|
308
|
-
(chain) => parseInt(chain.split(":")[1] || "")
|
|
309
|
-
);
|
|
310
|
-
return chainIds ?? [];
|
|
311
|
-
};
|
|
312
|
-
_getNamespaceMethods = new WeakSet();
|
|
313
|
-
getNamespaceMethods_fn = function() {
|
|
314
|
-
if (!__privateGet(this, _provider))
|
|
315
|
-
return [];
|
|
316
|
-
const namespaces = __privateGet(this, _provider).session?.namespaces;
|
|
317
|
-
if (!namespaces)
|
|
318
|
-
return [];
|
|
319
|
-
const normalizedNamespaces = normalizeNamespaces(namespaces);
|
|
320
|
-
const methods = normalizedNamespaces[NAMESPACE]?.methods;
|
|
321
|
-
return methods ?? [];
|
|
322
|
-
};
|
|
323
|
-
export {
|
|
324
|
-
WalletConnectConnector
|
|
325
|
-
};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import WalletConnectProvider from '@walletconnect/legacy-provider';
|
|
2
|
-
import { C as Connector, c as WalletClient } from './base-70e3a8a9.js';
|
|
3
|
-
import 'eventemitter3';
|
|
4
|
-
import 'viem';
|
|
5
|
-
import 'viem/chains';
|
|
6
|
-
|
|
7
|
-
type WalletConnectOptions = ConstructorParameters<typeof WalletConnectProvider>[0];
|
|
8
|
-
declare class WalletConnectLegacyConnector extends Connector<WalletConnectProvider, WalletConnectOptions> {
|
|
9
|
-
#private;
|
|
10
|
-
readonly id = "walletConnectLegacy";
|
|
11
|
-
readonly name = "WalletConnectLegacy";
|
|
12
|
-
readonly ready = true;
|
|
13
|
-
connect({ chainId }?: {
|
|
14
|
-
chainId?: number;
|
|
15
|
-
}): Promise<{
|
|
16
|
-
account: `0x${string}`;
|
|
17
|
-
chain: {
|
|
18
|
-
id: number;
|
|
19
|
-
unsupported: boolean;
|
|
20
|
-
};
|
|
21
|
-
}>;
|
|
22
|
-
disconnect(): Promise<void>;
|
|
23
|
-
getAccount(): Promise<`0x${string}`>;
|
|
24
|
-
getChainId(): Promise<number>;
|
|
25
|
-
getProvider({ chainId, create, }?: {
|
|
26
|
-
chainId?: number;
|
|
27
|
-
create?: boolean;
|
|
28
|
-
}): Promise<WalletConnectProvider>;
|
|
29
|
-
getWalletClient({ chainId, }?: {
|
|
30
|
-
chainId?: number;
|
|
31
|
-
}): Promise<WalletClient>;
|
|
32
|
-
isAuthorized(): Promise<boolean>;
|
|
33
|
-
protected onAccountsChanged: (accounts: string[]) => void;
|
|
34
|
-
protected onChainChanged: (chainId: number | string) => void;
|
|
35
|
-
protected onDisconnect: () => void;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export { WalletConnectLegacyConnector };
|
|
@@ -1,179 +0,0 @@
|
|
|
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
|
-
|
|
12
|
-
// src/walletConnectLegacy.ts
|
|
13
|
-
import {
|
|
14
|
-
SwitchChainError,
|
|
15
|
-
UserRejectedRequestError,
|
|
16
|
-
createWalletClient,
|
|
17
|
-
custom,
|
|
18
|
-
getAddress,
|
|
19
|
-
numberToHex
|
|
20
|
-
} from "viem";
|
|
21
|
-
var switchChainAllowedRegex = /(imtoken|metamask|rainbow|trust wallet|uniswap wallet|ledger)/i;
|
|
22
|
-
var _provider, _switchChain, switchChain_fn;
|
|
23
|
-
var WalletConnectLegacyConnector = class extends Connector {
|
|
24
|
-
constructor() {
|
|
25
|
-
super(...arguments);
|
|
26
|
-
__privateAdd(this, _switchChain);
|
|
27
|
-
this.id = "walletConnectLegacy";
|
|
28
|
-
this.name = "WalletConnectLegacy";
|
|
29
|
-
this.ready = true;
|
|
30
|
-
__privateAdd(this, _provider, void 0);
|
|
31
|
-
this.onAccountsChanged = (accounts) => {
|
|
32
|
-
if (accounts.length === 0)
|
|
33
|
-
this.emit("disconnect");
|
|
34
|
-
else
|
|
35
|
-
this.emit("change", { account: getAddress(accounts[0]) });
|
|
36
|
-
};
|
|
37
|
-
this.onChainChanged = (chainId) => {
|
|
38
|
-
const id = normalizeChainId(chainId);
|
|
39
|
-
const unsupported = this.isChainUnsupported(id);
|
|
40
|
-
this.emit("change", { chain: { id, unsupported } });
|
|
41
|
-
};
|
|
42
|
-
this.onDisconnect = () => {
|
|
43
|
-
this.emit("disconnect");
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
async connect({ chainId } = {}) {
|
|
47
|
-
try {
|
|
48
|
-
let targetChainId = chainId;
|
|
49
|
-
if (!targetChainId) {
|
|
50
|
-
const store = this.storage?.getItem("store");
|
|
51
|
-
const lastUsedChainId = store?.state?.data?.chain?.id;
|
|
52
|
-
if (lastUsedChainId && !this.isChainUnsupported(lastUsedChainId))
|
|
53
|
-
targetChainId = lastUsedChainId;
|
|
54
|
-
}
|
|
55
|
-
const provider = await this.getProvider({
|
|
56
|
-
chainId: targetChainId,
|
|
57
|
-
create: true
|
|
58
|
-
});
|
|
59
|
-
provider.on("accountsChanged", this.onAccountsChanged);
|
|
60
|
-
provider.on("chainChanged", this.onChainChanged);
|
|
61
|
-
provider.on("disconnect", this.onDisconnect);
|
|
62
|
-
setTimeout(() => this.emit("message", { type: "connecting" }), 0);
|
|
63
|
-
const accounts = await provider.enable();
|
|
64
|
-
const account = getAddress(accounts[0]);
|
|
65
|
-
const id = await this.getChainId();
|
|
66
|
-
const unsupported = this.isChainUnsupported(id);
|
|
67
|
-
const walletName = provider.connector?.peerMeta?.name ?? "";
|
|
68
|
-
if (switchChainAllowedRegex.test(walletName))
|
|
69
|
-
this.switchChain = __privateMethod(this, _switchChain, switchChain_fn);
|
|
70
|
-
return {
|
|
71
|
-
account,
|
|
72
|
-
chain: { id, unsupported }
|
|
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/legacy-provider")).default;
|
|
111
|
-
__privateSet(this, _provider, new WalletConnectProvider({
|
|
112
|
-
...this.options,
|
|
113
|
-
chainId,
|
|
114
|
-
rpc: { ...rpc, ...this.options?.rpc }
|
|
115
|
-
}));
|
|
116
|
-
__privateGet(this, _provider).http = await __privateGet(this, _provider).setHttpProvider(chainId);
|
|
117
|
-
}
|
|
118
|
-
return __privateGet(this, _provider);
|
|
119
|
-
}
|
|
120
|
-
async getWalletClient({
|
|
121
|
-
chainId
|
|
122
|
-
} = {}) {
|
|
123
|
-
const [provider, account] = await Promise.all([
|
|
124
|
-
this.getProvider({ chainId }),
|
|
125
|
-
this.getAccount()
|
|
126
|
-
]);
|
|
127
|
-
const chain = this.chains.find((x) => x.id === chainId);
|
|
128
|
-
if (!provider)
|
|
129
|
-
throw new Error("provider is required.");
|
|
130
|
-
return createWalletClient({
|
|
131
|
-
account,
|
|
132
|
-
chain,
|
|
133
|
-
transport: custom(provider)
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
async isAuthorized() {
|
|
137
|
-
try {
|
|
138
|
-
const account = await this.getAccount();
|
|
139
|
-
return !!account;
|
|
140
|
-
} catch {
|
|
141
|
-
return false;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
_provider = new WeakMap();
|
|
146
|
-
_switchChain = new WeakSet();
|
|
147
|
-
switchChain_fn = async function(chainId) {
|
|
148
|
-
const provider = await this.getProvider();
|
|
149
|
-
const id = numberToHex(chainId);
|
|
150
|
-
try {
|
|
151
|
-
await Promise.race([
|
|
152
|
-
provider.request({
|
|
153
|
-
method: "wallet_switchEthereumChain",
|
|
154
|
-
params: [{ chainId: id }]
|
|
155
|
-
}),
|
|
156
|
-
new Promise(
|
|
157
|
-
(res) => this.on("change", ({ chain }) => {
|
|
158
|
-
if (chain?.id === chainId)
|
|
159
|
-
res(chainId);
|
|
160
|
-
})
|
|
161
|
-
)
|
|
162
|
-
]);
|
|
163
|
-
return this.chains.find((x) => x.id === chainId) ?? {
|
|
164
|
-
id: chainId,
|
|
165
|
-
name: `Chain ${id}`,
|
|
166
|
-
network: `${id}`,
|
|
167
|
-
nativeCurrency: { name: "Ether", decimals: 18, symbol: "ETH" },
|
|
168
|
-
rpcUrls: { default: { http: [""] }, public: { http: [""] } }
|
|
169
|
-
};
|
|
170
|
-
} catch (error) {
|
|
171
|
-
const message = typeof error === "string" ? error : error?.message;
|
|
172
|
-
if (/user rejected request/i.test(message))
|
|
173
|
-
throw new UserRejectedRequestError(error);
|
|
174
|
-
throw new SwitchChainError(error);
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
export {
|
|
178
|
-
WalletConnectLegacyConnector
|
|
179
|
-
};
|
package/injected/package.json
DELETED
package/ledger/package.json
DELETED
package/metaMask/package.json
DELETED
package/mock/package.json
DELETED
package/safe/package.json
DELETED