@openocean.finance/wallet 1.10.5 → 1.10.8

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.
@@ -57,6 +57,7 @@ function isChainIdEq(wallet, chainId, utilsEht, k) {
57
57
  switch (_a.label) {
58
58
  case 0:
59
59
  key = k || 0;
60
+ console.log('isChainIdEq====', key);
60
61
  return [4 /*yield*/, (0, util_1.sleep)(1000)];
61
62
  case 1:
62
63
  _a.sent();
@@ -266,6 +267,7 @@ function linkAddOrSwitch(wallet, chain) {
266
267
  _b.label = 1;
267
268
  case 1:
268
269
  _b.trys.push([1, 9, , 22]);
270
+ console.log('wallet_switchEthereumChain____start');
269
271
  return [4 /*yield*/, currentProvider.request({
270
272
  method: 'wallet_switchEthereumChain',
271
273
  params: [{ chainId: params.chainId }],
@@ -11,6 +11,7 @@ declare class WalletConnect extends BaseWallet {
11
11
  modal: AppKit;
12
12
  modalIsClose: Boolean;
13
13
  disconnected: Boolean;
14
+ networks: any;
14
15
  init(chainId?: number, config?: any): void;
15
16
  getModalClose(): Boolean;
16
17
  /**
@@ -19,5 +20,7 @@ declare class WalletConnect extends BaseWallet {
19
20
  * @param config
20
21
  */
21
22
  requestConnect(chainId?: number, config?: any): Promise<any>;
23
+ switchNetwork(chainId: number): void;
24
+ disconnect(): Promise<void>;
22
25
  }
23
26
  export default WalletConnect;
@@ -124,7 +124,7 @@ var WalletConnect = /** @class */ (function (_super) {
124
124
  var _this = this;
125
125
  if (chainId === void 0) { chainId = 1; }
126
126
  var projectId = config && config.projectId ? config.projectId : 'c1ca7adc83e89c7e7848440702f28f38'; // '90304d7fbed3543fd7cac4b24f800264'
127
- var networks = [chains_1.mainnet, chains_1.telos, chains_1.opBNB, chains_1.mantle, chains_1.manta, chains_1.blast, chains_1.mode, chains_1.pulsechain, chains_1.merlin, chains_1.rootstock, chains_1.sei, chains_1.arbitrumSepolia, chains_1.gravity, chains_1.apeChain, chains_1.harmonyOne, chains_1.metis, chains_1.kava, chains_1.celo, chains_1.klaytn, chains_1.zksync, chains_1.linea, chains_1.lineaTestnet, chains_1.polygonZkEvm, chains_1.arbitrum, chains_1.bsc, chains_1.polygon, chains_1.okc, chains_1.xdc, chains_1.fantom, chains_1.avalanche, chains_1.optimism, chains_1.bob, chains_1.moonriver, chains_1.aurora, chains_1.cronos, chains_1.base];
127
+ var networks = this.networks = [chains_1.mainnet, chains_1.telos, chains_1.opBNB, chains_1.mantle, chains_1.manta, chains_1.blast, chains_1.mode, chains_1.pulsechain, chains_1.merlin, chains_1.rootstock, chains_1.sei, chains_1.arbitrumSepolia, chains_1.gravity, chains_1.apeChain, chains_1.harmonyOne, chains_1.metis, chains_1.kava, chains_1.celo, chains_1.klaytn, chains_1.zksync, chains_1.linea, chains_1.lineaTestnet, chains_1.polygonZkEvm, chains_1.arbitrum, chains_1.bsc, chains_1.polygon, chains_1.okc, chains_1.xdc, chains_1.fantom, chains_1.avalanche, chains_1.optimism, chains_1.bob, chains_1.moonriver, chains_1.aurora, chains_1.cronos, chains_1.base];
128
128
  var wagmiAdapter = new appkit_adapter_wagmi_1.WagmiAdapter({
129
129
  projectId: projectId,
130
130
  networks: networks
@@ -191,7 +191,7 @@ 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, chainId_1, address_1, address1, provider1, currentChainId, address;
194
+ var provider1_1, providerType, isConnected, currentChainId_1, modalChainId, currentChainId_2, modalChainId_1, address_1, address1, provider1, currentChainId, address;
195
195
  var _this = this;
196
196
  if (chainId === void 0) { chainId = 1; }
197
197
  return __generator(this, function (_a) {
@@ -206,7 +206,7 @@ var WalletConnect = /** @class */ (function (_super) {
206
206
  _a.sent();
207
207
  _a.label = 2;
208
208
  case 2:
209
- if (!this.modal) return [3 /*break*/, 6];
209
+ if (!this.modal) return [3 /*break*/, 7];
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*/, 6];
217
+ if (!(provider1_1 && isConnected && !this.disconnected)) return [3 /*break*/, 7];
218
218
  // let provider =await provider1.getProvider()
219
219
  // console.log(provider)
220
220
  console.log('requestConnect333322222-----------------');
@@ -223,16 +223,23 @@ var WalletConnect = /** @class */ (function (_super) {
223
223
  return [4 /*yield*/, this.sdk.eth.getChainId()];
224
224
  case 3:
225
225
  currentChainId_1 = _a.sent();
226
- chainId_1 = this.modal.getChainId();
227
- console.log(currentChainId_1, chainId_1);
228
- console.log('requestConnect444-----------------');
229
- if (!(chainId_1 && currentChainId_1 != chainId_1)) return [3 /*break*/, 4];
226
+ modalChainId = this.modal.getChainId();
227
+ console.log('requestConnect444-------chainId----------');
228
+ console.log(modalChainId, currentChainId_1, chainId);
229
+ if (!(chainId && currentChainId_1 != chainId)) return [3 /*break*/, 5];
230
230
  console.log('requestConnect555-----------------');
231
- throw new Error(types_1.EnumErrors.ChainIdNotMath);
231
+ this.switchNetwork(+chainId);
232
+ return [4 /*yield*/, this.sdk.eth.getChainId()];
232
233
  case 4:
233
- console.log('requestConnect666-----------------');
234
- return [4 /*yield*/, this.sdk.eth.getAccounts()];
234
+ currentChainId_2 = _a.sent();
235
+ modalChainId_1 = this.modal.getChainId();
236
+ console.log('requestConnect-------chainId----------');
237
+ console.log(modalChainId_1, currentChainId_2, chainId);
238
+ _a.label = 5;
235
239
  case 5:
240
+ console.log('requestConnect66-----------------');
241
+ return [4 /*yield*/, this.sdk.eth.getAccounts()];
242
+ case 6:
236
243
  address_1 = (_a.sent())[0];
237
244
  address1 = this.modal.getAddress();
238
245
  console.log(address_1, address1);
@@ -240,17 +247,17 @@ var WalletConnect = /** @class */ (function (_super) {
240
247
  this.chainId = currentChainId_1;
241
248
  this.disconnected = false;
242
249
  return [2 /*return*/, address_1];
243
- case 6:
250
+ case 7:
244
251
  console.log('requestConnect777-----------------');
245
252
  return [4 /*yield*/, this.modal.open({
246
253
  view: 'Connect' //'Account' | 'Connect' | 'Networks' | 'ApproveTransaction' | 'OnRampProviders';
247
254
  })];
248
- case 7:
255
+ case 8:
249
256
  _a.sent();
250
257
  return [4 /*yield*/, (0, helper_1.autoWalletCheck)(function () {
251
258
  return _this.getModalClose();
252
259
  }, 1000 * 60 * 6, 60 * 3)];
253
- case 8:
260
+ case 9:
254
261
  _a.sent();
255
262
  console.log('autoWalletCheck-----------------');
256
263
  provider1 = this.modal.getWalletProvider();
@@ -264,16 +271,17 @@ var WalletConnect = /** @class */ (function (_super) {
264
271
  // console.log(provider)
265
272
  this.sdk = new web3_1.default(provider1);
266
273
  return [4 /*yield*/, this.sdk.eth.getChainId()];
267
- case 9:
274
+ case 10:
268
275
  currentChainId = _a.sent();
269
276
  console.log('autoWalletCheck333-----------------');
270
277
  this.disconnected = false;
271
278
  if (chainId && currentChainId != chainId) {
272
- throw new Error(types_1.EnumErrors.ChainIdNotMath);
279
+ this.switchNetwork(chainId);
280
+ // throw new Error(EnumErrors.ChainIdNotMath);
273
281
  }
274
282
  console.log('autoWalletCheck4444-----------------');
275
283
  return [4 /*yield*/, this.sdk.eth.getAccounts()];
276
- case 10:
284
+ case 11:
277
285
  address = (_a.sent())[0];
278
286
  this.address = address;
279
287
  this.chainId = currentChainId;
@@ -284,6 +292,27 @@ var WalletConnect = /** @class */ (function (_super) {
284
292
  });
285
293
  });
286
294
  };
295
+ 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
+ }
300
+ };
301
+ WalletConnect.prototype.disconnect = function () {
302
+ return __awaiter(this, void 0, void 0, function () {
303
+ var _a, _b;
304
+ return __generator(this, function (_c) {
305
+ switch (_c.label) {
306
+ case 0:
307
+ this.disconnected = true;
308
+ return [4 /*yield*/, ((_b = (_a = this.modal.adapter) === null || _a === void 0 ? void 0 : _a.connectionControllerClient) === null || _b === void 0 ? void 0 : _b.disconnect())];
309
+ case 1:
310
+ _c.sent();
311
+ return [2 /*return*/];
312
+ }
313
+ });
314
+ });
315
+ };
287
316
  return WalletConnect;
288
317
  }(BaseWallet_1.default));
289
318
  exports.default = WalletConnect;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openocean.finance/wallet",
3
- "version": "1.10.5",
3
+ "version": "1.10.8",
4
4
  "description": "A multi-chain wallets manager",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -56,22 +56,22 @@
56
56
  "@onflow/fcl": "^0.0.71",
57
57
  "@ont-dev/ontology-dapi": "^0.5.7",
58
58
  "@project-serum/sol-wallet-adapter": "0.2.0",
59
- "@reown/appkit": "^1.3.0",
60
- "@reown/appkit-adapter-wagmi": "^1.3.0",
59
+ "@reown/appkit": "1.3.2",
60
+ "@reown/appkit-adapter-wagmi": "1.3.2",
61
61
  "@siddomains/sidjs": "^0.1.22",
62
62
  "@solana/web3.js": "^1.91.0",
63
63
  "@terra-money/terra.js": "3.1.10",
64
64
  "@uauth/js": "^2.4.0",
65
- "@walletconnect/ethereum-provider": "^2.17.1",
66
- "@walletconnect/modal": "^2.6.2",
65
+ "@walletconnect/ethereum-provider": "2.17.1",
66
+ "@walletconnect/modal": "2.6.2",
67
67
  "buffer": "^6.0.3",
68
68
  "fs": "^0.0.1-security",
69
69
  "near-api-js": "^0.44.2",
70
70
  "osmojs": "^13.0.0-rc.7-i-alpha",
71
71
  "path-browserify": "^1.0.1",
72
72
  "starknet": "^4.22.0",
73
- "viem": "^2.21.42",
74
- "wagmi": "^2.12.27",
73
+ "viem": "2.21.44",
74
+ "wagmi": "2.12.30",
75
75
  "web3": "^1.7.4",
76
76
  "web3-ledgerhq-frame-connector": "^1.1.0"
77
77
  },
@@ -1,17 +0,0 @@
1
- import { EnumChains, EnumWalletName, EnumWalletType } from "../types";
2
- import BaseWallet from "./BaseWallet";
3
- declare class WalletConnect extends BaseWallet {
4
- name: EnumWalletName;
5
- icon: any;
6
- supportChains: EnumChains[];
7
- type: EnumWalletType;
8
- sdk: any;
9
- infuraId?: string;
10
- /**
11
- * connect metamask and get wallet address
12
- * @param chainId specific chainId,throw error when not match
13
- * @param config
14
- */
15
- requestConnect(chainId?: number, config?: any): Promise<any>;
16
- }
17
- export default WalletConnect;
@@ -1,185 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
- return new (P || (P = Promise))(function (resolve, reject) {
20
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
- step((generator = generator.apply(thisArg, _arguments || [])).next());
24
- });
25
- };
26
- var __generator = (this && this.__generator) || function (thisArg, body) {
27
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
28
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
- function verb(n) { return function (v) { return step([n, v]); }; }
30
- function step(op) {
31
- if (f) throw new TypeError("Generator is already executing.");
32
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
33
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
- if (y = 0, t) op = [op[0] & 2, t.value];
35
- switch (op[0]) {
36
- case 0: case 1: t = op; break;
37
- case 4: _.label++; return { value: op[1], done: false };
38
- case 5: _.label++; y = op[1]; op = [0]; continue;
39
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
- default:
41
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
- if (t[2]) _.ops.pop();
46
- _.trys.pop(); continue;
47
- }
48
- op = body.call(thisArg, _);
49
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
- }
52
- };
53
- var __importDefault = (this && this.__importDefault) || function (mod) {
54
- return (mod && mod.__esModule) ? mod : { "default": mod };
55
- };
56
- Object.defineProperty(exports, "__esModule", { value: true });
57
- /**
58
- * @name WalletConnect
59
- * @author openocean
60
- * @date 2021/4/21
61
- * @desc
62
- */
63
- // @ts-ignore
64
- var walletconnect_svg_1 = __importDefault(require("../assets/walletconnect.svg"));
65
- var types_1 = require("../types");
66
- var BaseWallet_1 = __importDefault(require("./BaseWallet"));
67
- var web3_1 = __importDefault(require("web3"));
68
- var ethereum_provider_1 = require("@walletconnect/ethereum-provider");
69
- var WalletConnect = /** @class */ (function (_super) {
70
- __extends(WalletConnect, _super);
71
- function WalletConnect() {
72
- var _this = _super !== null && _super.apply(this, arguments) || this;
73
- _this.name = types_1.EnumWalletName.WalletConnect;
74
- _this.icon = walletconnect_svg_1.default;
75
- _this.supportChains = [
76
- types_1.EnumChains.ETH,
77
- types_1.EnumChains.BSC,
78
- types_1.EnumChains.Polygon,
79
- types_1.EnumChains.OKEX,
80
- types_1.EnumChains.XDai,
81
- types_1.EnumChains.HECO,
82
- types_1.EnumChains.Fantom,
83
- types_1.EnumChains.Avalanche,
84
- types_1.EnumChains.Arbitrum,
85
- types_1.EnumChains.Optimism,
86
- types_1.EnumChains.Boba,
87
- types_1.EnumChains.Moonriver,
88
- types_1.EnumChains.Aurora,
89
- types_1.EnumChains.Cronos,
90
- types_1.EnumChains.Harmony,
91
- types_1.EnumChains.Metis,
92
- types_1.EnumChains.Kava,
93
- types_1.EnumChains.Celo,
94
- types_1.EnumChains.Klaytn,
95
- types_1.EnumChains.ZKSYNC,
96
- types_1.EnumChains.Linea,
97
- types_1.EnumChains.LineaTest,
98
- types_1.EnumChains.PolygonzkEVM,
99
- types_1.EnumChains.Telos,
100
- types_1.EnumChains.OpBNB,
101
- types_1.EnumChains.Mantle,
102
- types_1.EnumChains.Manta,
103
- types_1.EnumChains.X1,
104
- types_1.EnumChains.Base,
105
- types_1.EnumChains.Blast,
106
- types_1.EnumChains.Mode,
107
- types_1.EnumChains.PulseChain,
108
- types_1.EnumChains.MerlinChain,
109
- types_1.EnumChains.Rootstock,
110
- types_1.EnumChains.Sei,
111
- types_1.EnumChains.ArbitrumSepolia,
112
- types_1.EnumChains.Gravity,
113
- types_1.EnumChains.ApeChain,
114
- ];
115
- _this.type = types_1.EnumWalletType.WalletConnect;
116
- _this.sdk = null;
117
- return _this;
118
- }
119
- /**
120
- * connect metamask and get wallet address
121
- * @param chainId specific chainId,throw error when not match
122
- * @param config
123
- */
124
- WalletConnect.prototype.requestConnect = function () {
125
- return __awaiter(this, arguments, void 0, function (chainId, config) {
126
- var rpcMap, provider, currentChainId, address;
127
- if (chainId === void 0) { chainId = 1; }
128
- return __generator(this, function (_a) {
129
- switch (_a.label) {
130
- case 0:
131
- rpcMap = {};
132
- this.supportChains.forEach(function (i) {
133
- var chain = config.chainsObj.chainObj[i];
134
- rpcMap[chain.chainId] = chain.rpcUrls[0];
135
- });
136
- console.log('chainId', chainId);
137
- console.log(rpcMap);
138
- console.log(config.chainsObj.chainIds);
139
- return [4 /*yield*/, ethereum_provider_1.EthereumProvider.init({
140
- projectId: config && config.projectId ? config.projectId : 'c1ca7adc83e89c7e7848440702f28f38', // required
141
- chains: [chainId],
142
- optionalChains: config.chainsObj.chainIds,
143
- rpcMap: rpcMap,
144
- optionalMethods: [
145
- 'wallet_addEthereumChain',
146
- 'wallet_switchEthereumChain',
147
- "eth_signTypedData",
148
- "eth_signTypedData_v4",
149
- "eth_sign"
150
- ],
151
- showQrModal: true, // requires @walletconnect/modal
152
- qrModalOptions: {
153
- themeVariables: {
154
- "--wcm-z-index": "9999",
155
- },
156
- // themeMode: 'light'
157
- }
158
- })];
159
- case 1:
160
- provider = _a.sent();
161
- console.log('provider', provider);
162
- return [4 /*yield*/, provider.enable()];
163
- case 2:
164
- _a.sent();
165
- console.log('provider', provider);
166
- this.sdk = new web3_1.default(provider);
167
- return [4 /*yield*/, this.sdk.eth.getChainId()];
168
- case 3:
169
- currentChainId = _a.sent();
170
- if (chainId && currentChainId != chainId) {
171
- throw new Error(types_1.EnumErrors.ChainIdNotMath);
172
- }
173
- return [4 /*yield*/, this.sdk.eth.getAccounts()];
174
- case 4:
175
- address = (_a.sent())[0];
176
- this.address = address;
177
- this.chainId = currentChainId;
178
- return [2 /*return*/, address];
179
- }
180
- });
181
- });
182
- };
183
- return WalletConnect;
184
- }(BaseWallet_1.default));
185
- exports.default = WalletConnect;