@dynamic-labs/wagmi-connector 0.13.58 → 0.13.60

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.
Files changed (2) hide show
  1. package/index.esm.js +9 -39
  2. package/package.json +3 -3
package/index.esm.js CHANGED
@@ -3,7 +3,7 @@ import { Connector as Connector$1, useConnect, useDisconnect } from 'wagmi';
3
3
  import { getNetwork, useDynamicContext } from '@dynamic-labs/sdk-react';
4
4
  import { getAddress, hexValue } from 'ethers/lib/utils.js';
5
5
 
6
- /*! *****************************************************************************
6
+ /******************************************************************************
7
7
  Copyright (c) Microsoft Corporation.
8
8
 
9
9
  Permission to use, copy, modify, and/or distribute this software for any
@@ -35,21 +35,19 @@ class Connector extends Connector$1 {
35
35
  }) {
36
36
  super({
37
37
  options: undefined
38
- }); // wagmi properties
39
-
38
+ });
39
+ // wagmi properties
40
40
  this.id = 'dynamic';
41
- this.name = 'Dynamic'; // also a wagmi prop, but is only used for auto-connect
41
+ this.name = 'Dynamic';
42
+ // also a wagmi prop, but is only used for auto-connect
42
43
  // which we have implemented ourselves, so this value
43
44
  // doesn't matter
44
-
45
45
  this.ready = false;
46
-
47
46
  this.onAccountsChanged = accounts => __awaiter(this, void 0, void 0, function* () {
48
47
  this.emit('change', {
49
48
  account: getAddress(accounts[0])
50
49
  });
51
50
  });
52
-
53
51
  this.onChainChanged = chain => __awaiter(this, void 0, void 0, function* () {
54
52
  this.emit('change', {
55
53
  chain: {
@@ -58,14 +56,11 @@ class Connector extends Connector$1 {
58
56
  }
59
57
  });
60
58
  });
61
-
62
59
  this.onDisconnect = () => __awaiter(this, void 0, void 0, function* () {});
63
-
64
60
  this.handleLogOut = handleLogOut;
65
61
  this.walletConnector = walletConnector;
66
62
  this.setupEventListeners();
67
63
  }
68
-
69
64
  setupEventListeners() {
70
65
  this.walletConnector.setupEventListeners({
71
66
  onAccountChange: this.onAccountsChanged,
@@ -73,13 +68,11 @@ class Connector extends Connector$1 {
73
68
  onDisconnect: this.onDisconnect
74
69
  });
75
70
  }
76
-
77
71
  connect(config) {
78
72
  return __awaiter(this, void 0, void 0, function* () {
79
73
  if (!this.walletConnector) {
80
74
  throw new Error('WalletConnector is not defined');
81
75
  }
82
-
83
76
  const account = yield this.getAccount();
84
77
  this.setupEventListeners();
85
78
  this.emit('message', {
@@ -99,10 +92,8 @@ class Connector extends Connector$1 {
99
92
  };
100
93
  });
101
94
  }
102
-
103
95
  disconnect() {
104
96
  var _a, _b, _c;
105
-
106
97
  return __awaiter(this, void 0, void 0, function* () {
107
98
  const web3Provider = yield this.getProvider();
108
99
  const {
@@ -115,65 +106,49 @@ class Connector extends Connector$1 {
115
106
  (_c = this.handleLogOut) === null || _c === void 0 ? void 0 : _c.call(this);
116
107
  });
117
108
  }
118
-
119
109
  getAccount() {
120
110
  var _a;
121
-
122
111
  return __awaiter(this, void 0, void 0, function* () {
123
112
  const address = yield (_a = this.walletConnector) === null || _a === void 0 ? void 0 : _a.fetchPublicAddress();
124
-
125
113
  if (!address) {
126
114
  throw new Error('Not connected');
127
115
  }
128
-
129
116
  return getAddress(address);
130
117
  });
131
118
  }
132
-
133
119
  getChainId() {
134
120
  return __awaiter(this, void 0, void 0, function* () {
135
121
  if (!this.walletConnector) {
136
122
  throw new Error('WalletConnector is not defined');
137
123
  }
138
-
139
124
  const network = yield getNetwork(this.walletConnector);
140
-
141
125
  if (!network) {
142
126
  throw new Error('Network is not defined');
143
127
  }
144
-
145
128
  return network;
146
129
  });
147
130
  }
148
-
149
131
  getProvider(config) {
150
132
  var _a;
151
-
152
133
  return __awaiter(this, void 0, void 0, function* () {
153
134
  return (_a = this.walletConnector) === null || _a === void 0 ? void 0 : _a.getWeb3Provider();
154
135
  });
155
136
  }
156
-
157
137
  getSigner(config) {
158
138
  var _a;
159
-
160
139
  return __awaiter(this, void 0, void 0, function* () {
161
140
  return (_a = this.walletConnector) === null || _a === void 0 ? void 0 : _a.getSigner();
162
141
  });
163
142
  }
164
-
165
143
  isAuthorized() {
166
144
  var _a, _b;
167
-
168
145
  return __awaiter(this, void 0, void 0, function* () {
169
146
  const accounts = (_b = yield (_a = this.walletConnector) === null || _a === void 0 ? void 0 : _a.getConnectedAccounts()) !== null && _b !== void 0 ? _b : [];
170
147
  return accounts.length > 0;
171
148
  });
172
149
  }
173
-
174
150
  switchChain(chainId) {
175
151
  var _a, _b;
176
-
177
152
  return __awaiter(this, void 0, void 0, function* () {
178
153
  yield (_a = this.walletConnector) === null || _a === void 0 ? void 0 : _a.switchNetwork({
179
154
  networkChainId: chainId
@@ -189,11 +164,9 @@ class Connector extends Connector$1 {
189
164
  };
190
165
  });
191
166
  }
192
-
193
167
  watchAsset(asset) {
194
168
  throw new Error('Method not implemented.');
195
169
  }
196
-
197
170
  }
198
171
 
199
172
  const DynamicWagmiConnector = ({
@@ -209,22 +182,19 @@ const DynamicWagmiConnector = ({
209
182
  } = useConnect();
210
183
  const {
211
184
  disconnect
212
- } = useDisconnect(); // storing as a singleton so we can re-setup event listeners on the same instance
213
-
185
+ } = useDisconnect();
186
+ // storing as a singleton so we can re-setup event listeners on the same instance
214
187
  const dynamicWagmiConnector = useRef();
215
-
216
188
  if (walletConnector) {
217
189
  // after connection is successful, re-setup event listeners after a short delay
218
190
  // so that they are not cleared by the teardown in useWalletEventListeners
219
191
  if (status === 'success') {
220
192
  setTimeout(() => {
221
193
  var _a;
222
-
223
194
  (_a = dynamicWagmiConnector.current) === null || _a === void 0 ? void 0 : _a.setupEventListeners();
224
195
  }, 100);
225
196
  }
226
197
  }
227
-
228
198
  useEffect(() => {
229
199
  if (!walletConnector) {
230
200
  dynamicWagmiConnector.current = undefined;
@@ -238,10 +208,10 @@ const DynamicWagmiConnector = ({
238
208
  connector: dynamicWagmiConnector.current
239
209
  });
240
210
  }
241
- }, [connect, disconnect, handleLogOut, status, walletConnector]); // use React.createElement to prevent bunding react/jsx-runtime,
211
+ }, [connect, disconnect, handleLogOut, status, walletConnector]);
212
+ // use React.createElement to prevent bunding react/jsx-runtime,
242
213
  // which is not compatible when bundling apps using React 17
243
214
  // eslint-disable-next-line react/no-children-prop
244
-
245
215
  return /*#__PURE__*/React.createElement(React.Fragment, {
246
216
  children
247
217
  });
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@dynamic-labs/wagmi-connector",
3
- "version": "0.13.58",
3
+ "version": "0.13.60",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "main": "./index.esm.js",
7
7
  "typings": "./index.d.ts",
8
8
  "dependencies": {},
9
9
  "peerDependencies": {
10
- "ethers": "^5.6.9",
10
+ "ethers": "^5.7.2",
11
11
  "wagmi": "^0.8.10",
12
- "@dynamic-labs/sdk-react": "0.13.58",
12
+ "@dynamic-labs/sdk-react": "0.13.60",
13
13
  "react": "^17.0.2 || ^18.0.0"
14
14
  }
15
15
  }