@wagmi/connectors 2.3.0 → 2.4.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.
@@ -1,73 +1,73 @@
1
- import {
2
- normalizeChainId
3
- } from "../chunk-OQILYQDO.js";
4
- import {
5
- Connector,
6
- __privateAdd,
7
- __privateGet,
8
- __privateMethod,
9
- __privateSet,
10
- __publicField
11
- } from "../chunk-QYMCVNHT.js";
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(); } } 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
+
11
+ var _chunkQYMCVNHTjs = require('../chunk-QYMCVNHT.js');
12
12
 
13
13
  // src/mock/connector.ts
14
- import { getAddress as getAddress2 } from "viem";
14
+ var _viem = require('viem');
15
15
 
16
16
  // src/mock/provider.ts
17
- import { default as EventEmitter } from "eventemitter3";
18
- import { UserRejectedRequestError, getAddress } from "viem";
17
+ var _eventemitter3 = require('eventemitter3'); var _eventemitter32 = _interopRequireDefault(_eventemitter3);
18
+
19
19
  var _options, _walletClient;
20
20
  var MockProvider = class {
21
21
  constructor(options) {
22
- __publicField(this, "events", new EventEmitter());
23
- __publicField(this, "chainId");
24
- __privateAdd(this, _options, void 0);
25
- __privateAdd(this, _walletClient, void 0);
22
+ _chunkQYMCVNHTjs.__publicField.call(void 0, this, "events", new (0, _eventemitter32.default)());
23
+ _chunkQYMCVNHTjs.__publicField.call(void 0, this, "chainId");
24
+ _chunkQYMCVNHTjs.__privateAdd.call(void 0, this, _options, void 0);
25
+ _chunkQYMCVNHTjs.__privateAdd.call(void 0, this, _walletClient, void 0);
26
26
  this.chainId = options.chainId;
27
- __privateSet(this, _options, options);
27
+ _chunkQYMCVNHTjs.__privateSet.call(void 0, this, _options, options);
28
28
  }
29
29
  async enable() {
30
- if (__privateGet(this, _options).flags?.failConnect)
31
- throw new UserRejectedRequestError(new Error("Failed to connect."));
32
- if (!__privateGet(this, _walletClient))
33
- __privateSet(this, _walletClient, __privateGet(this, _options).walletClient);
34
- const address = __privateGet(this, _walletClient).account.address;
30
+ if (_optionalChain([_chunkQYMCVNHTjs.__privateGet.call(void 0, this, _options), 'access', _ => _.flags, 'optionalAccess', _2 => _2.failConnect]))
31
+ throw new (0, _viem.UserRejectedRequestError)(new Error("Failed to connect."));
32
+ if (!_chunkQYMCVNHTjs.__privateGet.call(void 0, this, _walletClient))
33
+ _chunkQYMCVNHTjs.__privateSet.call(void 0, this, _walletClient, _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _options).walletClient);
34
+ const address = _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _walletClient).account.address;
35
35
  this.events.emit("accountsChanged", [address]);
36
36
  return [address];
37
37
  }
38
38
  async disconnect() {
39
39
  this.events.emit("disconnect");
40
- __privateSet(this, _walletClient, void 0);
40
+ _chunkQYMCVNHTjs.__privateSet.call(void 0, this, _walletClient, void 0);
41
41
  }
42
42
  async getAccounts() {
43
- const address = __privateGet(this, _walletClient)?.account.address;
43
+ const address = _optionalChain([_chunkQYMCVNHTjs.__privateGet.call(void 0, this, _walletClient), 'optionalAccess', _3 => _3.account, 'access', _4 => _4.address]);
44
44
  if (!address)
45
45
  return [];
46
- return [getAddress(address)];
46
+ return [_viem.getAddress.call(void 0, address)];
47
47
  }
48
48
  getWalletClient() {
49
- const walletClient = __privateGet(this, _walletClient);
49
+ const walletClient = _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _walletClient);
50
50
  if (!walletClient)
51
51
  throw new Error("walletClient not found");
52
52
  return walletClient;
53
53
  }
54
54
  async switchChain(chainId) {
55
- if (__privateGet(this, _options).flags?.failSwitchChain)
56
- throw new UserRejectedRequestError(new Error("Failed to switch chain."));
57
- __privateGet(this, _options).chainId = chainId;
55
+ if (_optionalChain([_chunkQYMCVNHTjs.__privateGet.call(void 0, this, _options), 'access', _5 => _5.flags, 'optionalAccess', _6 => _6.failSwitchChain]))
56
+ throw new (0, _viem.UserRejectedRequestError)(new Error("Failed to switch chain."));
57
+ _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _options).chainId = chainId;
58
58
  this.chainId = chainId;
59
59
  this.events.emit("chainChanged", chainId);
60
60
  }
61
61
  async switchWalletClient(walletClient) {
62
62
  const address = walletClient.account.address;
63
- __privateSet(this, _walletClient, walletClient);
63
+ _chunkQYMCVNHTjs.__privateSet.call(void 0, this, _walletClient, walletClient);
64
64
  this.events.emit("accountsChanged", [address]);
65
65
  }
66
66
  async watchAsset(_asset) {
67
67
  return true;
68
68
  }
69
69
  async request({ method, params }) {
70
- return __privateGet(this, _walletClient)?.transport.request({ method, params });
70
+ return _optionalChain([_chunkQYMCVNHTjs.__privateGet.call(void 0, this, _walletClient), 'optionalAccess', _7 => _7.transport, 'access', _8 => _8.request, 'call', _9 => _9({ method, params })]);
71
71
  }
72
72
  on(event, listener) {
73
73
  this.events.on(event, listener);
@@ -86,7 +86,7 @@ _walletClient = new WeakMap();
86
86
 
87
87
  // src/mock/connector.ts
88
88
  var _provider, _switchChain, switchChain_fn;
89
- var MockConnector = class extends Connector {
89
+ var MockConnector = class extends _chunkQYMCVNHTjs.Connector {
90
90
  constructor({
91
91
  chains,
92
92
  options
@@ -95,26 +95,26 @@ var MockConnector = class extends Connector {
95
95
  chains,
96
96
  options: {
97
97
  ...options,
98
- chainId: options.chainId ?? chains?.[0]?.id
98
+ chainId: _nullishCoalesce(options.chainId, () => ( _optionalChain([chains, 'optionalAccess', _10 => _10[0], 'optionalAccess', _11 => _11.id])))
99
99
  }
100
100
  });
101
- __privateAdd(this, _switchChain);
102
- __publicField(this, "id", "mock");
103
- __publicField(this, "name", "Mock");
104
- __publicField(this, "ready", true);
105
- __privateAdd(this, _provider, void 0);
106
- __publicField(this, "onAccountsChanged", (accounts) => {
101
+ _chunkQYMCVNHTjs.__privateAdd.call(void 0, this, _switchChain);
102
+ _chunkQYMCVNHTjs.__publicField.call(void 0, this, "id", "mock");
103
+ _chunkQYMCVNHTjs.__publicField.call(void 0, this, "name", "Mock");
104
+ _chunkQYMCVNHTjs.__publicField.call(void 0, this, "ready", true);
105
+ _chunkQYMCVNHTjs.__privateAdd.call(void 0, this, _provider, void 0);
106
+ _chunkQYMCVNHTjs.__publicField.call(void 0, this, "onAccountsChanged", (accounts) => {
107
107
  if (accounts.length === 0)
108
108
  this.emit("disconnect");
109
109
  else
110
- this.emit("change", { account: getAddress2(accounts[0]) });
110
+ this.emit("change", { account: _viem.getAddress.call(void 0, accounts[0]) });
111
111
  });
112
- __publicField(this, "onChainChanged", (chainId) => {
113
- const id = normalizeChainId(chainId);
112
+ _chunkQYMCVNHTjs.__publicField.call(void 0, this, "onChainChanged", (chainId) => {
113
+ const id = _chunkOQILYQDOjs.normalizeChainId.call(void 0, chainId);
114
114
  const unsupported = this.isChainUnsupported(id);
115
115
  this.emit("change", { chain: { id, unsupported } });
116
116
  });
117
- __publicField(this, "onDisconnect", () => {
117
+ _chunkQYMCVNHTjs.__publicField.call(void 0, this, "onDisconnect", () => {
118
118
  this.emit("disconnect");
119
119
  });
120
120
  }
@@ -125,12 +125,12 @@ var MockConnector = class extends Connector {
125
125
  provider.on("disconnect", this.onDisconnect);
126
126
  this.emit("message", { type: "connecting" });
127
127
  const accounts = await provider.enable();
128
- const account = getAddress2(accounts[0]);
129
- const id = normalizeChainId(provider.chainId);
128
+ const account = _viem.getAddress.call(void 0, accounts[0]);
129
+ const id = _chunkOQILYQDOjs.normalizeChainId.call(void 0, provider.chainId);
130
130
  const unsupported = this.isChainUnsupported(id);
131
131
  const data = { account, chain: { id, unsupported }, provider };
132
- if (!this.options.flags?.noSwitchChain)
133
- this.switchChain = __privateMethod(this, _switchChain, switchChain_fn);
132
+ if (!_optionalChain([this, 'access', _12 => _12.options, 'access', _13 => _13.flags, 'optionalAccess', _14 => _14.noSwitchChain]))
133
+ this.switchChain = _chunkQYMCVNHTjs.__privateMethod.call(void 0, this, _switchChain, switchChain_fn);
134
134
  return new Promise(
135
135
  (res) => setTimeout(() => res(data), 100)
136
136
  );
@@ -148,19 +148,19 @@ var MockConnector = class extends Connector {
148
148
  const account = accounts[0];
149
149
  if (!account)
150
150
  throw new Error("Failed to get account");
151
- return getAddress2(account);
151
+ return _viem.getAddress.call(void 0, account);
152
152
  }
153
153
  async getChainId() {
154
154
  const provider = await this.getProvider();
155
- return normalizeChainId(provider.chainId);
155
+ return _chunkOQILYQDOjs.normalizeChainId.call(void 0, provider.chainId);
156
156
  }
157
157
  async getProvider({ chainId } = {}) {
158
- if (!__privateGet(this, _provider) || chainId)
159
- __privateSet(this, _provider, new MockProvider({
158
+ if (!_chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider) || chainId)
159
+ _chunkQYMCVNHTjs.__privateSet.call(void 0, this, _provider, new MockProvider({
160
160
  ...this.options,
161
- chainId: chainId ?? this.options.chainId ?? this.chains[0].id
161
+ chainId: _nullishCoalesce(_nullishCoalesce(chainId, () => ( this.options.chainId)), () => ( this.chains[0].id))
162
162
  }));
163
- return __privateGet(this, _provider);
163
+ return _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider);
164
164
  }
165
165
  async getWalletClient() {
166
166
  const provider = await this.getProvider();
@@ -170,8 +170,8 @@ var MockConnector = class extends Connector {
170
170
  try {
171
171
  const provider = await this.getProvider();
172
172
  const account = await provider.getAccounts();
173
- return this.options.flags?.isAuthorized ?? !!account;
174
- } catch {
173
+ return _nullishCoalesce(_optionalChain([this, 'access', _15 => _15.options, 'access', _16 => _16.flags, 'optionalAccess', _17 => _17.isAuthorized]), () => ( !!account));
174
+ } catch (e) {
175
175
  return false;
176
176
  }
177
177
  }
@@ -188,15 +188,15 @@ _switchChain = new WeakSet();
188
188
  switchChain_fn = async function(chainId) {
189
189
  const provider = await this.getProvider();
190
190
  await provider.switchChain(chainId);
191
- return this.chains.find((x) => x.id === chainId) ?? {
191
+ return _nullishCoalesce(this.chains.find((x) => x.id === chainId), () => ( {
192
192
  id: chainId,
193
193
  name: `Chain ${chainId}`,
194
194
  network: `${chainId}`,
195
195
  nativeCurrency: { name: "Ether", decimals: 18, symbol: "ETH" },
196
196
  rpcUrls: { default: { http: [""] }, public: { http: [""] } }
197
- };
198
- };
199
- export {
200
- MockConnector,
201
- MockProvider
197
+ }));
202
198
  };
199
+
200
+
201
+
202
+ exports.MockConnector = MockConnector; exports.MockProvider = MockProvider;
package/dist/safe.d.ts CHANGED
@@ -2,7 +2,7 @@ import * as viem from 'viem';
2
2
  import { SafeAppProvider } from '@safe-global/safe-apps-provider';
3
3
  import { Opts } from '@safe-global/safe-apps-sdk';
4
4
  import { Chain } from '@wagmi/chains';
5
- import { C as Connector } from './base-0473abd3.js';
5
+ import { C as Connector } from './base-2dd7facf.js';
6
6
  import 'eventemitter3';
7
7
 
8
8
  type SafeConnectorProvider = SafeAppProvider;
package/dist/safe.js CHANGED
@@ -1,23 +1,23 @@
1
- import {
2
- ConnectorNotFoundError
3
- } from "./chunk-ZCAPXGBX.js";
4
- import {
5
- normalizeChainId
6
- } from "./chunk-OQILYQDO.js";
7
- import {
8
- Connector,
9
- __privateAdd,
10
- __privateGet,
11
- __privateSet,
12
- __publicField
13
- } from "./chunk-QYMCVNHT.js";
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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 _chunkZCAPXGBXjs = require('./chunk-ZCAPXGBX.js');
4
+
5
+
6
+ var _chunkOQILYQDOjs = require('./chunk-OQILYQDO.js');
7
+
8
+
9
+
10
+
11
+
12
+
13
+ var _chunkQYMCVNHTjs = require('./chunk-QYMCVNHT.js');
14
14
 
15
15
  // src/safe.ts
16
- import { SafeAppProvider } from "@safe-global/safe-apps-provider";
17
- import { default as SafeAppsSDK } from "@safe-global/safe-apps-sdk";
18
- import { createWalletClient, custom, getAddress } from "viem";
16
+ var _safeappsprovider = require('@safe-global/safe-apps-provider');
17
+ var _safeappssdk = require('@safe-global/safe-apps-sdk'); var _safeappssdk2 = _interopRequireDefault(_safeappssdk);
18
+ var _viem = require('viem');
19
19
  var _provider, _sdk;
20
- var SafeConnector = class extends Connector {
20
+ var SafeConnector = class extends _chunkQYMCVNHTjs.Connector {
21
21
  constructor({
22
22
  chains,
23
23
  options: options_
@@ -27,21 +27,21 @@ var SafeConnector = class extends Connector {
27
27
  ...options_
28
28
  };
29
29
  super({ chains, options });
30
- __publicField(this, "id", "safe");
31
- __publicField(this, "name", "Safe");
32
- __publicField(this, "ready", !(typeof window === "undefined") && window?.parent !== window);
33
- __privateAdd(this, _provider, void 0);
34
- __privateAdd(this, _sdk, void 0);
35
- __publicField(this, "shimDisconnectKey", `${this.id}.shimDisconnect`);
36
- let SDK = SafeAppsSDK;
37
- if (typeof SafeAppsSDK !== "function" && typeof SafeAppsSDK.default === "function")
38
- SDK = SafeAppsSDK.default;
39
- __privateSet(this, _sdk, new SDK(options));
30
+ _chunkQYMCVNHTjs.__publicField.call(void 0, this, "id", "safe");
31
+ _chunkQYMCVNHTjs.__publicField.call(void 0, this, "name", "Safe");
32
+ _chunkQYMCVNHTjs.__publicField.call(void 0, this, "ready", !(typeof window === "undefined") && _optionalChain([window, 'optionalAccess', _ => _.parent]) !== window);
33
+ _chunkQYMCVNHTjs.__privateAdd.call(void 0, this, _provider, void 0);
34
+ _chunkQYMCVNHTjs.__privateAdd.call(void 0, this, _sdk, void 0);
35
+ _chunkQYMCVNHTjs.__publicField.call(void 0, this, "shimDisconnectKey", `${this.id}.shimDisconnect`);
36
+ let SDK = _safeappssdk2.default;
37
+ if (typeof _safeappssdk2.default !== "function" && typeof _safeappssdk2.default.default === "function")
38
+ SDK = _safeappssdk2.default.default;
39
+ _chunkQYMCVNHTjs.__privateSet.call(void 0, this, _sdk, new SDK(options));
40
40
  }
41
41
  async connect() {
42
42
  const provider = await this.getProvider();
43
43
  if (!provider)
44
- throw new ConnectorNotFoundError();
44
+ throw new (0, _chunkZCAPXGBXjs.ConnectorNotFoundError)();
45
45
  if (provider.on) {
46
46
  provider.on("accountsChanged", this.onAccountsChanged);
47
47
  provider.on("chainChanged", this.onChainChanged);
@@ -51,7 +51,7 @@ var SafeConnector = class extends Connector {
51
51
  const account = await this.getAccount();
52
52
  const id = await this.getChainId();
53
53
  if (this.options.shimDisconnect)
54
- this.storage?.setItem(this.shimDisconnectKey, true);
54
+ _optionalChain([this, 'access', _2 => _2.storage, 'optionalAccess', _3 => _3.setItem, 'call', _4 => _4(this.shimDisconnectKey, true)]);
55
55
  return {
56
56
  account,
57
57
  chain: { id, unsupported: this.isChainUnsupported(id) }
@@ -59,37 +59,37 @@ var SafeConnector = class extends Connector {
59
59
  }
60
60
  async disconnect() {
61
61
  const provider = await this.getProvider();
62
- if (!provider?.removeListener)
62
+ if (!_optionalChain([provider, 'optionalAccess', _5 => _5.removeListener]))
63
63
  return;
64
64
  provider.removeListener("accountsChanged", this.onAccountsChanged);
65
65
  provider.removeListener("chainChanged", this.onChainChanged);
66
66
  provider.removeListener("disconnect", this.onDisconnect);
67
67
  if (this.options.shimDisconnect)
68
- this.storage?.removeItem(this.shimDisconnectKey);
68
+ _optionalChain([this, 'access', _6 => _6.storage, 'optionalAccess', _7 => _7.removeItem, 'call', _8 => _8(this.shimDisconnectKey)]);
69
69
  }
70
70
  async getAccount() {
71
71
  const provider = await this.getProvider();
72
72
  if (!provider)
73
- throw new ConnectorNotFoundError();
73
+ throw new (0, _chunkZCAPXGBXjs.ConnectorNotFoundError)();
74
74
  const accounts = await provider.request({
75
75
  method: "eth_accounts"
76
76
  });
77
- return getAddress(accounts[0]);
77
+ return _viem.getAddress.call(void 0, accounts[0]);
78
78
  }
79
79
  async getChainId() {
80
80
  const provider = await this.getProvider();
81
81
  if (!provider)
82
- throw new ConnectorNotFoundError();
83
- return normalizeChainId(provider.chainId);
82
+ throw new (0, _chunkZCAPXGBXjs.ConnectorNotFoundError)();
83
+ return _chunkOQILYQDOjs.normalizeChainId.call(void 0, provider.chainId);
84
84
  }
85
85
  async getProvider() {
86
- if (!__privateGet(this, _provider)) {
87
- const safe = await __privateGet(this, _sdk).safe.getInfo();
86
+ if (!_chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider)) {
87
+ const safe = await _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _sdk).safe.getInfo();
88
88
  if (!safe)
89
89
  throw new Error("Could not load Safe information");
90
- __privateSet(this, _provider, new SafeAppProvider(safe, __privateGet(this, _sdk)));
90
+ _chunkQYMCVNHTjs.__privateSet.call(void 0, this, _provider, new (0, _safeappsprovider.SafeAppProvider)(safe, _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _sdk)));
91
91
  }
92
- return __privateGet(this, _provider);
92
+ return _chunkQYMCVNHTjs.__privateGet.call(void 0, this, _provider);
93
93
  }
94
94
  async getWalletClient({ chainId } = {}) {
95
95
  const provider = await this.getProvider();
@@ -97,19 +97,19 @@ var SafeConnector = class extends Connector {
97
97
  const chain = this.chains.find((x) => x.id === chainId);
98
98
  if (!provider)
99
99
  throw new Error("provider is required.");
100
- return createWalletClient({
100
+ return _viem.createWalletClient.call(void 0, {
101
101
  account,
102
102
  chain,
103
- transport: custom(provider)
103
+ transport: _viem.custom.call(void 0, provider)
104
104
  });
105
105
  }
106
106
  async isAuthorized() {
107
107
  try {
108
- if (this.options.shimDisconnect && !this.storage?.getItem(this.shimDisconnectKey))
108
+ if (this.options.shimDisconnect && !_optionalChain([this, 'access', _9 => _9.storage, 'optionalAccess', _10 => _10.getItem, 'call', _11 => _11(this.shimDisconnectKey)]))
109
109
  return false;
110
110
  const account = await this.getAccount();
111
111
  return !!account;
112
- } catch {
112
+ } catch (e) {
113
113
  return false;
114
114
  }
115
115
  }
@@ -123,6 +123,6 @@ var SafeConnector = class extends Connector {
123
123
  };
124
124
  _provider = new WeakMap();
125
125
  _sdk = new WeakMap();
126
- export {
127
- SafeConnector
128
- };
126
+
127
+
128
+ exports.SafeConnector = SafeConnector;
@@ -2,7 +2,7 @@ import * as viem from 'viem';
2
2
  import { Chain } from '@wagmi/chains';
3
3
  import WalletConnectProvider from '@walletconnect/ethereum-provider';
4
4
  import { EthereumProviderOptions } from '@walletconnect/ethereum-provider/dist/types/EthereumProvider';
5
- import { C as Connector } from './base-0473abd3.js';
5
+ import { C as Connector } from './base-2dd7facf.js';
6
6
  import 'eventemitter3';
7
7
 
8
8
  type WalletConnectOptions = {