@dynamic-labs/ethereum 4.9.2-preview.0 → 4.9.3

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,5 +1,32 @@
1
1
 
2
- ### [4.9.2-preview.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.9.1...v4.9.2-preview.0) (2025-03-11)
2
+ ### [4.9.3](https://github.com/dynamic-labs/dynamic-auth/compare/v4.9.2...v4.9.3) (2025-03-14)
3
+
4
+
5
+ ### Features
6
+
7
+ * allow adding extra text to ToS and PP footer using custom css ([#8290](https://github.com/dynamic-labs/dynamic-auth/issues/8290)) ([0f6eb26](https://github.com/dynamic-labs/dynamic-auth/commit/0f6eb2666ea93a32360710ba5ac14eac53e07e2d))
8
+
9
+
10
+ ### Bug Fixes
11
+
12
+ * log out if there is a mismatch in user and wallet state ([#8300](https://github.com/dynamic-labs/dynamic-auth/issues/8300)) ([82ec2ad](https://github.com/dynamic-labs/dynamic-auth/commit/82ec2add1682a576d00dfe13aa1b9cccecf96688))
13
+ * sol sponsored tx for v3 ([#8288](https://github.com/dynamic-labs/dynamic-auth/issues/8288)) ([c466fba](https://github.com/dynamic-labs/dynamic-auth/commit/c466fba417d39641631e29104ec9c156dfdf7647))
14
+ * v3 existing wallet could not log in again ([#8282](https://github.com/dynamic-labs/dynamic-auth/issues/8282)) ([c2d68ad](https://github.com/dynamic-labs/dynamic-auth/commit/c2d68adf575fcce371e438076184ef590f346c9f))
15
+
16
+ ### [4.9.2](https://github.com/dynamic-labs/dynamic-auth/compare/v4.9.1...v4.9.2) (2025-03-12)
17
+
18
+
19
+ ### Features
20
+
21
+ * **QNTM-2951:** update sdk styles ([#8214](https://github.com/dynamic-labs/dynamic-auth/issues/8214)) ([45cefa8](https://github.com/dynamic-labs/dynamic-auth/commit/45cefa82bdaad769c63ffeab4fb48f88ac855461))
22
+
23
+
24
+ ### Bug Fixes
25
+
26
+ * embedded widget race condition that would show both embedded and non-embedded widgets at the same time ([#8208](https://github.com/dynamic-labs/dynamic-auth/issues/8208)) ([031fb77](https://github.com/dynamic-labs/dynamic-auth/commit/031fb775c10daa383bf56ab7ba5fa4cf6ae9451c))
27
+ * **iframe-setup:** require the initial parent url when using an iframe ([#8268](https://github.com/dynamic-labs/dynamic-auth/issues/8268)) ([258e8a1](https://github.com/dynamic-labs/dynamic-auth/commit/258e8a128c31b8695518f9943bc74de9fce63196))
28
+ * improve WalletConnect experience ([#8201](https://github.com/dynamic-labs/dynamic-auth/issues/8201)) ([a09b16d](https://github.com/dynamic-labs/dynamic-auth/commit/a09b16de2ccd3cbba89f70a8ded4b7656f09f807)), closes [#8202](https://github.com/dynamic-labs/dynamic-auth/issues/8202) [#8207](https://github.com/dynamic-labs/dynamic-auth/issues/8207)
29
+ * prevent closing modal when mfa view is required ([#8156](https://github.com/dynamic-labs/dynamic-auth/issues/8156)) ([c34b245](https://github.com/dynamic-labs/dynamic-auth/commit/c34b24509e3f96046e72150b055d9c820f98706f))
3
30
 
4
31
  ### [4.9.1](https://github.com/dynamic-labs/dynamic-auth/compare/v4.9.0...v4.9.1) (2025-03-11)
5
32
 
package/package.cjs CHANGED
@@ -3,6 +3,6 @@
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
- var version = "4.9.2-preview.0";
6
+ var version = "4.9.3";
7
7
 
8
8
  exports.version = version;
package/package.js CHANGED
@@ -1,4 +1,4 @@
1
1
  'use client'
2
- var version = "4.9.2-preview.0";
2
+ var version = "4.9.3";
3
3
 
4
4
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/ethereum",
3
- "version": "4.9.2-preview.0",
3
+ "version": "4.9.3",
4
4
  "description": "A React SDK for implementing wallet web3 authentication and authorization to your website.",
5
5
  "author": "Dynamic Labs, Inc.",
6
6
  "license": "MIT",
@@ -19,19 +19,19 @@
19
19
  "homepage": "https://www.dynamic.xyz/",
20
20
  "dependencies": {
21
21
  "@coinbase/wallet-sdk": "4.3.0",
22
- "@walletconnect/ethereum-provider": "2.18.0",
22
+ "@walletconnect/ethereum-provider": "2.19.1",
23
23
  "eventemitter3": "5.0.1",
24
24
  "buffer": "6.0.3",
25
25
  "@metamask/sdk": "0.32.0",
26
- "@dynamic-labs/assert-package-version": "4.9.2-preview.0",
27
- "@dynamic-labs/embedded-wallet-evm": "4.9.2-preview.0",
28
- "@dynamic-labs/ethereum-core": "4.9.2-preview.0",
29
- "@dynamic-labs/logger": "4.9.2-preview.0",
30
- "@dynamic-labs/rpc-providers": "4.9.2-preview.0",
31
- "@dynamic-labs/types": "4.9.2-preview.0",
32
- "@dynamic-labs/utils": "4.9.2-preview.0",
33
- "@dynamic-labs/wallet-book": "4.9.2-preview.0",
34
- "@dynamic-labs/wallet-connector-core": "4.9.2-preview.0"
26
+ "@dynamic-labs/assert-package-version": "4.9.3",
27
+ "@dynamic-labs/embedded-wallet-evm": "4.9.3",
28
+ "@dynamic-labs/ethereum-core": "4.9.3",
29
+ "@dynamic-labs/logger": "4.9.3",
30
+ "@dynamic-labs/rpc-providers": "4.9.3",
31
+ "@dynamic-labs/types": "4.9.3",
32
+ "@dynamic-labs/utils": "4.9.3",
33
+ "@dynamic-labs/wallet-book": "4.9.3",
34
+ "@dynamic-labs/wallet-connector-core": "4.9.3"
35
35
  },
36
36
  "peerDependencies": {
37
37
  "viem": "^2.21.55"
@@ -372,7 +372,7 @@ class MetaMaskConnector extends InjectedWalletBase.InjectedWalletBase {
372
372
  return true;
373
373
  }
374
374
  getConnectionUri() {
375
- return undefined;
375
+ return this.metaMaskSDKDisplayUriState.getConnectionUri();
376
376
  }
377
377
  }
378
378
  // Utils
@@ -368,7 +368,7 @@ class MetaMaskConnector extends InjectedWalletBase {
368
368
  return true;
369
369
  }
370
370
  getConnectionUri() {
371
- return undefined;
371
+ return this.metaMaskSDKDisplayUriState.getConnectionUri();
372
372
  }
373
373
  }
374
374
  // Utils
@@ -52,6 +52,7 @@ const createMetaMaskSDKDisplayUriState = (metaMaskSDK) => {
52
52
  }, 10);
53
53
  });
54
54
  }),
55
+ getConnectionUri: () => displayUri !== null && displayUri !== void 0 ? displayUri : undefined,
55
56
  };
56
57
  };
57
58
 
@@ -1,6 +1,7 @@
1
1
  import { MetaMaskSDK } from '@metamask/sdk';
2
2
  export type MetaMaskSDKDisplayUriState = {
3
3
  consumeDisplayUri: () => Promise<string | undefined>;
4
+ getConnectionUri: () => string | undefined;
4
5
  };
5
6
  /**
6
7
  * Listens for the `display_uri` event emitted by the MetaMask SDK.
@@ -48,6 +48,7 @@ const createMetaMaskSDKDisplayUriState = (metaMaskSDK) => {
48
48
  }, 10);
49
49
  });
50
50
  }),
51
+ getConnectionUri: () => displayUri !== null && displayUri !== void 0 ? displayUri : undefined,
51
52
  };
52
53
  };
53
54
 
@@ -38,11 +38,13 @@ class WalletConnectConnector extends ethereumCore.EthereumWalletConnector {
38
38
  return _tslib.__awaiter(this, void 0, void 0, function* () {
39
39
  walletConnectorCore.logger.logVerboseTroubleshootingMessage('[WalletConnect] init called', {
40
40
  isInitialized: WalletConnectProvider.WalletConnectProvider.isInitialized,
41
+ isInitializing: WalletConnectProvider.WalletConnectProvider.isInitializing,
41
42
  });
42
43
  // we should only init the provider once as soon as possible
43
44
  // the connection is established when a wallet is selected (with getAddress)
44
- if (WalletConnectProvider.WalletConnectProvider.isInitialized) {
45
- walletConnectorCore.logger.debug('[WalletConnect] init - already initialized - skipping');
45
+ if (WalletConnectProvider.WalletConnectProvider.isInitialized ||
46
+ WalletConnectProvider.WalletConnectProvider.isInitializing) {
47
+ walletConnectorCore.logger.debug('[WalletConnect] init - already initialized or initializing - skipping');
46
48
  return;
47
49
  }
48
50
  walletConnectorCore.logger.debug('[WalletConnect] init');
@@ -92,11 +94,10 @@ class WalletConnectConnector extends ethereumCore.EthereumWalletConnector {
92
94
  getAddress(opts) {
93
95
  return _tslib.__awaiter(this, void 0, void 0, function* () {
94
96
  walletConnectorCore.logger.debug('[WalletConnect] getAddress', opts);
95
- if (!WalletConnectProvider.WalletConnectProvider.isInitialized) {
96
- walletConnectorCore.logger.debug('[WalletConnect] getAddress - WalletConnectProvider is not initialized');
97
- throw new utils.DynamicError('WalletConnectProvider is not initialized');
98
- }
99
- walletConnectorCore.logger.debug('[WalletConnect] getAddress - connecting to WalletConnect');
97
+ const provider = yield WalletConnectProvider.WalletConnectProvider.awaitAndGetProvider();
98
+ walletConnectorCore.logger.debug('[WalletConnect] getAddress - connecting to WalletConnect', {
99
+ provider,
100
+ });
100
101
  const addresses = yield WalletConnectProvider.WalletConnectProvider.connect({
101
102
  connectionOpts: opts,
102
103
  deepLinkPreference: this.deepLinkPreference,
@@ -196,7 +197,7 @@ class WalletConnectConnector extends ethereumCore.EthereumWalletConnector {
196
197
  getNetwork() {
197
198
  return _tslib.__awaiter(this, void 0, void 0, function* () {
198
199
  walletConnectorCore.logger.logVerboseTroubleshootingMessage('[WalletConnect] getNetwork');
199
- const provider = WalletConnectProvider.WalletConnectProvider.getProvider();
200
+ const provider = yield WalletConnectProvider.WalletConnectProvider.awaitAndGetProvider();
200
201
  if (provider === null || provider === void 0 ? void 0 : provider.chainId) {
201
202
  const network = provider.chainId;
202
203
  this.currentChainId = network;
@@ -240,7 +241,7 @@ class WalletConnectConnector extends ethereumCore.EthereumWalletConnector {
240
241
  getSupportedNetworks() {
241
242
  return _tslib.__awaiter(this, void 0, void 0, function* () {
242
243
  var _a;
243
- const provider = WalletConnectProvider.WalletConnectProvider.getProvider();
244
+ const provider = yield WalletConnectProvider.WalletConnectProvider.awaitAndGetProvider();
244
245
  if (!(provider === null || provider === void 0 ? void 0 : provider.session)) {
245
246
  return [];
246
247
  }
@@ -34,11 +34,13 @@ class WalletConnectConnector extends EthereumWalletConnector {
34
34
  return __awaiter(this, void 0, void 0, function* () {
35
35
  logger.logVerboseTroubleshootingMessage('[WalletConnect] init called', {
36
36
  isInitialized: WalletConnectProvider.isInitialized,
37
+ isInitializing: WalletConnectProvider.isInitializing,
37
38
  });
38
39
  // we should only init the provider once as soon as possible
39
40
  // the connection is established when a wallet is selected (with getAddress)
40
- if (WalletConnectProvider.isInitialized) {
41
- logger.debug('[WalletConnect] init - already initialized - skipping');
41
+ if (WalletConnectProvider.isInitialized ||
42
+ WalletConnectProvider.isInitializing) {
43
+ logger.debug('[WalletConnect] init - already initialized or initializing - skipping');
42
44
  return;
43
45
  }
44
46
  logger.debug('[WalletConnect] init');
@@ -88,11 +90,10 @@ class WalletConnectConnector extends EthereumWalletConnector {
88
90
  getAddress(opts) {
89
91
  return __awaiter(this, void 0, void 0, function* () {
90
92
  logger.debug('[WalletConnect] getAddress', opts);
91
- if (!WalletConnectProvider.isInitialized) {
92
- logger.debug('[WalletConnect] getAddress - WalletConnectProvider is not initialized');
93
- throw new DynamicError('WalletConnectProvider is not initialized');
94
- }
95
- logger.debug('[WalletConnect] getAddress - connecting to WalletConnect');
93
+ const provider = yield WalletConnectProvider.awaitAndGetProvider();
94
+ logger.debug('[WalletConnect] getAddress - connecting to WalletConnect', {
95
+ provider,
96
+ });
96
97
  const addresses = yield WalletConnectProvider.connect({
97
98
  connectionOpts: opts,
98
99
  deepLinkPreference: this.deepLinkPreference,
@@ -192,7 +193,7 @@ class WalletConnectConnector extends EthereumWalletConnector {
192
193
  getNetwork() {
193
194
  return __awaiter(this, void 0, void 0, function* () {
194
195
  logger.logVerboseTroubleshootingMessage('[WalletConnect] getNetwork');
195
- const provider = WalletConnectProvider.getProvider();
196
+ const provider = yield WalletConnectProvider.awaitAndGetProvider();
196
197
  if (provider === null || provider === void 0 ? void 0 : provider.chainId) {
197
198
  const network = provider.chainId;
198
199
  this.currentChainId = network;
@@ -236,7 +237,7 @@ class WalletConnectConnector extends EthereumWalletConnector {
236
237
  getSupportedNetworks() {
237
238
  return __awaiter(this, void 0, void 0, function* () {
238
239
  var _a;
239
- const provider = WalletConnectProvider.getProvider();
240
+ const provider = yield WalletConnectProvider.awaitAndGetProvider();
240
241
  if (!(provider === null || provider === void 0 ? void 0 : provider.session)) {
241
242
  return [];
242
243
  }
@@ -26,6 +26,7 @@ class WalletConnectProvider {
26
26
  }
27
27
  }
28
28
  _a = WalletConnectProvider;
29
+ WalletConnectProvider.isInitializing = false;
29
30
  WalletConnectProvider.isInitialized = false;
30
31
  WalletConnectProvider.enabledNetworks = [];
31
32
  WalletConnectProvider.preferredChains = [];
@@ -41,13 +42,15 @@ WalletConnectProvider.disconnectHandler = () => { };
41
42
  WalletConnectProvider.init = (...args_1) => _tslib.__awaiter(void 0, [...args_1], void 0, function* ({ storePrefix = 'dynamic-wc2', } = {}) {
42
43
  logger.logger.debug('[WalletConnectProvider] init', {
43
44
  isInitialized: _a.isInitialized,
45
+ isInitializing: _a.isInitializing,
44
46
  });
45
- if (_a.isInitialized) {
47
+ if (_a.isInitializing ||
48
+ _a.isInitialized) {
46
49
  return;
47
50
  }
48
- _a.isInitialized = true;
51
+ _a.isInitializing = true;
49
52
  logger.logger.debug('[WalletConnectProvider] initializing');
50
- _a.provider = yield EthereumProvider__default["default"].init({
53
+ _a.providerInitPromise = EthereumProvider__default["default"].init({
51
54
  customStoragePrefix: storePrefix,
52
55
  disableProviderPing: true,
53
56
  optionalChains: _a.getMappedChainsByPreferredOrder(),
@@ -67,6 +70,10 @@ WalletConnectProvider.init = (...args_1) => _tslib.__awaiter(void 0, [...args_1]
67
70
  rpcMap: _a.evmNetworkRpcMap,
68
71
  showQrModal: false,
69
72
  });
73
+ _a.provider =
74
+ yield _a.providerInitPromise;
75
+ _a.isInitialized = true;
76
+ _a.isInitializing = false;
70
77
  logger.logger.debug('[WalletConnectProvider] initialized');
71
78
  });
72
79
  /**
@@ -86,6 +93,7 @@ WalletConnectProvider.connect = (_b) => _tslib.__awaiter(void 0, [_b], void 0, f
86
93
  (_b = _a.provider) === null || _b === void 0 ? void 0 : _b.off('display_uri', handleDisplayURI);
87
94
  };
88
95
  if (!_a.provider) {
96
+ logger.logger.error('[WalletConnectProvider] connect - provider is not initialized');
89
97
  throw new utils.DynamicError('WalletConnectProvider is not initialized');
90
98
  }
91
99
  // this is in case the user just cancels the deeplink prompt (i.e. in mobile/Safari)
@@ -98,14 +106,26 @@ WalletConnectProvider.connect = (_b) => _tslib.__awaiter(void 0, [_b], void 0, f
98
106
  logger.logger.debug('[WalletConnectProvider] adding display_uri event listener');
99
107
  _a.provider.on('display_uri', handleDisplayURI);
100
108
  try {
109
+ // enable = connect to the provider
101
110
  const result = yield _a.provider.enable();
102
111
  logger.logger.debug('[WalletConnectProvider] connected to WalletConnect', result);
103
112
  return result;
104
113
  }
105
114
  catch (error) {
106
115
  logger.logger.error('[WalletConnectProvider] Failed to connect to WalletConnect', error);
107
- const customError = new utils.DynamicError('Connection rejected. Please try again.');
108
- customError.code = 'connection_rejected';
116
+ if (typeof error !== 'object' ||
117
+ error === null ||
118
+ !('message' in error) ||
119
+ typeof error.message !== 'string') {
120
+ throw error;
121
+ }
122
+ const customError = new utils.DynamicError(error.message);
123
+ if (error.message.includes('rejected')) {
124
+ customError.code = utils.ErrorCode.CONNECTION_REJECTED;
125
+ }
126
+ else if (error.message.includes('expired')) {
127
+ customError.code = utils.ErrorCode.CONNECTION_PROPOSAL_EXPIRED;
128
+ }
109
129
  throw customError;
110
130
  }
111
131
  finally {
@@ -131,8 +151,14 @@ WalletConnectProvider.disconnect = () => _tslib.__awaiter(void 0, void 0, void 0
131
151
  logger.logger.error('[WalletConnectProvider] Failed to disconnect from WalletConnect', error);
132
152
  }
133
153
  });
154
+ /**
155
+ * Waits for the provider to be initialized and returns the EthereumProvider instance.
156
+ * We should use this wherever possible (async methods), to ensure the provider is initialized.
157
+ */
158
+ WalletConnectProvider.awaitAndGetProvider = () => _tslib.__awaiter(void 0, void 0, void 0, function* () { return _a.providerInitPromise; });
134
159
  /**
135
160
  * Returns the EthereumProvider instance.
161
+ * Used when we need to access the provider synchronously.
136
162
  */
137
163
  WalletConnectProvider.getProvider = () => _a.provider;
138
164
  WalletConnectProvider.getConnectionUri = () => _a.connectionUri;
@@ -6,11 +6,13 @@ type ProviderInitOpts = {
6
6
  storePrefix?: string;
7
7
  };
8
8
  export declare class WalletConnectProvider {
9
+ static isInitializing: boolean;
9
10
  static isInitialized: boolean;
10
11
  static projectId: string;
11
12
  static enabledNetworks: GenericNetwork[];
12
13
  static preferredChains: `eip155:${number}`[];
13
14
  static evmNetworkRpcMap: Record<string, string>;
15
+ private static providerInitPromise;
14
16
  private static provider;
15
17
  /**
16
18
  * The connection URI for the current connection.
@@ -40,8 +42,14 @@ export declare class WalletConnectProvider {
40
42
  * It will kill the connection, but not the provider.
41
43
  */
42
44
  static disconnect: () => Promise<void>;
45
+ /**
46
+ * Waits for the provider to be initialized and returns the EthereumProvider instance.
47
+ * We should use this wherever possible (async methods), to ensure the provider is initialized.
48
+ */
49
+ static awaitAndGetProvider: () => Promise<EthereumProvider | undefined>;
43
50
  /**
44
51
  * Returns the EthereumProvider instance.
52
+ * Used when we need to access the provider synchronously.
45
53
  */
46
54
  static getProvider: () => EthereumProvider | undefined;
47
55
  static getConnectionUri: () => string | undefined;
@@ -2,7 +2,7 @@
2
2
  import { __awaiter } from '../../../_virtual/_tslib.js';
3
3
  import EthereumProvider from '@walletconnect/ethereum-provider';
4
4
  import { performPlatformSpecificConnectionMethod } from '@dynamic-labs/wallet-connector-core';
5
- import { parseIntSafe, DynamicError } from '@dynamic-labs/utils';
5
+ import { parseIntSafe, DynamicError, ErrorCode } from '@dynamic-labs/utils';
6
6
  import { logger } from '../../utils/logger.js';
7
7
 
8
8
  var _a;
@@ -18,6 +18,7 @@ class WalletConnectProvider {
18
18
  }
19
19
  }
20
20
  _a = WalletConnectProvider;
21
+ WalletConnectProvider.isInitializing = false;
21
22
  WalletConnectProvider.isInitialized = false;
22
23
  WalletConnectProvider.enabledNetworks = [];
23
24
  WalletConnectProvider.preferredChains = [];
@@ -33,13 +34,15 @@ WalletConnectProvider.disconnectHandler = () => { };
33
34
  WalletConnectProvider.init = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* ({ storePrefix = 'dynamic-wc2', } = {}) {
34
35
  logger.debug('[WalletConnectProvider] init', {
35
36
  isInitialized: _a.isInitialized,
37
+ isInitializing: _a.isInitializing,
36
38
  });
37
- if (_a.isInitialized) {
39
+ if (_a.isInitializing ||
40
+ _a.isInitialized) {
38
41
  return;
39
42
  }
40
- _a.isInitialized = true;
43
+ _a.isInitializing = true;
41
44
  logger.debug('[WalletConnectProvider] initializing');
42
- _a.provider = yield EthereumProvider.init({
45
+ _a.providerInitPromise = EthereumProvider.init({
43
46
  customStoragePrefix: storePrefix,
44
47
  disableProviderPing: true,
45
48
  optionalChains: _a.getMappedChainsByPreferredOrder(),
@@ -59,6 +62,10 @@ WalletConnectProvider.init = (...args_1) => __awaiter(void 0, [...args_1], void
59
62
  rpcMap: _a.evmNetworkRpcMap,
60
63
  showQrModal: false,
61
64
  });
65
+ _a.provider =
66
+ yield _a.providerInitPromise;
67
+ _a.isInitialized = true;
68
+ _a.isInitializing = false;
62
69
  logger.debug('[WalletConnectProvider] initialized');
63
70
  });
64
71
  /**
@@ -78,6 +85,7 @@ WalletConnectProvider.connect = (_b) => __awaiter(void 0, [_b], void 0, function
78
85
  (_b = _a.provider) === null || _b === void 0 ? void 0 : _b.off('display_uri', handleDisplayURI);
79
86
  };
80
87
  if (!_a.provider) {
88
+ logger.error('[WalletConnectProvider] connect - provider is not initialized');
81
89
  throw new DynamicError('WalletConnectProvider is not initialized');
82
90
  }
83
91
  // this is in case the user just cancels the deeplink prompt (i.e. in mobile/Safari)
@@ -90,14 +98,26 @@ WalletConnectProvider.connect = (_b) => __awaiter(void 0, [_b], void 0, function
90
98
  logger.debug('[WalletConnectProvider] adding display_uri event listener');
91
99
  _a.provider.on('display_uri', handleDisplayURI);
92
100
  try {
101
+ // enable = connect to the provider
93
102
  const result = yield _a.provider.enable();
94
103
  logger.debug('[WalletConnectProvider] connected to WalletConnect', result);
95
104
  return result;
96
105
  }
97
106
  catch (error) {
98
107
  logger.error('[WalletConnectProvider] Failed to connect to WalletConnect', error);
99
- const customError = new DynamicError('Connection rejected. Please try again.');
100
- customError.code = 'connection_rejected';
108
+ if (typeof error !== 'object' ||
109
+ error === null ||
110
+ !('message' in error) ||
111
+ typeof error.message !== 'string') {
112
+ throw error;
113
+ }
114
+ const customError = new DynamicError(error.message);
115
+ if (error.message.includes('rejected')) {
116
+ customError.code = ErrorCode.CONNECTION_REJECTED;
117
+ }
118
+ else if (error.message.includes('expired')) {
119
+ customError.code = ErrorCode.CONNECTION_PROPOSAL_EXPIRED;
120
+ }
101
121
  throw customError;
102
122
  }
103
123
  finally {
@@ -123,8 +143,14 @@ WalletConnectProvider.disconnect = () => __awaiter(void 0, void 0, void 0, funct
123
143
  logger.error('[WalletConnectProvider] Failed to disconnect from WalletConnect', error);
124
144
  }
125
145
  });
146
+ /**
147
+ * Waits for the provider to be initialized and returns the EthereumProvider instance.
148
+ * We should use this wherever possible (async methods), to ensure the provider is initialized.
149
+ */
150
+ WalletConnectProvider.awaitAndGetProvider = () => __awaiter(void 0, void 0, void 0, function* () { return _a.providerInitPromise; });
126
151
  /**
127
152
  * Returns the EthereumProvider instance.
153
+ * Used when we need to access the provider synchronously.
128
154
  */
129
155
  WalletConnectProvider.getProvider = () => _a.provider;
130
156
  WalletConnectProvider.getConnectionUri = () => _a.connectionUri;