@dynamic-labs/ethereum 0.18.0-beta.29 → 0.18.0-beta.30
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/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
|
|
2
|
+
## [0.18.0-beta.30](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.0-beta.29...v0.18.0-beta.30) (2023-08-04)
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* add improves to wallet events handling
|
|
7
|
+
|
|
2
8
|
## [0.18.0-beta.29](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.0-beta.28...v0.18.0-beta.29) (2023-08-03)
|
|
3
9
|
|
|
4
10
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/ethereum",
|
|
3
|
-
"version": "0.18.0-beta.
|
|
3
|
+
"version": "0.18.0-beta.30",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/dynamic-labs/DynamicAuth.git",
|
|
@@ -32,11 +32,11 @@
|
|
|
32
32
|
"ethers": "5.7.2",
|
|
33
33
|
"eventemitter3": "5.0.1",
|
|
34
34
|
"buffer": "6.0.3",
|
|
35
|
-
"@dynamic-labs/rpc-providers": "0.18.0-beta.
|
|
36
|
-
"@dynamic-labs/types": "0.18.0-beta.
|
|
37
|
-
"@dynamic-labs/utils": "0.18.0-beta.
|
|
38
|
-
"@dynamic-labs/wallet-book": "0.18.0-beta.
|
|
39
|
-
"@dynamic-labs/wallet-connector-core": "0.18.0-beta.
|
|
35
|
+
"@dynamic-labs/rpc-providers": "0.18.0-beta.30",
|
|
36
|
+
"@dynamic-labs/types": "0.18.0-beta.30",
|
|
37
|
+
"@dynamic-labs/utils": "0.18.0-beta.30",
|
|
38
|
+
"@dynamic-labs/wallet-book": "0.18.0-beta.30",
|
|
39
|
+
"@dynamic-labs/wallet-connector-core": "0.18.0-beta.30",
|
|
40
40
|
"@ethersproject/providers": "5.7.2"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {}
|
|
@@ -28,7 +28,6 @@ class WalletConnectV2 extends EthWalletConnector.EthWalletConnector {
|
|
|
28
28
|
this.isInitialized = false;
|
|
29
29
|
this.canConnectViaQrCode = true;
|
|
30
30
|
this.isWalletConnect = true;
|
|
31
|
-
this.listeners = {};
|
|
32
31
|
this.name = opts.walletName;
|
|
33
32
|
this.projectId = opts.projectId;
|
|
34
33
|
}
|
|
@@ -129,13 +128,11 @@ class WalletConnectV2 extends EthWalletConnector.EthWalletConnector {
|
|
|
129
128
|
supportsNetworkSwitching() {
|
|
130
129
|
return true;
|
|
131
130
|
}
|
|
132
|
-
setupEventListeners(
|
|
131
|
+
setupEventListeners() {
|
|
133
132
|
if (!WalletConnectV2.provider) {
|
|
134
133
|
return;
|
|
135
134
|
}
|
|
136
|
-
this.listeners = listeners;
|
|
137
135
|
WalletConnectV2.provider.client.on('session_event', ({ params }) => {
|
|
138
|
-
var _a, _b;
|
|
139
136
|
if (!params || !params.event) {
|
|
140
137
|
walletConnectorCore.logger.debug('session_event was called without params or params.event');
|
|
141
138
|
return;
|
|
@@ -147,7 +144,7 @@ class WalletConnectV2 extends EthWalletConnector.EthWalletConnector {
|
|
|
147
144
|
walletConnectorCore.logger.debug(`received unexpected data for chainChanged: ${data} with type ${typeof data}}`);
|
|
148
145
|
return;
|
|
149
146
|
}
|
|
150
|
-
(
|
|
147
|
+
this.emit('chainChange', { chain: String(chainId) });
|
|
151
148
|
// When a user switches network from their wallet, we need the provider to change network
|
|
152
149
|
// such that any future calls to `getNetwork` will return the correct network
|
|
153
150
|
this.switchNetwork({ networkChainId: chainId });
|
|
@@ -160,20 +157,18 @@ class WalletConnectV2 extends EthWalletConnector.EthWalletConnector {
|
|
|
160
157
|
// eslint-disable-next-line prefer-destructuring
|
|
161
158
|
const account = data[0].split(':')[2];
|
|
162
159
|
this.setActiveAccount(account);
|
|
163
|
-
(
|
|
160
|
+
this.emit('accountChange', { accounts: [account] });
|
|
164
161
|
}
|
|
165
162
|
});
|
|
166
163
|
WalletConnectV2.provider.client.on('session_delete', () => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
167
|
-
var _a;
|
|
168
164
|
this.endSession();
|
|
169
|
-
|
|
165
|
+
this.emit('disconnect');
|
|
170
166
|
}));
|
|
171
167
|
}
|
|
172
168
|
teardownEventListeners() {
|
|
173
169
|
if (!WalletConnectV2.provider) {
|
|
174
170
|
return;
|
|
175
171
|
}
|
|
176
|
-
this.listeners = {};
|
|
177
172
|
WalletConnectV2.provider.client.removeAllListeners('session_event');
|
|
178
173
|
WalletConnectV2.provider.client.removeAllListeners('session_delete');
|
|
179
174
|
}
|
|
@@ -248,11 +243,7 @@ class WalletConnectV2 extends EthWalletConnector.EthWalletConnector {
|
|
|
248
243
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
249
244
|
const raceConditionPromise = new Promise((resolve) => {
|
|
250
245
|
// Create listener for chain change event
|
|
251
|
-
this.
|
|
252
|
-
onChainChange: () => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
253
|
-
resolve({ success: false });
|
|
254
|
-
}),
|
|
255
|
-
});
|
|
246
|
+
this.on('chainChange', () => resolve({ success: false }));
|
|
256
247
|
signMessageFn(messageToSign).then((result) => resolve({ signedMessage: result, success: true }));
|
|
257
248
|
});
|
|
258
249
|
const signedMessageResult = yield raceConditionPromise;
|
|
@@ -351,7 +342,6 @@ class WalletConnectV2 extends EthWalletConnector.EthWalletConnector {
|
|
|
351
342
|
const _super = Object.create(null, {
|
|
352
343
|
providerSwitchNetwork: { get: () => super.providerSwitchNetwork }
|
|
353
344
|
});
|
|
354
|
-
var _a, _b;
|
|
355
345
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
356
346
|
const currentNetworkId = yield this.getNetwork();
|
|
357
347
|
if (currentNetworkId && currentNetworkId === network.chainId) {
|
|
@@ -367,7 +357,7 @@ class WalletConnectV2 extends EthWalletConnector.EthWalletConnector {
|
|
|
367
357
|
throw new utils.DynamicError('Provider not found');
|
|
368
358
|
}
|
|
369
359
|
yield _super.providerSwitchNetwork.call(this, { network, provider });
|
|
370
|
-
|
|
360
|
+
this.emit('chainChange', { chain: String(network.chainId) });
|
|
371
361
|
});
|
|
372
362
|
}
|
|
373
363
|
getConnectedAccounts() {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ethers } from 'ethers';
|
|
2
2
|
import type { SessionTypes } from '@walletconnect/types';
|
|
3
|
-
import { Chain, FetchPublicAddressOpts
|
|
3
|
+
import { Chain, FetchPublicAddressOpts } from '@dynamic-labs/wallet-connector-core';
|
|
4
4
|
import { EvmNetwork } from '@dynamic-labs/types';
|
|
5
5
|
import { EthWalletConnector, EthWalletConnectorOpts } from '../EthWalletConnector';
|
|
6
6
|
export type WalletConnectorV2Opts = EthWalletConnectorOpts & {
|
|
@@ -19,7 +19,6 @@ export declare class WalletConnectV2 extends EthWalletConnector {
|
|
|
19
19
|
isWalletConnect: boolean;
|
|
20
20
|
private static provider;
|
|
21
21
|
private projectId?;
|
|
22
|
-
private listeners;
|
|
23
22
|
constructor(opts: WalletConnectorV2Opts);
|
|
24
23
|
private initConnection;
|
|
25
24
|
private createInitProviderPromise;
|
|
@@ -29,7 +28,7 @@ export declare class WalletConnectV2 extends EthWalletConnector {
|
|
|
29
28
|
get sessionTopicKey(): string;
|
|
30
29
|
get activeAccountKey(): string;
|
|
31
30
|
supportsNetworkSwitching(): boolean;
|
|
32
|
-
setupEventListeners(
|
|
31
|
+
setupEventListeners(): void;
|
|
33
32
|
teardownEventListeners(): void;
|
|
34
33
|
getWeb3Provider(): ethers.providers.Web3Provider | undefined;
|
|
35
34
|
fetchPublicAddress(opts?: FetchPublicAddressOpts): Promise<string | undefined>;
|
|
@@ -19,7 +19,6 @@ class WalletConnectV2 extends EthWalletConnector {
|
|
|
19
19
|
this.isInitialized = false;
|
|
20
20
|
this.canConnectViaQrCode = true;
|
|
21
21
|
this.isWalletConnect = true;
|
|
22
|
-
this.listeners = {};
|
|
23
22
|
this.name = opts.walletName;
|
|
24
23
|
this.projectId = opts.projectId;
|
|
25
24
|
}
|
|
@@ -120,13 +119,11 @@ class WalletConnectV2 extends EthWalletConnector {
|
|
|
120
119
|
supportsNetworkSwitching() {
|
|
121
120
|
return true;
|
|
122
121
|
}
|
|
123
|
-
setupEventListeners(
|
|
122
|
+
setupEventListeners() {
|
|
124
123
|
if (!WalletConnectV2.provider) {
|
|
125
124
|
return;
|
|
126
125
|
}
|
|
127
|
-
this.listeners = listeners;
|
|
128
126
|
WalletConnectV2.provider.client.on('session_event', ({ params }) => {
|
|
129
|
-
var _a, _b;
|
|
130
127
|
if (!params || !params.event) {
|
|
131
128
|
logger.debug('session_event was called without params or params.event');
|
|
132
129
|
return;
|
|
@@ -138,7 +135,7 @@ class WalletConnectV2 extends EthWalletConnector {
|
|
|
138
135
|
logger.debug(`received unexpected data for chainChanged: ${data} with type ${typeof data}}`);
|
|
139
136
|
return;
|
|
140
137
|
}
|
|
141
|
-
(
|
|
138
|
+
this.emit('chainChange', { chain: String(chainId) });
|
|
142
139
|
// When a user switches network from their wallet, we need the provider to change network
|
|
143
140
|
// such that any future calls to `getNetwork` will return the correct network
|
|
144
141
|
this.switchNetwork({ networkChainId: chainId });
|
|
@@ -151,20 +148,18 @@ class WalletConnectV2 extends EthWalletConnector {
|
|
|
151
148
|
// eslint-disable-next-line prefer-destructuring
|
|
152
149
|
const account = data[0].split(':')[2];
|
|
153
150
|
this.setActiveAccount(account);
|
|
154
|
-
(
|
|
151
|
+
this.emit('accountChange', { accounts: [account] });
|
|
155
152
|
}
|
|
156
153
|
});
|
|
157
154
|
WalletConnectV2.provider.client.on('session_delete', () => __awaiter(this, void 0, void 0, function* () {
|
|
158
|
-
var _a;
|
|
159
155
|
this.endSession();
|
|
160
|
-
|
|
156
|
+
this.emit('disconnect');
|
|
161
157
|
}));
|
|
162
158
|
}
|
|
163
159
|
teardownEventListeners() {
|
|
164
160
|
if (!WalletConnectV2.provider) {
|
|
165
161
|
return;
|
|
166
162
|
}
|
|
167
|
-
this.listeners = {};
|
|
168
163
|
WalletConnectV2.provider.client.removeAllListeners('session_event');
|
|
169
164
|
WalletConnectV2.provider.client.removeAllListeners('session_delete');
|
|
170
165
|
}
|
|
@@ -239,11 +234,7 @@ class WalletConnectV2 extends EthWalletConnector {
|
|
|
239
234
|
return __awaiter(this, void 0, void 0, function* () {
|
|
240
235
|
const raceConditionPromise = new Promise((resolve) => {
|
|
241
236
|
// Create listener for chain change event
|
|
242
|
-
this.
|
|
243
|
-
onChainChange: () => __awaiter(this, void 0, void 0, function* () {
|
|
244
|
-
resolve({ success: false });
|
|
245
|
-
}),
|
|
246
|
-
});
|
|
237
|
+
this.on('chainChange', () => resolve({ success: false }));
|
|
247
238
|
signMessageFn(messageToSign).then((result) => resolve({ signedMessage: result, success: true }));
|
|
248
239
|
});
|
|
249
240
|
const signedMessageResult = yield raceConditionPromise;
|
|
@@ -342,7 +333,6 @@ class WalletConnectV2 extends EthWalletConnector {
|
|
|
342
333
|
const _super = Object.create(null, {
|
|
343
334
|
providerSwitchNetwork: { get: () => super.providerSwitchNetwork }
|
|
344
335
|
});
|
|
345
|
-
var _a, _b;
|
|
346
336
|
return __awaiter(this, void 0, void 0, function* () {
|
|
347
337
|
const currentNetworkId = yield this.getNetwork();
|
|
348
338
|
if (currentNetworkId && currentNetworkId === network.chainId) {
|
|
@@ -358,7 +348,7 @@ class WalletConnectV2 extends EthWalletConnector {
|
|
|
358
348
|
throw new DynamicError('Provider not found');
|
|
359
349
|
}
|
|
360
350
|
yield _super.providerSwitchNetwork.call(this, { network, provider });
|
|
361
|
-
|
|
351
|
+
this.emit('chainChange', { chain: String(network.chainId) });
|
|
362
352
|
});
|
|
363
353
|
}
|
|
364
354
|
getConnectedAccounts() {
|