@openocean.finance/wallet 1.10.10 → 1.10.12

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.
@@ -242,7 +242,7 @@ function linkAddOrSwitch(wallet, chain) {
242
242
  _b.label = 1;
243
243
  case 1:
244
244
  _b.trys.push([1, 9, , 22]);
245
- console.log('wallet_switchEthereumChain____start');
245
+ console.log('wallet_switchEthereumChain____start----');
246
246
  return [4 /*yield*/, currentProvider.request({
247
247
  method: 'wallet_switchEthereumChain',
248
248
  params: [{ chainId: params.chainId }],
@@ -263,13 +263,18 @@ function linkAddOrSwitch(wallet, chain) {
263
263
  address = (_b.sent())[0];
264
264
  wallet.address = address;
265
265
  _b.label = 7;
266
- case 7: return [2 /*return*/, wallet];
266
+ case 7:
267
+ console.log('wallet_switchEthereumChain____end---');
268
+ return [2 /*return*/, wallet];
267
269
  case 8: return [3 /*break*/, 22];
268
270
  case 9:
269
271
  switchError_1 = _b.sent();
270
272
  console.log('wallet_switchEthereumChain errer');
271
- console.log(JSON.stringify(switchError_1));
273
+ console.log(switchError_1);
272
274
  console.log(params);
275
+ if (switchError_1.code === 5000 && switchError_1.message && switchError_1.message.indexOf('4902')) {
276
+ switchError_1.code = 4902;
277
+ }
273
278
  if (!(switchError_1.code === 4902 || (switchError_1.data && switchError_1.data.originalError && switchError_1.data.originalError.code == 4902))) return [3 /*break*/, 20];
274
279
  _b.label = 10;
275
280
  case 10:
@@ -20,7 +20,7 @@ declare class WalletConnect extends BaseWallet {
20
20
  * @param config
21
21
  */
22
22
  requestConnect(chainId?: number, config?: any): Promise<any>;
23
- switchNetwork(chainId: number): void;
23
+ switchNetwork(chainId: number): Promise<void>;
24
24
  disconnect(): Promise<void>;
25
25
  }
26
26
  export default WalletConnect;
@@ -191,11 +191,11 @@ var WalletConnect = /** @class */ (function (_super) {
191
191
  */
192
192
  WalletConnect.prototype.requestConnect = function () {
193
193
  return __awaiter(this, arguments, void 0, function (chainId, config) {
194
- var provider1_1, providerType, isConnected, currentChainId_1, modalChainId, currentChainId_2, modalChainId_1, address_1, address1, provider1, currentChainId, address;
194
+ var provider1_1, providerType, isConnected, currentChainId_1, modalChainId, currentChainId_2, modalChainId_1, address_1, address1, _a, provider1, currentChainId, currentChainId_3, modalChainId, address, _b;
195
195
  var _this = this;
196
196
  if (chainId === void 0) { chainId = 1; }
197
- return __generator(this, function (_a) {
198
- switch (_a.label) {
197
+ return __generator(this, function (_c) {
198
+ switch (_c.label) {
199
199
  case 0:
200
200
  this.modalIsClose = false;
201
201
  console.log('requestConnect1111-----------------');
@@ -203,10 +203,10 @@ var WalletConnect = /** @class */ (function (_super) {
203
203
  this.init(chainId, config);
204
204
  return [4 /*yield*/, (0, helper_2.sleep)(5000)];
205
205
  case 1:
206
- _a.sent();
207
- _a.label = 2;
206
+ _c.sent();
207
+ _c.label = 2;
208
208
  case 2:
209
- if (!this.modal) return [3 /*break*/, 7];
209
+ if (!this.modal) return [3 /*break*/, 10];
210
210
  console.log('requestConnect222-----------------');
211
211
  provider1_1 = this.modal.getWalletProvider();
212
212
  console.log(provider1_1);
@@ -214,7 +214,7 @@ var WalletConnect = /** @class */ (function (_super) {
214
214
  console.log('providerType', providerType);
215
215
  isConnected = this.modal.getIsConnectedState();
216
216
  console.log('requestConnect333-----------------');
217
- if (!(provider1_1 && isConnected && !this.disconnected)) return [3 /*break*/, 7];
217
+ if (!(provider1_1 && isConnected && !this.disconnected)) return [3 /*break*/, 10];
218
218
  // let provider =await provider1.getProvider()
219
219
  // console.log(provider)
220
220
  console.log('requestConnect333322222-----------------');
@@ -222,43 +222,53 @@ var WalletConnect = /** @class */ (function (_super) {
222
222
  this.sdk = new web3_1.default(provider1_1);
223
223
  return [4 /*yield*/, this.sdk.eth.getChainId()];
224
224
  case 3:
225
- currentChainId_1 = _a.sent();
225
+ currentChainId_1 = _c.sent();
226
226
  modalChainId = this.modal.getChainId();
227
227
  console.log('requestConnect444-------chainId----------');
228
228
  console.log(modalChainId, currentChainId_1, chainId);
229
- if (!(chainId && currentChainId_1 != chainId)) return [3 /*break*/, 5];
230
- console.log('requestConnect555-----------------');
231
- this.switchNetwork(+chainId);
232
- return [4 /*yield*/, this.sdk.eth.getChainId()];
229
+ if (!(chainId && currentChainId_1 != chainId)) return [3 /*break*/, 7];
230
+ console.log('requestConnect-----*********');
231
+ return [4 /*yield*/, this.switchNetwork(+chainId)];
233
232
  case 4:
234
- currentChainId_2 = _a.sent();
233
+ _c.sent();
234
+ return [4 /*yield*/, (0, helper_2.sleep)(1000)];
235
+ case 5:
236
+ _c.sent();
237
+ return [4 /*yield*/, this.sdk.eth.getChainId()];
238
+ case 6:
239
+ currentChainId_2 = _c.sent();
235
240
  modalChainId_1 = this.modal.getChainId();
236
241
  console.log('requestConnect-------chainId----------');
237
242
  console.log(modalChainId_1, currentChainId_2, chainId);
238
- _a.label = 5;
239
- case 5:
240
- console.log('requestConnect66-----------------');
243
+ this.disconnected = false;
244
+ // if (currentChainId != modalChainId || currentChainId != chainId) {
245
+ throw new Error(types_1.EnumErrors.ChainIdNotMath);
246
+ case 7:
247
+ console.log('requestConnect--------666666666666');
241
248
  return [4 /*yield*/, this.sdk.eth.getAccounts()];
242
- case 6:
243
- address_1 = (_a.sent())[0];
249
+ case 8:
250
+ address_1 = (_c.sent())[0];
244
251
  address1 = this.modal.getAddress();
245
252
  console.log(address_1, address1);
246
253
  this.address = address_1 || address1;
247
- this.chainId = currentChainId_1;
254
+ _a = this;
255
+ return [4 /*yield*/, this.sdk.eth.getChainId()];
256
+ case 9:
257
+ _a.chainId = _c.sent();
248
258
  this.disconnected = false;
249
259
  return [2 /*return*/, address_1];
250
- case 7:
260
+ case 10:
251
261
  console.log('requestConnect777-----------------');
252
262
  return [4 /*yield*/, this.modal.open({
253
263
  view: 'Connect' //'Account' | 'Connect' | 'Networks' | 'ApproveTransaction' | 'OnRampProviders';
254
264
  })];
255
- case 8:
256
- _a.sent();
265
+ case 11:
266
+ _c.sent();
257
267
  return [4 /*yield*/, (0, helper_1.autoWalletCheck)(function () {
258
268
  return _this.getModalClose();
259
269
  }, 1000 * 60 * 6, 60 * 3)];
260
- case 9:
261
- _a.sent();
270
+ case 12:
271
+ _c.sent();
262
272
  console.log('autoWalletCheck-----------------');
263
273
  provider1 = this.modal.getWalletProvider();
264
274
  console.log(provider1);
@@ -271,20 +281,35 @@ var WalletConnect = /** @class */ (function (_super) {
271
281
  // console.log(provider)
272
282
  this.sdk = new web3_1.default(provider1);
273
283
  return [4 /*yield*/, this.sdk.eth.getChainId()];
274
- case 10:
275
- currentChainId = _a.sent();
284
+ case 13:
285
+ currentChainId = _c.sent();
276
286
  console.log('autoWalletCheck333-----------------');
277
287
  this.disconnected = false;
278
- if (chainId && currentChainId != chainId) {
279
- this.switchNetwork(chainId);
280
- // throw new Error(EnumErrors.ChainIdNotMath);
281
- }
282
- console.log('autoWalletCheck4444-----------------');
288
+ if (!(chainId && currentChainId != chainId)) return [3 /*break*/, 17];
289
+ return [4 /*yield*/, this.switchNetwork(chainId)];
290
+ case 14:
291
+ _c.sent();
292
+ return [4 /*yield*/, (0, helper_2.sleep)(1000)];
293
+ case 15:
294
+ _c.sent();
295
+ return [4 /*yield*/, this.sdk.eth.getChainId()];
296
+ case 16:
297
+ currentChainId_3 = _c.sent();
298
+ modalChainId = this.modal.getChainId();
299
+ console.log('requestConnect999999-------chainId----------');
300
+ console.log(modalChainId, currentChainId_3, chainId);
301
+ // if (currentChainId != modalChainId || currentChainId != chainId) {
302
+ throw new Error(types_1.EnumErrors.ChainIdNotMath);
303
+ case 17:
304
+ console.log('autoWalletCheck------------666666666666');
283
305
  return [4 /*yield*/, this.sdk.eth.getAccounts()];
284
- case 11:
285
- address = (_a.sent())[0];
306
+ case 18:
307
+ address = (_c.sent())[0];
286
308
  this.address = address;
287
- this.chainId = currentChainId;
309
+ _b = this;
310
+ return [4 /*yield*/, this.sdk.eth.getChainId()];
311
+ case 19:
312
+ _b.chainId = _c.sent();
288
313
  console.log('address,currentChainId-----------------');
289
314
  console.log(address, currentChainId);
290
315
  return [2 /*return*/, address];
@@ -293,10 +318,21 @@ var WalletConnect = /** @class */ (function (_super) {
293
318
  });
294
319
  };
295
320
  WalletConnect.prototype.switchNetwork = function (chainId) {
296
- var chain = this.networks.find(function (item) { return item.id == chainId; });
297
- if (chain) {
298
- this.modal.switchNetwork(chain);
299
- }
321
+ return __awaiter(this, void 0, void 0, function () {
322
+ var chain;
323
+ return __generator(this, function (_a) {
324
+ switch (_a.label) {
325
+ case 0:
326
+ chain = this.networks.find(function (item) { return item.id == chainId; });
327
+ if (!chain) return [3 /*break*/, 2];
328
+ return [4 /*yield*/, this.modal.switchNetwork(chain)];
329
+ case 1:
330
+ _a.sent();
331
+ _a.label = 2;
332
+ case 2: return [2 /*return*/];
333
+ }
334
+ });
335
+ });
300
336
  };
301
337
  WalletConnect.prototype.disconnect = function () {
302
338
  return __awaiter(this, void 0, void 0, function () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openocean.finance/wallet",
3
- "version": "1.10.10",
3
+ "version": "1.10.12",
4
4
  "description": "A multi-chain wallets manager",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {