@wagmi/connectors 3.1.2-cjs → 3.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,41 +1,41 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } 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
- var _chunkOQILYQDOjs = require('./chunk-OQILYQDO.js');
4
-
5
-
6
-
7
-
8
-
9
-
10
- var _chunkW65LBPLTjs = require('./chunk-W65LBPLT.js');
1
+ import {
2
+ normalizeChainId
3
+ } from "./chunk-OQILYQDO.js";
4
+ import {
5
+ Connector,
6
+ __privateAdd,
7
+ __privateGet,
8
+ __privateMethod,
9
+ __privateSet
10
+ } from "./chunk-W65LBPLT.js";
11
11
 
12
12
  // src/walletConnectLegacy.ts
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
- var _viem = require('viem');
13
+ import {
14
+ SwitchChainError,
15
+ UserRejectedRequestError,
16
+ createWalletClient,
17
+ custom,
18
+ getAddress,
19
+ numberToHex
20
+ } from "viem";
21
21
  var switchChainAllowedRegex = /(imtoken|metamask|rainbow|trust wallet|uniswap wallet|ledger)/i;
22
22
  var _provider, _switchChain, switchChain_fn;
23
- var WalletConnectLegacyConnector = class extends _chunkW65LBPLTjs.Connector {
23
+ var WalletConnectLegacyConnector = class extends Connector {
24
24
  constructor() {
25
25
  super(...arguments);
26
- _chunkW65LBPLTjs.__privateAdd.call(void 0, this, _switchChain);
26
+ __privateAdd(this, _switchChain);
27
27
  this.id = "walletConnectLegacy";
28
28
  this.name = "WalletConnectLegacy";
29
29
  this.ready = true;
30
- _chunkW65LBPLTjs.__privateAdd.call(void 0, this, _provider, void 0);
30
+ __privateAdd(this, _provider, void 0);
31
31
  this.onAccountsChanged = (accounts) => {
32
32
  if (accounts.length === 0)
33
33
  this.emit("disconnect");
34
34
  else
35
- this.emit("change", { account: _viem.getAddress.call(void 0, accounts[0]) });
35
+ this.emit("change", { account: getAddress(accounts[0]) });
36
36
  };
37
37
  this.onChainChanged = (chainId) => {
38
- const id = _chunkOQILYQDOjs.normalizeChainId.call(void 0, chainId);
38
+ const id = normalizeChainId(chainId);
39
39
  const unsupported = this.isChainUnsupported(id);
40
40
  this.emit("change", { chain: { id, unsupported } });
41
41
  };
@@ -47,8 +47,8 @@ var WalletConnectLegacyConnector = class extends _chunkW65LBPLTjs.Connector {
47
47
  try {
48
48
  let targetChainId = chainId;
49
49
  if (!targetChainId) {
50
- const store = _optionalChain([this, 'access', _ => _.storage, 'optionalAccess', _2 => _2.getItem, 'call', _3 => _3("store")]);
51
- const lastUsedChainId = _optionalChain([store, 'optionalAccess', _4 => _4.state, 'optionalAccess', _5 => _5.data, 'optionalAccess', _6 => _6.chain, 'optionalAccess', _7 => _7.id]);
50
+ const store = this.storage?.getItem("store");
51
+ const lastUsedChainId = store?.state?.data?.chain?.id;
52
52
  if (lastUsedChainId && !this.isChainUnsupported(lastUsedChainId))
53
53
  targetChainId = lastUsedChainId;
54
54
  }
@@ -61,19 +61,19 @@ var WalletConnectLegacyConnector = class extends _chunkW65LBPLTjs.Connector {
61
61
  provider.on("disconnect", this.onDisconnect);
62
62
  setTimeout(() => this.emit("message", { type: "connecting" }), 0);
63
63
  const accounts = await provider.enable();
64
- const account = _viem.getAddress.call(void 0, accounts[0]);
64
+ const account = getAddress(accounts[0]);
65
65
  const id = await this.getChainId();
66
66
  const unsupported = this.isChainUnsupported(id);
67
- const walletName = _nullishCoalesce(_optionalChain([provider, 'access', _8 => _8.connector, 'optionalAccess', _9 => _9.peerMeta, 'optionalAccess', _10 => _10.name]), () => ( ""));
67
+ const walletName = provider.connector?.peerMeta?.name ?? "";
68
68
  if (switchChainAllowedRegex.test(walletName))
69
- this.switchChain = _chunkW65LBPLTjs.__privateMethod.call(void 0, this, _switchChain, switchChain_fn);
69
+ this.switchChain = __privateMethod(this, _switchChain, switchChain_fn);
70
70
  return {
71
71
  account,
72
72
  chain: { id, unsupported }
73
73
  };
74
74
  } catch (error) {
75
75
  if (/user closed modal/i.test(error.message))
76
- throw new (0, _viem.UserRejectedRequestError)(error);
76
+ throw new UserRejectedRequestError(error);
77
77
  throw error;
78
78
  }
79
79
  }
@@ -88,34 +88,34 @@ var WalletConnectLegacyConnector = class extends _chunkW65LBPLTjs.Connector {
88
88
  async getAccount() {
89
89
  const provider = await this.getProvider();
90
90
  const accounts = provider.accounts;
91
- return _viem.getAddress.call(void 0, accounts[0]);
91
+ return getAddress(accounts[0]);
92
92
  }
93
93
  async getChainId() {
94
94
  const provider = await this.getProvider();
95
- const chainId = _chunkOQILYQDOjs.normalizeChainId.call(void 0, provider.chainId);
95
+ const chainId = normalizeChainId(provider.chainId);
96
96
  return chainId;
97
97
  }
98
98
  async getProvider({
99
99
  chainId,
100
100
  create
101
101
  } = {}) {
102
- if (!_chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider) || chainId || create) {
103
- const rpc = !_optionalChain([this, 'access', _11 => _11.options, 'optionalAccess', _12 => _12.infuraId]) ? this.chains.reduce(
102
+ if (!__privateGet(this, _provider) || chainId || create) {
103
+ const rpc = !this.options?.infuraId ? this.chains.reduce(
104
104
  (rpc2, chain) => ({
105
105
  ...rpc2,
106
106
  [chain.id]: chain.rpcUrls.default.http[0]
107
107
  }),
108
108
  {}
109
109
  ) : {};
110
- const WalletConnectProvider = (await Promise.resolve().then(() => _interopRequireWildcard(require("@walletconnect/legacy-provider")))).default;
111
- _chunkW65LBPLTjs.__privateSet.call(void 0, this, _provider, new WalletConnectProvider({
110
+ const WalletConnectProvider = (await import("@walletconnect/legacy-provider")).default;
111
+ __privateSet(this, _provider, new WalletConnectProvider({
112
112
  ...this.options,
113
113
  chainId,
114
- rpc: { ...rpc, ..._optionalChain([this, 'access', _13 => _13.options, 'optionalAccess', _14 => _14.rpc]) }
114
+ rpc: { ...rpc, ...this.options?.rpc }
115
115
  }));
116
- _chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider).http = await _chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider).setHttpProvider(chainId);
116
+ __privateGet(this, _provider).http = await __privateGet(this, _provider).setHttpProvider(chainId);
117
117
  }
118
- return _chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider);
118
+ return __privateGet(this, _provider);
119
119
  }
120
120
  async getWalletClient({
121
121
  chainId
@@ -127,17 +127,17 @@ var WalletConnectLegacyConnector = class extends _chunkW65LBPLTjs.Connector {
127
127
  const chain = this.chains.find((x) => x.id === chainId);
128
128
  if (!provider)
129
129
  throw new Error("provider is required.");
130
- return _viem.createWalletClient.call(void 0, {
130
+ return createWalletClient({
131
131
  account,
132
132
  chain,
133
- transport: _viem.custom.call(void 0, provider)
133
+ transport: custom(provider)
134
134
  });
135
135
  }
136
136
  async isAuthorized() {
137
137
  try {
138
138
  const account = await this.getAccount();
139
139
  return !!account;
140
- } catch (e) {
140
+ } catch {
141
141
  return false;
142
142
  }
143
143
  }
@@ -146,7 +146,7 @@ _provider = new WeakMap();
146
146
  _switchChain = new WeakSet();
147
147
  switchChain_fn = async function(chainId) {
148
148
  const provider = await this.getProvider();
149
- const id = _viem.numberToHex.call(void 0, chainId);
149
+ const id = numberToHex(chainId);
150
150
  try {
151
151
  await Promise.race([
152
152
  provider.request({
@@ -155,25 +155,25 @@ switchChain_fn = async function(chainId) {
155
155
  }),
156
156
  new Promise(
157
157
  (res) => this.on("change", ({ chain }) => {
158
- if (_optionalChain([chain, 'optionalAccess', _15 => _15.id]) === chainId)
158
+ if (chain?.id === chainId)
159
159
  res(chainId);
160
160
  })
161
161
  )
162
162
  ]);
163
- return _nullishCoalesce(this.chains.find((x) => x.id === chainId), () => ( {
163
+ return this.chains.find((x) => x.id === chainId) ?? {
164
164
  id: chainId,
165
165
  name: `Chain ${id}`,
166
166
  network: `${id}`,
167
167
  nativeCurrency: { name: "Ether", decimals: 18, symbol: "ETH" },
168
168
  rpcUrls: { default: { http: [""] }, public: { http: [""] } }
169
- }));
169
+ };
170
170
  } catch (error) {
171
- const message = typeof error === "string" ? error : _optionalChain([error, 'optionalAccess', _16 => _16.message]);
171
+ const message = typeof error === "string" ? error : error?.message;
172
172
  if (/user rejected request/i.test(message))
173
- throw new (0, _viem.UserRejectedRequestError)(error);
174
- throw new (0, _viem.SwitchChainError)(error);
173
+ throw new UserRejectedRequestError(error);
174
+ throw new SwitchChainError(error);
175
175
  }
176
176
  };
177
-
178
-
179
- exports.WalletConnectLegacyConnector = WalletConnectLegacyConnector;
177
+ export {
178
+ WalletConnectLegacyConnector
179
+ };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@wagmi/connectors",
3
3
  "description": "A collection of connectors for wagmi",
4
4
  "license": "MIT",
5
- "version": "3.1.2-cjs",
5
+ "version": "3.1.2",
6
6
  "peerDependencies": {
7
7
  "typescript": ">=5.0.4",
8
8
  "viem": ">=0.3.35"
@@ -27,6 +27,7 @@
27
27
  "devDependencies": {
28
28
  "viem": "^1.0.0"
29
29
  },
30
+ "type": "module",
30
31
  "main": "dist/index.js",
31
32
  "types": "dist/index.d.ts",
32
33
  "exports": {