@wagmi/connectors 0.3.19 → 1.0.0-cjs
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 +3 -3
- package/coinbaseWallet/package.json +1 -1
- package/dist/base-b7cfab8e.d.ts +133 -0
- package/dist/{chunk-2VZS2JHJ.js → chunk-HIOOQYJ7.js} +95 -79
- package/dist/chunk-OQILYQDO.js +15 -0
- package/dist/{chunk-5NCTPR6C.js → chunk-QYMCVNHT.js} +18 -14
- package/dist/chunk-ZCAPXGBX.js +26 -0
- package/dist/coinbaseWallet.d.ts +715 -8
- package/dist/coinbaseWallet.js +71 -72
- package/dist/index.d.ts +18 -5
- package/dist/index.js +12 -6
- package/dist/injected.d.ts +718 -12
- package/dist/injected.js +9 -7
- package/dist/ledger.d.ts +715 -8
- package/dist/ledger.js +68 -63
- package/dist/metaMask.d.ts +8 -7
- package/dist/metaMask.js +37 -37
- package/dist/mock/index.d.ts +1392 -16
- package/dist/mock/index.js +78 -82
- package/dist/safe.d.ts +715 -6
- package/dist/safe.js +53 -47
- package/dist/walletConnect.d.ts +759 -9
- package/dist/walletConnect.js +116 -108
- package/dist/walletConnectLegacy.d.ts +715 -9
- package/dist/walletConnectLegacy.js +66 -61
- 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 +8 -48
- package/safe/package.json +1 -1
- package/walletConnect/package.json +1 -1
- package/walletConnectLegacy/package.json +1 -1
- package/dist/base-84a689bb.d.ts +0 -65
- package/dist/types-82d07ee0.d.ts +0 -162
package/README.md
CHANGED
|
@@ -12,16 +12,16 @@ npm i @wagmi/connectors
|
|
|
12
12
|
|
|
13
13
|
## Usage
|
|
14
14
|
|
|
15
|
-
Configure your wagmi
|
|
15
|
+
Configure your wagmi config with connectors!
|
|
16
16
|
|
|
17
17
|
```tsx
|
|
18
|
-
import { configureChains,
|
|
18
|
+
import { configureChains, createConfig } from 'wagmi'
|
|
19
19
|
|
|
20
20
|
import { InjectedConnector } from '@wagmi/connectors/injected'
|
|
21
21
|
|
|
22
22
|
const { chains, provider } = configureChains(...)
|
|
23
23
|
|
|
24
|
-
const
|
|
24
|
+
const config = createConfig({
|
|
25
25
|
connectors: [
|
|
26
26
|
new InjectedConnector({ chains }),
|
|
27
27
|
],
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { Chain as Chain$1 } from '@wagmi/chains';
|
|
2
|
+
import { Address } from 'abitype';
|
|
3
|
+
import EventEmitter from 'eventemitter3';
|
|
4
|
+
import { EIP1193Provider, Transport, Chain, Account, WalletClient as WalletClient$1 } from 'viem';
|
|
5
|
+
|
|
6
|
+
type InjectedProviderFlags = {
|
|
7
|
+
isApexWallet?: true;
|
|
8
|
+
isAvalanche?: true;
|
|
9
|
+
isBackpack?: true;
|
|
10
|
+
isBifrost?: true;
|
|
11
|
+
isBitKeep?: true;
|
|
12
|
+
isBitski?: true;
|
|
13
|
+
isBlockWallet?: true;
|
|
14
|
+
isBraveWallet?: true;
|
|
15
|
+
isCoinbaseWallet?: true;
|
|
16
|
+
isDawn?: true;
|
|
17
|
+
isEnkrypt?: true;
|
|
18
|
+
isExodus?: true;
|
|
19
|
+
isFrame?: true;
|
|
20
|
+
isFrontier?: true;
|
|
21
|
+
isGamestop?: true;
|
|
22
|
+
isHyperPay?: true;
|
|
23
|
+
isImToken?: true;
|
|
24
|
+
isKuCoinWallet?: true;
|
|
25
|
+
isMathWallet?: true;
|
|
26
|
+
isMetaMask?: true;
|
|
27
|
+
isOkxWallet?: true;
|
|
28
|
+
isOKExWallet?: true;
|
|
29
|
+
isOneInchAndroidWallet?: true;
|
|
30
|
+
isOneInchIOSWallet?: true;
|
|
31
|
+
isOpera?: true;
|
|
32
|
+
isPhantom?: true;
|
|
33
|
+
isPortal?: true;
|
|
34
|
+
isRabby?: true;
|
|
35
|
+
isRainbow?: true;
|
|
36
|
+
isStatus?: true;
|
|
37
|
+
isTally?: true;
|
|
38
|
+
isTokenPocket?: true;
|
|
39
|
+
isTokenary?: true;
|
|
40
|
+
isTrust?: true;
|
|
41
|
+
isTrustWallet?: true;
|
|
42
|
+
isXDEFI?: true;
|
|
43
|
+
isZerion?: true;
|
|
44
|
+
isHaloWallet?: true;
|
|
45
|
+
};
|
|
46
|
+
type InjectedProviders = InjectedProviderFlags & {
|
|
47
|
+
isMetaMask: true;
|
|
48
|
+
/** Only exists in MetaMask as of 2022/04/03 */
|
|
49
|
+
_events: {
|
|
50
|
+
connect?: () => void;
|
|
51
|
+
};
|
|
52
|
+
/** Only exists in MetaMask as of 2022/04/03 */
|
|
53
|
+
_state?: {
|
|
54
|
+
accounts?: string[];
|
|
55
|
+
initialized?: boolean;
|
|
56
|
+
isConnected?: boolean;
|
|
57
|
+
isPermanentlyDisconnected?: boolean;
|
|
58
|
+
isUnlocked?: boolean;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
interface WindowProvider extends InjectedProviders, EIP1193Provider {
|
|
62
|
+
providers?: WindowProvider[];
|
|
63
|
+
}
|
|
64
|
+
type WalletClient<TTransport extends Transport = Transport, TChain extends Chain = Chain, TAccount extends Account = Account> = WalletClient$1<TTransport, TChain, TAccount>;
|
|
65
|
+
type Storage = {
|
|
66
|
+
getItem<T>(key: string, defaultState?: T | null): T | null;
|
|
67
|
+
setItem<T>(key: string, value: T | null): void;
|
|
68
|
+
removeItem(key: string): void;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
type ConnectorData = {
|
|
72
|
+
account?: Address;
|
|
73
|
+
chain?: {
|
|
74
|
+
id: number;
|
|
75
|
+
unsupported: boolean;
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
interface ConnectorEvents {
|
|
79
|
+
change(data: ConnectorData): void;
|
|
80
|
+
connect(data: ConnectorData): void;
|
|
81
|
+
message({ type, data }: {
|
|
82
|
+
type: string;
|
|
83
|
+
data?: unknown;
|
|
84
|
+
}): void;
|
|
85
|
+
disconnect(): void;
|
|
86
|
+
error(error: Error): void;
|
|
87
|
+
}
|
|
88
|
+
declare abstract class Connector<Provider = any, Options = any> extends EventEmitter<ConnectorEvents> {
|
|
89
|
+
/** Unique connector id */
|
|
90
|
+
abstract readonly id: string;
|
|
91
|
+
/** Connector name */
|
|
92
|
+
abstract readonly name: string;
|
|
93
|
+
/** Chains connector supports */
|
|
94
|
+
readonly chains: Chain$1[];
|
|
95
|
+
/** Options to use with connector */
|
|
96
|
+
readonly options: Options;
|
|
97
|
+
/** Connector storage. */
|
|
98
|
+
protected storage?: Storage;
|
|
99
|
+
/** Whether connector is usable */
|
|
100
|
+
abstract readonly ready: boolean;
|
|
101
|
+
constructor({ chains, options, }: {
|
|
102
|
+
chains?: Chain$1[];
|
|
103
|
+
options: Options;
|
|
104
|
+
});
|
|
105
|
+
abstract connect(config?: {
|
|
106
|
+
chainId?: number;
|
|
107
|
+
}): Promise<Required<ConnectorData>>;
|
|
108
|
+
abstract disconnect(): Promise<void>;
|
|
109
|
+
abstract getAccount(): Promise<Address>;
|
|
110
|
+
abstract getChainId(): Promise<number>;
|
|
111
|
+
abstract getProvider(config?: {
|
|
112
|
+
chainId?: number;
|
|
113
|
+
}): Promise<Provider>;
|
|
114
|
+
abstract getWalletClient(config?: {
|
|
115
|
+
chainId?: number;
|
|
116
|
+
}): Promise<WalletClient>;
|
|
117
|
+
abstract isAuthorized(): Promise<boolean>;
|
|
118
|
+
switchChain?(chainId: number): Promise<Chain$1>;
|
|
119
|
+
watchAsset?(asset: {
|
|
120
|
+
address: string;
|
|
121
|
+
decimals?: number;
|
|
122
|
+
image?: string;
|
|
123
|
+
symbol: string;
|
|
124
|
+
}): Promise<boolean>;
|
|
125
|
+
protected abstract onAccountsChanged(accounts: Address[]): void;
|
|
126
|
+
protected abstract onChainChanged(chain: number | string): void;
|
|
127
|
+
protected abstract onDisconnect(error: Error): void;
|
|
128
|
+
protected getBlockExplorerUrls(chain: Chain$1): string[] | undefined;
|
|
129
|
+
protected isChainUnsupported(chainId: number): boolean;
|
|
130
|
+
setStorage(storage: Storage): void;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export { Connector as C, WindowProvider as W, ConnectorData as a, ConnectorEvents as b, WalletClient as c };
|
|
@@ -1,25 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunkZCAPXGBXjs = require('./chunk-ZCAPXGBX.js');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
var _chunkOQILYQDOjs = require('./chunk-OQILYQDO.js');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
var _chunkQYMCVNHTjs = require('./chunk-QYMCVNHT.js');
|
|
8
15
|
|
|
9
16
|
// src/injected.ts
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
normalizeChainId
|
|
20
|
-
} from "@wagmi/core";
|
|
21
|
-
import { providers } from "ethers";
|
|
22
|
-
import { getAddress, hexValue } from "ethers/lib/utils.js";
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
var _viem = require('viem');
|
|
23
26
|
|
|
24
27
|
// src/utils/getInjectedName.ts
|
|
25
28
|
function getInjectedName(ethereum) {
|
|
@@ -60,6 +63,8 @@ function getInjectedName(ethereum) {
|
|
|
60
63
|
return "HyperPay Wallet";
|
|
61
64
|
if (provider.isImToken)
|
|
62
65
|
return "ImToken";
|
|
66
|
+
if (provider.isHaloWallet)
|
|
67
|
+
return "Halo Wallet";
|
|
63
68
|
if (provider.isKuCoinWallet)
|
|
64
69
|
return "KuCoin Wallet";
|
|
65
70
|
if (provider.isMathWallet)
|
|
@@ -95,7 +100,7 @@ function getInjectedName(ethereum) {
|
|
|
95
100
|
if (provider.isMetaMask)
|
|
96
101
|
return "MetaMask";
|
|
97
102
|
};
|
|
98
|
-
if (ethereum.providers
|
|
103
|
+
if (_optionalChain([ethereum, 'access', _ => _.providers, 'optionalAccess', _2 => _2.length])) {
|
|
99
104
|
const nameSet = /* @__PURE__ */ new Set();
|
|
100
105
|
let unknownCount = 1;
|
|
101
106
|
for (const provider of ethereum.providers) {
|
|
@@ -109,43 +114,50 @@ function getInjectedName(ethereum) {
|
|
|
109
114
|
const names = [...nameSet];
|
|
110
115
|
if (names.length)
|
|
111
116
|
return names;
|
|
112
|
-
return names[0]
|
|
117
|
+
return _nullishCoalesce(names[0], () => ( "Injected"));
|
|
113
118
|
}
|
|
114
|
-
return getName(ethereum)
|
|
119
|
+
return _nullishCoalesce(getName(ethereum), () => ( "Injected"));
|
|
115
120
|
}
|
|
116
121
|
|
|
117
122
|
// src/injected.ts
|
|
118
123
|
var _provider;
|
|
119
|
-
var InjectedConnector = class extends Connector {
|
|
124
|
+
var InjectedConnector = class extends _chunkQYMCVNHTjs.Connector {
|
|
120
125
|
constructor({
|
|
121
126
|
chains,
|
|
122
127
|
options: options_
|
|
123
128
|
} = {}) {
|
|
124
129
|
const options = {
|
|
125
130
|
shimDisconnect: true,
|
|
126
|
-
getProvider
|
|
131
|
+
getProvider() {
|
|
132
|
+
if (typeof window === "undefined")
|
|
133
|
+
return;
|
|
134
|
+
const ethereum = window.ethereum;
|
|
135
|
+
if (_optionalChain([ethereum, 'optionalAccess', _3 => _3.providers]))
|
|
136
|
+
return ethereum.providers[0];
|
|
137
|
+
return ethereum;
|
|
138
|
+
},
|
|
127
139
|
...options_
|
|
128
140
|
};
|
|
129
141
|
super({ chains, options });
|
|
130
|
-
__publicField(this, "id", "injected");
|
|
131
|
-
__publicField(this, "name");
|
|
132
|
-
__publicField(this, "ready");
|
|
133
|
-
__privateAdd(this, _provider, void 0);
|
|
134
|
-
__publicField(this, "shimDisconnectKey", `${this.id}.shimDisconnect`);
|
|
135
|
-
__publicField(this, "onAccountsChanged", (accounts) => {
|
|
142
|
+
_chunkQYMCVNHTjs.__publicField.call(void 0, this, "id", "injected");
|
|
143
|
+
_chunkQYMCVNHTjs.__publicField.call(void 0, this, "name");
|
|
144
|
+
_chunkQYMCVNHTjs.__publicField.call(void 0, this, "ready");
|
|
145
|
+
_chunkQYMCVNHTjs.__privateAdd.call(void 0, this, _provider, void 0);
|
|
146
|
+
_chunkQYMCVNHTjs.__publicField.call(void 0, this, "shimDisconnectKey", `${this.id}.shimDisconnect`);
|
|
147
|
+
_chunkQYMCVNHTjs.__publicField.call(void 0, this, "onAccountsChanged", (accounts) => {
|
|
136
148
|
if (accounts.length === 0)
|
|
137
149
|
this.emit("disconnect");
|
|
138
150
|
else
|
|
139
151
|
this.emit("change", {
|
|
140
|
-
account: getAddress(accounts[0])
|
|
152
|
+
account: _viem.getAddress.call(void 0, accounts[0])
|
|
141
153
|
});
|
|
142
154
|
});
|
|
143
|
-
__publicField(this, "onChainChanged", (chainId) => {
|
|
144
|
-
const id = normalizeChainId(chainId);
|
|
155
|
+
_chunkQYMCVNHTjs.__publicField.call(void 0, this, "onChainChanged", (chainId) => {
|
|
156
|
+
const id = _chunkOQILYQDOjs.normalizeChainId.call(void 0, chainId);
|
|
145
157
|
const unsupported = this.isChainUnsupported(id);
|
|
146
158
|
this.emit("change", { chain: { id, unsupported } });
|
|
147
159
|
});
|
|
148
|
-
__publicField(this, "onDisconnect", async (error) => {
|
|
160
|
+
_chunkQYMCVNHTjs.__publicField.call(void 0, this, "onDisconnect", async (error) => {
|
|
149
161
|
if (error.code === 1013) {
|
|
150
162
|
const provider = await this.getProvider();
|
|
151
163
|
if (provider) {
|
|
@@ -156,7 +168,7 @@ var InjectedConnector = class extends Connector {
|
|
|
156
168
|
}
|
|
157
169
|
this.emit("disconnect");
|
|
158
170
|
if (this.options.shimDisconnect)
|
|
159
|
-
|
|
171
|
+
_optionalChain([this, 'access', _4 => _4.storage, 'optionalAccess', _5 => _5.removeItem, 'call', _6 => _6(this.shimDisconnectKey)]);
|
|
160
172
|
});
|
|
161
173
|
const provider = options.getProvider();
|
|
162
174
|
if (typeof options.name === "string")
|
|
@@ -179,7 +191,7 @@ var InjectedConnector = class extends Connector {
|
|
|
179
191
|
try {
|
|
180
192
|
const provider = await this.getProvider();
|
|
181
193
|
if (!provider)
|
|
182
|
-
throw new ConnectorNotFoundError();
|
|
194
|
+
throw new (0, _chunkZCAPXGBXjs.ConnectorNotFoundError)();
|
|
183
195
|
if (provider.on) {
|
|
184
196
|
provider.on("accountsChanged", this.onAccountsChanged);
|
|
185
197
|
provider.on("chainChanged", this.onChainChanged);
|
|
@@ -189,7 +201,7 @@ var InjectedConnector = class extends Connector {
|
|
|
189
201
|
const accounts = await provider.request({
|
|
190
202
|
method: "eth_requestAccounts"
|
|
191
203
|
});
|
|
192
|
-
const account = getAddress(accounts[0]);
|
|
204
|
+
const account = _viem.getAddress.call(void 0, accounts[0]);
|
|
193
205
|
let id = await this.getChainId();
|
|
194
206
|
let unsupported = this.isChainUnsupported(id);
|
|
195
207
|
if (chainId && id !== chainId) {
|
|
@@ -198,75 +210,79 @@ var InjectedConnector = class extends Connector {
|
|
|
198
210
|
unsupported = this.isChainUnsupported(id);
|
|
199
211
|
}
|
|
200
212
|
if (this.options.shimDisconnect)
|
|
201
|
-
|
|
202
|
-
return { account, chain: { id, unsupported }
|
|
213
|
+
_optionalChain([this, 'access', _7 => _7.storage, 'optionalAccess', _8 => _8.setItem, 'call', _9 => _9(this.shimDisconnectKey, true)]);
|
|
214
|
+
return { account, chain: { id, unsupported } };
|
|
203
215
|
} catch (error) {
|
|
204
216
|
if (this.isUserRejectedRequestError(error))
|
|
205
|
-
throw new UserRejectedRequestError(error);
|
|
217
|
+
throw new (0, _viem.UserRejectedRequestError)(error);
|
|
206
218
|
if (error.code === -32002)
|
|
207
|
-
throw new
|
|
219
|
+
throw new (0, _viem.ResourceNotFoundRpcError)(error);
|
|
208
220
|
throw error;
|
|
209
221
|
}
|
|
210
222
|
}
|
|
211
223
|
async disconnect() {
|
|
212
224
|
const provider = await this.getProvider();
|
|
213
|
-
if (!provider
|
|
225
|
+
if (!_optionalChain([provider, 'optionalAccess', _10 => _10.removeListener]))
|
|
214
226
|
return;
|
|
215
227
|
provider.removeListener("accountsChanged", this.onAccountsChanged);
|
|
216
228
|
provider.removeListener("chainChanged", this.onChainChanged);
|
|
217
229
|
provider.removeListener("disconnect", this.onDisconnect);
|
|
218
230
|
if (this.options.shimDisconnect)
|
|
219
|
-
|
|
231
|
+
_optionalChain([this, 'access', _11 => _11.storage, 'optionalAccess', _12 => _12.removeItem, 'call', _13 => _13(this.shimDisconnectKey)]);
|
|
220
232
|
}
|
|
221
233
|
async getAccount() {
|
|
222
234
|
const provider = await this.getProvider();
|
|
223
235
|
if (!provider)
|
|
224
|
-
throw new ConnectorNotFoundError();
|
|
236
|
+
throw new (0, _chunkZCAPXGBXjs.ConnectorNotFoundError)();
|
|
225
237
|
const accounts = await provider.request({
|
|
226
238
|
method: "eth_accounts"
|
|
227
239
|
});
|
|
228
|
-
return getAddress(accounts[0]);
|
|
240
|
+
return _viem.getAddress.call(void 0, accounts[0]);
|
|
229
241
|
}
|
|
230
242
|
async getChainId() {
|
|
231
243
|
const provider = await this.getProvider();
|
|
232
244
|
if (!provider)
|
|
233
|
-
throw new ConnectorNotFoundError();
|
|
234
|
-
return provider.request({ method: "eth_chainId" }).then(normalizeChainId);
|
|
245
|
+
throw new (0, _chunkZCAPXGBXjs.ConnectorNotFoundError)();
|
|
246
|
+
return provider.request({ method: "eth_chainId" }).then(_chunkOQILYQDOjs.normalizeChainId);
|
|
235
247
|
}
|
|
236
248
|
async getProvider() {
|
|
237
249
|
const provider = this.options.getProvider();
|
|
238
250
|
if (provider)
|
|
239
|
-
__privateSet(this, _provider, provider);
|
|
240
|
-
return __privateGet(this, _provider);
|
|
251
|
+
_chunkQYMCVNHTjs.__privateSet.call(void 0, this, _provider, provider);
|
|
252
|
+
return _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider);
|
|
241
253
|
}
|
|
242
|
-
async
|
|
254
|
+
async getWalletClient({ chainId } = {}) {
|
|
243
255
|
const [provider, account] = await Promise.all([
|
|
244
256
|
this.getProvider(),
|
|
245
257
|
this.getAccount()
|
|
246
258
|
]);
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
259
|
+
const chain = this.chains.find((x) => x.id === chainId) || this.chains[0];
|
|
260
|
+
if (!provider)
|
|
261
|
+
throw new Error("provider is required.");
|
|
262
|
+
return _viem.createWalletClient.call(void 0, {
|
|
263
|
+
account,
|
|
264
|
+
chain,
|
|
265
|
+
transport: _viem.custom.call(void 0, provider)
|
|
266
|
+
});
|
|
251
267
|
}
|
|
252
268
|
async isAuthorized() {
|
|
253
269
|
try {
|
|
254
|
-
if (this.options.shimDisconnect && !
|
|
270
|
+
if (this.options.shimDisconnect && !_optionalChain([this, 'access', _14 => _14.storage, 'optionalAccess', _15 => _15.getItem, 'call', _16 => _16(this.shimDisconnectKey)]))
|
|
255
271
|
return false;
|
|
256
272
|
const provider = await this.getProvider();
|
|
257
273
|
if (!provider)
|
|
258
|
-
throw new ConnectorNotFoundError();
|
|
274
|
+
throw new (0, _chunkZCAPXGBXjs.ConnectorNotFoundError)();
|
|
259
275
|
const account = await this.getAccount();
|
|
260
276
|
return !!account;
|
|
261
|
-
} catch {
|
|
277
|
+
} catch (e) {
|
|
262
278
|
return false;
|
|
263
279
|
}
|
|
264
280
|
}
|
|
265
281
|
async switchChain(chainId) {
|
|
266
282
|
const provider = await this.getProvider();
|
|
267
283
|
if (!provider)
|
|
268
|
-
throw new ConnectorNotFoundError();
|
|
269
|
-
const id =
|
|
284
|
+
throw new (0, _chunkZCAPXGBXjs.ConnectorNotFoundError)();
|
|
285
|
+
const id = _viem.numberToHex.call(void 0, chainId);
|
|
270
286
|
try {
|
|
271
287
|
await Promise.all([
|
|
272
288
|
provider.request({
|
|
@@ -275,23 +291,26 @@ var InjectedConnector = class extends Connector {
|
|
|
275
291
|
}),
|
|
276
292
|
new Promise(
|
|
277
293
|
(res) => this.on("change", ({ chain }) => {
|
|
278
|
-
if (chain
|
|
294
|
+
if (_optionalChain([chain, 'optionalAccess', _17 => _17.id]) === chainId)
|
|
279
295
|
res();
|
|
280
296
|
})
|
|
281
297
|
)
|
|
282
298
|
]);
|
|
283
|
-
return this.chains.find((x) => x.id === chainId)
|
|
299
|
+
return _nullishCoalesce(this.chains.find((x) => x.id === chainId), () => ( {
|
|
284
300
|
id: chainId,
|
|
285
301
|
name: `Chain ${id}`,
|
|
286
302
|
network: `${id}`,
|
|
287
303
|
nativeCurrency: { name: "Ether", decimals: 18, symbol: "ETH" },
|
|
288
304
|
rpcUrls: { default: { http: [""] }, public: { http: [""] } }
|
|
289
|
-
};
|
|
305
|
+
}));
|
|
290
306
|
} catch (error) {
|
|
291
307
|
const chain = this.chains.find((x) => x.id === chainId);
|
|
292
308
|
if (!chain)
|
|
293
|
-
throw new
|
|
294
|
-
|
|
309
|
+
throw new (0, _chunkZCAPXGBXjs.ChainNotConfiguredForConnectorError)({
|
|
310
|
+
chainId,
|
|
311
|
+
connectorId: this.id
|
|
312
|
+
});
|
|
313
|
+
if (error.code === 4902 || _optionalChain([error, 'optionalAccess', _18 => _18.data, 'optionalAccess', _19 => _19.originalError, 'optionalAccess', _20 => _20.code]) === 4902) {
|
|
295
314
|
try {
|
|
296
315
|
await provider.request({
|
|
297
316
|
method: "wallet_addEthereumChain",
|
|
@@ -300,27 +319,24 @@ var InjectedConnector = class extends Connector {
|
|
|
300
319
|
chainId: id,
|
|
301
320
|
chainName: chain.name,
|
|
302
321
|
nativeCurrency: chain.nativeCurrency,
|
|
303
|
-
rpcUrls: [chain.rpcUrls.public
|
|
322
|
+
rpcUrls: [_nullishCoalesce(_optionalChain([chain, 'access', _21 => _21.rpcUrls, 'access', _22 => _22.public, 'optionalAccess', _23 => _23.http, 'access', _24 => _24[0]]), () => ( ""))],
|
|
304
323
|
blockExplorerUrls: this.getBlockExplorerUrls(chain)
|
|
305
324
|
}
|
|
306
325
|
]
|
|
307
326
|
});
|
|
308
327
|
const currentChainId = await this.getChainId();
|
|
309
328
|
if (currentChainId !== chainId)
|
|
310
|
-
throw new
|
|
311
|
-
"User rejected switch after adding network."
|
|
312
|
-
{ code: 4001 }
|
|
329
|
+
throw new (0, _viem.UserRejectedRequestError)(
|
|
330
|
+
new Error("User rejected switch after adding network.")
|
|
313
331
|
);
|
|
314
332
|
return chain;
|
|
315
|
-
} catch (
|
|
316
|
-
|
|
317
|
-
throw new UserRejectedRequestError(addError);
|
|
318
|
-
throw new AddChainError();
|
|
333
|
+
} catch (error2) {
|
|
334
|
+
throw new (0, _viem.UserRejectedRequestError)(error2);
|
|
319
335
|
}
|
|
320
336
|
}
|
|
321
337
|
if (this.isUserRejectedRequestError(error))
|
|
322
|
-
throw new UserRejectedRequestError(error);
|
|
323
|
-
throw new SwitchChainError(error);
|
|
338
|
+
throw new (0, _viem.UserRejectedRequestError)(error);
|
|
339
|
+
throw new (0, _viem.SwitchChainError)(error);
|
|
324
340
|
}
|
|
325
341
|
}
|
|
326
342
|
async watchAsset({
|
|
@@ -331,7 +347,7 @@ var InjectedConnector = class extends Connector {
|
|
|
331
347
|
}) {
|
|
332
348
|
const provider = await this.getProvider();
|
|
333
349
|
if (!provider)
|
|
334
|
-
throw new ConnectorNotFoundError();
|
|
350
|
+
throw new (0, _chunkZCAPXGBXjs.ConnectorNotFoundError)();
|
|
335
351
|
return provider.request({
|
|
336
352
|
method: "wallet_watchAsset",
|
|
337
353
|
params: {
|
|
@@ -351,6 +367,6 @@ var InjectedConnector = class extends Connector {
|
|
|
351
367
|
};
|
|
352
368
|
_provider = new WeakMap();
|
|
353
369
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
exports.InjectedConnector = InjectedConnector;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/utils/normalizeChainId.ts
|
|
2
|
+
function normalizeChainId(chainId) {
|
|
3
|
+
if (typeof chainId === "string")
|
|
4
|
+
return Number.parseInt(
|
|
5
|
+
chainId,
|
|
6
|
+
chainId.trim().substring(0, 2) === "0x" ? 16 : 10
|
|
7
|
+
);
|
|
8
|
+
if (typeof chainId === "bigint")
|
|
9
|
+
return Number(chainId);
|
|
10
|
+
return chainId;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
exports.normalizeChainId = normalizeChainId;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }var __defProp = Object.defineProperty;
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
3
|
var __publicField = (obj, key, value) => {
|
|
4
4
|
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
@@ -28,21 +28,22 @@ var __privateMethod = (obj, member, method) => {
|
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
// src/base.ts
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
var Connector = class extends
|
|
31
|
+
var _eventemitter3 = require('eventemitter3'); var _eventemitter32 = _interopRequireDefault(_eventemitter3);
|
|
32
|
+
var _chains = require('viem/chains');
|
|
33
|
+
var Connector = class extends _eventemitter32.default {
|
|
34
34
|
constructor({
|
|
35
|
-
chains = [mainnet, goerli],
|
|
35
|
+
chains = [_chains.mainnet, _chains.goerli],
|
|
36
36
|
options
|
|
37
37
|
}) {
|
|
38
38
|
super();
|
|
39
39
|
__publicField(this, "chains");
|
|
40
40
|
__publicField(this, "options");
|
|
41
|
+
__publicField(this, "storage");
|
|
41
42
|
this.chains = chains;
|
|
42
43
|
this.options = options;
|
|
43
44
|
}
|
|
44
45
|
getBlockExplorerUrls(chain) {
|
|
45
|
-
const { default: blockExplorer, ...blockExplorers } = chain.blockExplorers
|
|
46
|
+
const { default: blockExplorer, ...blockExplorers } = _nullishCoalesce(chain.blockExplorers, () => ( {}));
|
|
46
47
|
if (blockExplorer)
|
|
47
48
|
return [
|
|
48
49
|
blockExplorer.url,
|
|
@@ -52,13 +53,16 @@ var Connector = class extends EventEmitter {
|
|
|
52
53
|
isChainUnsupported(chainId) {
|
|
53
54
|
return !this.chains.some((x) => x.id === chainId);
|
|
54
55
|
}
|
|
56
|
+
setStorage(storage) {
|
|
57
|
+
this.storage = storage;
|
|
58
|
+
}
|
|
55
59
|
};
|
|
56
60
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
exports.__publicField = __publicField; exports.__privateGet = __privateGet; exports.__privateAdd = __privateAdd; exports.__privateSet = __privateSet; exports.__privateMethod = __privateMethod; exports.Connector = Connector;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkQYMCVNHTjs = require('./chunk-QYMCVNHT.js');
|
|
4
|
+
|
|
5
|
+
// src/errors.ts
|
|
6
|
+
var ChainNotConfiguredForConnectorError = class extends Error {
|
|
7
|
+
constructor({
|
|
8
|
+
chainId,
|
|
9
|
+
connectorId
|
|
10
|
+
}) {
|
|
11
|
+
super(`Chain "${chainId}" not configured for connector "${connectorId}".`);
|
|
12
|
+
_chunkQYMCVNHTjs.__publicField.call(void 0, this, "name", "ChainNotConfiguredForConnectorError");
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
var ConnectorNotFoundError = class extends Error {
|
|
16
|
+
constructor() {
|
|
17
|
+
super(...arguments);
|
|
18
|
+
_chunkQYMCVNHTjs.__publicField.call(void 0, this, "name", "ConnectorNotFoundError");
|
|
19
|
+
_chunkQYMCVNHTjs.__publicField.call(void 0, this, "message", "Connector not found");
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
exports.ChainNotConfiguredForConnectorError = ChainNotConfiguredForConnectorError; exports.ConnectorNotFoundError = ConnectorNotFoundError;
|