@openocean.finance/wallet 1.10.3 → 1.10.5
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
|
});
|
|
@@ -0,0 +1,17 @@
|
|
|
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;
|
|
@@ -0,0 +1,185 @@
|
|
|
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;
|
|
@@ -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
|
|
194
|
+
var provider1_1, providerType, isConnected, currentChainId_1, chainId_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) {
|
|
@@ -208,17 +208,25 @@ var WalletConnect = /** @class */ (function (_super) {
|
|
|
208
208
|
case 2:
|
|
209
209
|
if (!this.modal) return [3 /*break*/, 6];
|
|
210
210
|
console.log('requestConnect222-----------------');
|
|
211
|
-
|
|
211
|
+
provider1_1 = this.modal.getWalletProvider();
|
|
212
|
+
console.log(provider1_1);
|
|
213
|
+
providerType = this.modal.getWalletProviderType();
|
|
214
|
+
console.log('providerType', providerType);
|
|
212
215
|
isConnected = this.modal.getIsConnectedState();
|
|
213
216
|
console.log('requestConnect333-----------------');
|
|
214
|
-
if (!(
|
|
217
|
+
if (!(provider1_1 && isConnected && !this.disconnected)) return [3 /*break*/, 6];
|
|
218
|
+
// let provider =await provider1.getProvider()
|
|
219
|
+
// console.log(provider)
|
|
215
220
|
console.log('requestConnect333322222-----------------');
|
|
216
|
-
|
|
221
|
+
// await provider.enable();
|
|
222
|
+
this.sdk = new web3_1.default(provider1_1);
|
|
217
223
|
return [4 /*yield*/, this.sdk.eth.getChainId()];
|
|
218
224
|
case 3:
|
|
219
225
|
currentChainId_1 = _a.sent();
|
|
226
|
+
chainId_1 = this.modal.getChainId();
|
|
227
|
+
console.log(currentChainId_1, chainId_1);
|
|
220
228
|
console.log('requestConnect444-----------------');
|
|
221
|
-
if (!(
|
|
229
|
+
if (!(chainId_1 && currentChainId_1 != chainId_1)) return [3 /*break*/, 4];
|
|
222
230
|
console.log('requestConnect555-----------------');
|
|
223
231
|
throw new Error(types_1.EnumErrors.ChainIdNotMath);
|
|
224
232
|
case 4:
|
|
@@ -226,8 +234,11 @@ var WalletConnect = /** @class */ (function (_super) {
|
|
|
226
234
|
return [4 /*yield*/, this.sdk.eth.getAccounts()];
|
|
227
235
|
case 5:
|
|
228
236
|
address_1 = (_a.sent())[0];
|
|
229
|
-
|
|
237
|
+
address1 = this.modal.getAddress();
|
|
238
|
+
console.log(address_1, address1);
|
|
239
|
+
this.address = address_1 || address1;
|
|
230
240
|
this.chainId = currentChainId_1;
|
|
241
|
+
this.disconnected = false;
|
|
231
242
|
return [2 /*return*/, address_1];
|
|
232
243
|
case 6:
|
|
233
244
|
console.log('requestConnect777-----------------');
|
|
@@ -242,17 +253,21 @@ var WalletConnect = /** @class */ (function (_super) {
|
|
|
242
253
|
case 8:
|
|
243
254
|
_a.sent();
|
|
244
255
|
console.log('autoWalletCheck-----------------');
|
|
245
|
-
|
|
246
|
-
|
|
256
|
+
provider1 = this.modal.getWalletProvider();
|
|
257
|
+
console.log(provider1);
|
|
258
|
+
if (!provider1) {
|
|
247
259
|
this.modal.close();
|
|
248
260
|
throw new Error('User rejected the request.');
|
|
249
261
|
}
|
|
250
262
|
console.log('autoWalletCheck22-----------------');
|
|
251
|
-
|
|
263
|
+
// let provider = await provider1.getProvider()
|
|
264
|
+
// console.log(provider)
|
|
265
|
+
this.sdk = new web3_1.default(provider1);
|
|
252
266
|
return [4 /*yield*/, this.sdk.eth.getChainId()];
|
|
253
267
|
case 9:
|
|
254
268
|
currentChainId = _a.sent();
|
|
255
269
|
console.log('autoWalletCheck333-----------------');
|
|
270
|
+
this.disconnected = false;
|
|
256
271
|
if (chainId && currentChainId != chainId) {
|
|
257
272
|
throw new Error(types_1.EnumErrors.ChainIdNotMath);
|
|
258
273
|
}
|