@openocean.finance/wallet 1.10.2 → 1.10.4
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.
|
@@ -52,7 +52,7 @@ var SID = require('@siddomains/sidjs').default;
|
|
|
52
52
|
var SIDfunctions = require('@siddomains/sidjs');
|
|
53
53
|
function isChainIdEq(wallet, chainId, utilsEht, k) {
|
|
54
54
|
return __awaiter(this, void 0, void 0, function () {
|
|
55
|
-
var key, chainIdNow;
|
|
55
|
+
var key, chainIdNow1, chainIdNow2, chainIdNow;
|
|
56
56
|
return __generator(this, function (_a) {
|
|
57
57
|
switch (_a.label) {
|
|
58
58
|
case 0:
|
|
@@ -60,15 +60,19 @@ function isChainIdEq(wallet, chainId, utilsEht, k) {
|
|
|
60
60
|
return [4 /*yield*/, (0, util_1.sleep)(1000)];
|
|
61
61
|
case 1:
|
|
62
62
|
_a.sent();
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
return [4 /*yield*/, wallet.sdk.eth.getChainId()];
|
|
64
|
+
case 2:
|
|
65
|
+
chainIdNow1 = _a.sent();
|
|
66
|
+
chainIdNow2 = utilsEht.hexToNumber(wallet.sdk.currentProvider.chainId);
|
|
67
|
+
chainIdNow = chainIdNow2 || chainIdNow1;
|
|
68
|
+
if (!(chainId == chainIdNow)) return [3 /*break*/, 3];
|
|
65
69
|
wallet.chainId = chainId;
|
|
66
70
|
return [2 /*return*/, true];
|
|
67
|
-
case
|
|
68
|
-
if (!(key < 4)) return [3 /*break*/,
|
|
71
|
+
case 3:
|
|
72
|
+
if (!(key < 4)) return [3 /*break*/, 5];
|
|
69
73
|
return [4 /*yield*/, isChainIdEq(wallet, chainId, utilsEht, key + 1)];
|
|
70
|
-
case
|
|
71
|
-
case
|
|
74
|
+
case 4: return [2 /*return*/, _a.sent()];
|
|
75
|
+
case 5: throw new Error('User rejected the request.');
|
|
72
76
|
}
|
|
73
77
|
});
|
|
74
78
|
});
|
|
@@ -9,8 +9,9 @@ declare class WalletConnect extends BaseWallet {
|
|
|
9
9
|
sdk: any;
|
|
10
10
|
infuraId?: string;
|
|
11
11
|
modal: AppKit;
|
|
12
|
-
|
|
12
|
+
modalIsClose: Boolean;
|
|
13
13
|
init(chainId?: number, config?: any): void;
|
|
14
|
+
getModalClose(): Boolean;
|
|
14
15
|
/**
|
|
15
16
|
* connect metamask and get wallet address
|
|
16
17
|
* @param chainId specific chainId,throw error when not match
|
|
@@ -73,7 +73,7 @@ var helper_2 = require("../helper");
|
|
|
73
73
|
var WalletConnect = /** @class */ (function (_super) {
|
|
74
74
|
__extends(WalletConnect, _super);
|
|
75
75
|
function WalletConnect() {
|
|
76
|
-
var _this = _super.
|
|
76
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
77
77
|
_this.name = types_1.EnumWalletName.WalletConnect;
|
|
78
78
|
_this.icon = walletconnect_svg_1.default;
|
|
79
79
|
_this.supportChains = [
|
|
@@ -121,6 +121,7 @@ var WalletConnect = /** @class */ (function (_super) {
|
|
|
121
121
|
return _this;
|
|
122
122
|
}
|
|
123
123
|
WalletConnect.prototype.init = function (chainId, config) {
|
|
124
|
+
var _this = this;
|
|
124
125
|
if (chainId === void 0) { chainId = 1; }
|
|
125
126
|
var projectId = config && config.projectId ? config.projectId : 'c1ca7adc83e89c7e7848440702f28f38'; // '90304d7fbed3543fd7cac4b24f800264'
|
|
126
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];
|
|
@@ -158,12 +159,31 @@ var WalletConnect = /** @class */ (function (_super) {
|
|
|
158
159
|
allWallets: 'HIDE',
|
|
159
160
|
});
|
|
160
161
|
this.modal.subscribeEvents(function (event) {
|
|
162
|
+
console.log('_____________________event_________________');
|
|
161
163
|
console.log(event.data);
|
|
164
|
+
console.log(event.data.event);
|
|
165
|
+
if (event.data.event == 'MODAL_OPEN') {
|
|
166
|
+
_this.modalIsClose = false;
|
|
167
|
+
}
|
|
168
|
+
if (event.data.event == "MODAL_CLOSE") {
|
|
169
|
+
_this.modalIsClose = true;
|
|
170
|
+
}
|
|
171
|
+
if (event.data.event == "CONNECT_ERROR") {
|
|
172
|
+
if (event.data.properties.message.indexOf('User rejected the request') != -1) {
|
|
173
|
+
_this.modal.close();
|
|
174
|
+
// this.modalIsClose = true
|
|
175
|
+
}
|
|
176
|
+
}
|
|
162
177
|
});
|
|
163
178
|
this.modal.subscribeWalletInfo(function (data) {
|
|
164
|
-
|
|
179
|
+
console.log('_____________________subscribeWalletInfo_________________');
|
|
180
|
+
console.log(data);
|
|
165
181
|
});
|
|
166
182
|
};
|
|
183
|
+
WalletConnect.prototype.getModalClose = function () {
|
|
184
|
+
var open = this.modal.getState().open;
|
|
185
|
+
return this.modalIsClose || !open;
|
|
186
|
+
};
|
|
167
187
|
/**
|
|
168
188
|
* connect metamask and get wallet address
|
|
169
189
|
* @param chainId specific chainId,throw error when not match
|
|
@@ -171,12 +191,14 @@ var WalletConnect = /** @class */ (function (_super) {
|
|
|
171
191
|
*/
|
|
172
192
|
WalletConnect.prototype.requestConnect = function () {
|
|
173
193
|
return __awaiter(this, arguments, void 0, function (chainId, config) {
|
|
174
|
-
var
|
|
194
|
+
var provider1_1, providerType, isConnected, currentChainId_1, chainId_1, address_1, address1, provider1, currentChainId, address;
|
|
175
195
|
var _this = this;
|
|
176
196
|
if (chainId === void 0) { chainId = 1; }
|
|
177
197
|
return __generator(this, function (_a) {
|
|
178
198
|
switch (_a.label) {
|
|
179
199
|
case 0:
|
|
200
|
+
this.modalIsClose = false;
|
|
201
|
+
console.log('requestConnect1111-----------------');
|
|
180
202
|
if (!!this.modal) return [3 /*break*/, 2];
|
|
181
203
|
this.init(chainId, config);
|
|
182
204
|
return [4 /*yield*/, (0, helper_2.sleep)(5000)];
|
|
@@ -185,54 +207,75 @@ var WalletConnect = /** @class */ (function (_super) {
|
|
|
185
207
|
_a.label = 2;
|
|
186
208
|
case 2:
|
|
187
209
|
if (!this.modal) return [3 /*break*/, 6];
|
|
188
|
-
|
|
210
|
+
console.log('requestConnect222-----------------');
|
|
211
|
+
provider1_1 = this.modal.getWalletProvider();
|
|
212
|
+
console.log(provider1_1);
|
|
213
|
+
providerType = this.modal.getWalletProviderType();
|
|
214
|
+
console.log('providerType', providerType);
|
|
189
215
|
isConnected = this.modal.getIsConnectedState();
|
|
190
|
-
|
|
191
|
-
|
|
216
|
+
console.log('requestConnect333-----------------');
|
|
217
|
+
if (!(provider1_1 && isConnected)) return [3 /*break*/, 6];
|
|
218
|
+
// let provider =await provider1.getProvider()
|
|
219
|
+
// console.log(provider)
|
|
220
|
+
console.log('requestConnect333322222-----------------');
|
|
221
|
+
// await provider.enable();
|
|
222
|
+
this.sdk = new web3_1.default(provider1_1);
|
|
192
223
|
return [4 /*yield*/, this.sdk.eth.getChainId()];
|
|
193
224
|
case 3:
|
|
194
225
|
currentChainId_1 = _a.sent();
|
|
195
|
-
|
|
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];
|
|
230
|
+
console.log('requestConnect555-----------------');
|
|
196
231
|
throw new Error(types_1.EnumErrors.ChainIdNotMath);
|
|
197
|
-
case 4:
|
|
232
|
+
case 4:
|
|
233
|
+
console.log('requestConnect666-----------------');
|
|
234
|
+
return [4 /*yield*/, this.sdk.eth.getAccounts()];
|
|
198
235
|
case 5:
|
|
199
236
|
address_1 = (_a.sent())[0];
|
|
200
|
-
|
|
237
|
+
address1 = this.modal.getAddress();
|
|
238
|
+
console.log(address_1, address1);
|
|
239
|
+
this.address = address_1 || address1;
|
|
201
240
|
this.chainId = currentChainId_1;
|
|
202
241
|
return [2 /*return*/, address_1];
|
|
203
|
-
case 6:
|
|
204
|
-
|
|
205
|
-
|
|
242
|
+
case 6:
|
|
243
|
+
console.log('requestConnect777-----------------');
|
|
244
|
+
return [4 /*yield*/, this.modal.open({
|
|
245
|
+
view: 'Connect' //'Account' | 'Connect' | 'Networks' | 'ApproveTransaction' | 'OnRampProviders';
|
|
246
|
+
})];
|
|
206
247
|
case 7:
|
|
207
248
|
_a.sent();
|
|
208
249
|
return [4 /*yield*/, (0, helper_1.autoWalletCheck)(function () {
|
|
209
|
-
|
|
210
|
-
var _a = _this.modal.getState(), open = _a.open, selectedNetworkId = _a.selectedNetworkId;
|
|
211
|
-
return !open;
|
|
250
|
+
return _this.getModalClose();
|
|
212
251
|
}, 1000 * 60 * 6, 60 * 3)];
|
|
213
252
|
case 8:
|
|
214
253
|
_a.sent();
|
|
215
|
-
|
|
216
|
-
|
|
254
|
+
console.log('autoWalletCheck-----------------');
|
|
255
|
+
provider1 = this.modal.getWalletProvider();
|
|
256
|
+
console.log(provider1);
|
|
257
|
+
if (!provider1) {
|
|
217
258
|
this.modal.close();
|
|
218
|
-
throw new Error('
|
|
259
|
+
throw new Error('User rejected the request.');
|
|
219
260
|
}
|
|
220
|
-
console.log('
|
|
221
|
-
|
|
261
|
+
console.log('autoWalletCheck22-----------------');
|
|
262
|
+
// let provider = await provider1.getProvider()
|
|
263
|
+
// console.log(provider)
|
|
264
|
+
this.sdk = new web3_1.default(provider1);
|
|
222
265
|
return [4 /*yield*/, this.sdk.eth.getChainId()];
|
|
223
266
|
case 9:
|
|
224
267
|
currentChainId = _a.sent();
|
|
225
|
-
console.log('
|
|
268
|
+
console.log('autoWalletCheck333-----------------');
|
|
226
269
|
if (chainId && currentChainId != chainId) {
|
|
227
270
|
throw new Error(types_1.EnumErrors.ChainIdNotMath);
|
|
228
271
|
}
|
|
229
|
-
console.log('
|
|
272
|
+
console.log('autoWalletCheck4444-----------------');
|
|
230
273
|
return [4 /*yield*/, this.sdk.eth.getAccounts()];
|
|
231
274
|
case 10:
|
|
232
275
|
address = (_a.sent())[0];
|
|
233
276
|
this.address = address;
|
|
234
277
|
this.chainId = currentChainId;
|
|
235
|
-
console.log('
|
|
278
|
+
console.log('address,currentChainId-----------------');
|
|
236
279
|
console.log(address, currentChainId);
|
|
237
280
|
return [2 /*return*/, address];
|
|
238
281
|
}
|