@openocean.finance/openocean-sdk 0.1.49 → 0.1.52

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.
@@ -0,0 +1,229 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ 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;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.Approve = void 0;
43
+ var web3_1 = __importDefault(require("web3"));
44
+ var Approve = /** @class */ (function () {
45
+ function Approve(contract, wallet) {
46
+ this.errorCallback = function () { };
47
+ this.transactionHashCallback = function () { };
48
+ this.receiptCallback = function () { };
49
+ this.successCallback = function () { };
50
+ this.contract = contract;
51
+ this.wallet = wallet;
52
+ }
53
+ Approve.prototype.send = function (reqApproveVo, address) {
54
+ return __awaiter(this, void 0, void 0, function () {
55
+ var web3, data, safeTxHash, e_1, _a, gasAmount, error_1, json;
56
+ var _this = this;
57
+ return __generator(this, function (_b) {
58
+ switch (_b.label) {
59
+ case 0:
60
+ this.account = address;
61
+ this.key = 0;
62
+ this.contractAddress = reqApproveVo.contractAddress;
63
+ this.tokenAddress = reqApproveVo.tokenAddress;
64
+ if (!(this.wallet.key === "GnosisSafeWallet")) return [3 /*break*/, 5];
65
+ web3 = new web3_1.default();
66
+ data = web3.eth.abi.encodeFunctionCall({
67
+ "inputs": [
68
+ {
69
+ "name": "spender",
70
+ "type": "address"
71
+ },
72
+ {
73
+ "name": "value",
74
+ "type": "uint256"
75
+ }
76
+ ],
77
+ "name": "approve",
78
+ "type": "function"
79
+ }, [this.contractAddress, reqApproveVo.amount]);
80
+ console.log('data', this.contractAddress, reqApproveVo.amount, data);
81
+ _b.label = 1;
82
+ case 1:
83
+ _b.trys.push([1, 3, , 4]);
84
+ return [4 /*yield*/, this.wallet.sdk.txs.send({
85
+ txs: [
86
+ {
87
+ to: this.tokenAddress,
88
+ value: 0,
89
+ data: data
90
+ },
91
+ ],
92
+ })];
93
+ case 2:
94
+ safeTxHash = (_b.sent()).safeTxHash;
95
+ console.log('safeTxHash', safeTxHash);
96
+ setTimeout(function () {
97
+ console.log('successCallback');
98
+ _this.successCallback(1);
99
+ }, 3000);
100
+ return [3 /*break*/, 4];
101
+ case 3:
102
+ e_1 = _b.sent();
103
+ setTimeout(function () {
104
+ _this.errorCallback(e_1);
105
+ }, 500);
106
+ return [3 /*break*/, 4];
107
+ case 4: return [3 /*break*/, 12];
108
+ case 5:
109
+ if (!!reqApproveVo.amount) return [3 /*break*/, 7];
110
+ _a = reqApproveVo;
111
+ return [4 /*yield*/, this.contract.methods.totalSupply().call()];
112
+ case 6:
113
+ _a.amount = _b.sent();
114
+ _b.label = 7;
115
+ case 7:
116
+ this.amount = reqApproveVo.amount + '';
117
+ gasAmount = '80000';
118
+ _b.label = 8;
119
+ case 8:
120
+ _b.trys.push([8, 10, , 11]);
121
+ return [4 /*yield*/, this.contract.methods
122
+ .approve(this.contractAddress, this.amount)
123
+ .estimateGas({
124
+ from: this.account,
125
+ })];
126
+ case 9:
127
+ gasAmount = _b.sent();
128
+ return [3 /*break*/, 11];
129
+ case 10:
130
+ error_1 = _b.sent();
131
+ setTimeout(function () {
132
+ _this.errorCallback(error_1);
133
+ }, 500);
134
+ return [2 /*return*/];
135
+ case 11:
136
+ json = {
137
+ from: address,
138
+ // gas: gasAmount
139
+ };
140
+ if (reqApproveVo.gasPrice) {
141
+ json.gasPrice = reqApproveVo.gasPrice;
142
+ }
143
+ console.log('准备授权');
144
+ try {
145
+ this.contract.methods.approve(this.contractAddress, this.amount)
146
+ .send(json, function (err, data) {
147
+ if (err) {
148
+ console.log('回调1error');
149
+ }
150
+ else {
151
+ console.log('data1----');
152
+ }
153
+ })
154
+ .on('error', function (error) {
155
+ console.log('回调2error');
156
+ _this.errorCallback(error);
157
+ })
158
+ .on('transactionHash', function (transactionHash) {
159
+ console.log('hash----');
160
+ _this.transactionHashCallback(transactionHash);
161
+ })
162
+ .on('receipt', function (receipt) {
163
+ console.log('receipt1----');
164
+ _this.receiptCallback(receipt);
165
+ _this.getSuccess();
166
+ })
167
+ .then(function (receipt) {
168
+ console.log('receipt2----');
169
+ })
170
+ .catch(function (err) {
171
+ console.log('catch----' + err);
172
+ });
173
+ }
174
+ catch (error) {
175
+ console.log('catch-error----');
176
+ this.errorCallback(error);
177
+ }
178
+ _b.label = 12;
179
+ case 12: return [2 /*return*/];
180
+ }
181
+ });
182
+ });
183
+ };
184
+ Approve.prototype.on = function (events, callback) {
185
+ if (events === 'error') {
186
+ // alert('成功绑定回调方法')
187
+ this.errorCallback = callback;
188
+ }
189
+ else if (events === 'transactionHash') {
190
+ this.transactionHashCallback = callback;
191
+ }
192
+ else if (events === 'receipt') {
193
+ this.receiptCallback = callback;
194
+ }
195
+ else if (events === 'success') {
196
+ this.successCallback = callback;
197
+ }
198
+ return this;
199
+ };
200
+ Approve.prototype.getSuccess = function () {
201
+ return __awaiter(this, void 0, void 0, function () {
202
+ var balance;
203
+ var _this = this;
204
+ return __generator(this, function (_a) {
205
+ switch (_a.label) {
206
+ case 0: return [4 /*yield*/, this.contract.methods.allowance(this.account, this.contractAddress).call()];
207
+ case 1:
208
+ balance = _a.sent();
209
+ // const decimals = await this.contract.methods.decimals().call()
210
+ // Number(formatUnits(balance, decimals))
211
+ this.key++;
212
+ if (this.key > 20)
213
+ return [2 /*return*/];
214
+ if (balance >= Number(this.amount)) {
215
+ this.successCallback(balance);
216
+ }
217
+ else {
218
+ setTimeout(function () {
219
+ _this.getSuccess();
220
+ }, 2000);
221
+ }
222
+ return [2 /*return*/];
223
+ }
224
+ });
225
+ });
226
+ };
227
+ return Approve;
228
+ }());
229
+ exports.Approve = Approve;
@@ -0,0 +1,283 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ 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;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.ConnectWallet = void 0;
40
+ var Wallets_1 = require("../config/Wallets");
41
+ var utils_1 = require("../utils");
42
+ var web3_js_1 = require("@solana/web3.js");
43
+ var Chains_1 = require("../config/Chains");
44
+ var NotoMobile_1 = require("./NotoMobile");
45
+ var axios = require('axios');
46
+ var ConnectWallet = /** @class */ (function () {
47
+ function ConnectWallet() {
48
+ }
49
+ ConnectWallet.isChainIdEq = function (wallet, chainId, utilsEht, k) {
50
+ return __awaiter(this, void 0, void 0, function () {
51
+ var key, chainIdNow;
52
+ return __generator(this, function (_a) {
53
+ switch (_a.label) {
54
+ case 0:
55
+ key = k || 0;
56
+ return [4 /*yield*/, utils_1.utils.sleep(1000)];
57
+ case 1:
58
+ _a.sent();
59
+ chainIdNow = utilsEht.hexToNumber(wallet.sdk.currentProvider.chainId);
60
+ if (!(chainId == chainIdNow)) return [3 /*break*/, 2];
61
+ wallet.chainId = chainId;
62
+ return [2 /*return*/, true];
63
+ case 2:
64
+ if (!(key < 10)) return [3 /*break*/, 4];
65
+ return [4 /*yield*/, this.isChainIdEq(wallet, chainId, utilsEht, key + 1)];
66
+ case 3:
67
+ // console.log('获取chainId是否改变')
68
+ return [2 /*return*/, _a.sent()];
69
+ case 4: throw new Error('Link error.');
70
+ }
71
+ });
72
+ });
73
+ };
74
+ ConnectWallet.link = function (reqConnectWalletVo) {
75
+ return __awaiter(this, void 0, void 0, function () {
76
+ var wallet, chain, chainId, selectedChain, qrData, instance_1, account, res, res, account, res, res, _a, e_1, message, _b, currentProvider, utilsEht;
77
+ return __generator(this, function (_c) {
78
+ switch (_c.label) {
79
+ case 0:
80
+ wallet = Wallets_1.wallets.walletObj[reqConnectWalletVo.walletName];
81
+ if (!wallet)
82
+ wallet = Wallets_1.wallets.walletList.find(function (item) { return item.name == reqConnectWalletVo.walletName; });
83
+ chain = Chains_1.chains.chainObj[reqConnectWalletVo.chain];
84
+ if (!chain)
85
+ throw new Error('Chain error.');
86
+ chainId = chain.chainId;
87
+ selectedChain = chain.key;
88
+ _c.label = 1;
89
+ case 1:
90
+ _c.trys.push([1, 23, , 27]);
91
+ if (!(wallet.type === 'WalletConnect')) return [3 /*break*/, 3];
92
+ wallet.infuraId = '2c7c4d86c2c746c89de722551b606119';
93
+ return [4 /*yield*/, wallet.requestConnect(chainId)
94
+ // this.connect(wallet);
95
+ ];
96
+ case 2:
97
+ _c.sent();
98
+ return [3 /*break*/, 22];
99
+ case 3:
100
+ if (!(wallet.key === 'OntoMobile')) return [3 /*break*/, 6];
101
+ return [4 /*yield*/, axios.get('https://ethapi.openocean.finance/v1/ont/login')];
102
+ case 4:
103
+ qrData = _c.sent();
104
+ wallet.qrData = qrData.data;
105
+ instance_1 = new NotoMobile_1.NotoMobile(qrData.data);
106
+ return [4 /*yield*/, new Promise(function (r, q) {
107
+ instance_1.$on('close', function (result, action, account) {
108
+ if (action === 'login' && result === 'success') {
109
+ r(account);
110
+ }
111
+ else {
112
+ q(action);
113
+ }
114
+ });
115
+ })];
116
+ case 5:
117
+ account = _c.sent();
118
+ wallet.address = account;
119
+ return [3 /*break*/, 22];
120
+ case 6:
121
+ if (!(selectedChain === 'terra')) return [3 /*break*/, 9];
122
+ if (!!wallet.sdk) return [3 /*break*/, 8];
123
+ return [4 /*yield*/, wallet.requestTerraConnect()];
124
+ case 7:
125
+ res = _c.sent();
126
+ if (res) {
127
+ // this.connect(wallet);
128
+ }
129
+ else {
130
+ // const message = {
131
+ // 'XDEFI Wallet': 'wallet_message_40018',
132
+ // 'Terra Station': 'wallet_message_40015'
133
+ // }[wallet.name];
134
+ // showToast(this.$t(message));
135
+ }
136
+ _c.label = 8;
137
+ case 8: return [3 /*break*/, 22];
138
+ case 9:
139
+ if (!(selectedChain === "solana")) return [3 /*break*/, 11];
140
+ return [4 /*yield*/, wallet.requestSolanaConnect()];
141
+ case 10:
142
+ res = _c.sent();
143
+ wallet.customPublicKey = new web3_js_1.PublicKey(res);
144
+ // "https://api.mainnet-beta.solana.com"
145
+ // "https://solana-mainnet.phantom.tech"
146
+ // "https://rpc.ankr.com/solana"
147
+ // https://solana-api.projectserum.com
148
+ // https://mercuria-fronten-1cd8.mainnet.rpcpool.com/
149
+ wallet.connection = new web3_js_1.Connection("https://solana-api.projectserum.com");
150
+ if (res) {
151
+ // this.connect(wallet);
152
+ }
153
+ else {
154
+ // const message = {
155
+ // 'Sollet': 'wallet_message_40010',
156
+ // 'Coin98 Wallet': 'wallet_message_40011',
157
+ // 'Phantom': 'wallet_message_40013',
158
+ // 'Clover Wallet': 'wallet_message_40017',
159
+ // 'Slope Wallet': 'wallet_message_40019',
160
+ // 'Solflare Wallet': 'wallet_message_40020',
161
+ // };
162
+ // return {
163
+ // code: 401,
164
+ // message: message
165
+ // }
166
+ }
167
+ return [3 /*break*/, 22];
168
+ case 11:
169
+ if (!(selectedChain === 'tron')) return [3 /*break*/, 16];
170
+ account = window.tronWeb.defaultAddress.base58;
171
+ if (!!account) return [3 /*break*/, 14];
172
+ return [4 /*yield*/, utils_1.utils.sleep(1000)];
173
+ case 12:
174
+ _c.sent();
175
+ return [4 /*yield*/, this.link(reqConnectWalletVo)];
176
+ case 13: return [2 /*return*/, _c.sent()];
177
+ case 14: return [4 /*yield*/, wallet.requestConnect()];
178
+ case 15:
179
+ res = _c.sent();
180
+ console.log('wallet.requestConnect', res, wallet);
181
+ return [3 /*break*/, 22];
182
+ case 16:
183
+ if (!chainId) return [3 /*break*/, 18];
184
+ return [4 /*yield*/, wallet.requestConnect(chainId)];
185
+ case 17:
186
+ _a = _c.sent();
187
+ return [3 /*break*/, 20];
188
+ case 18: return [4 /*yield*/, wallet.requestConnect()];
189
+ case 19:
190
+ _a = _c.sent();
191
+ _c.label = 20;
192
+ case 20:
193
+ res = _a;
194
+ console.log('wallet.requestConnect', res, wallet);
195
+ return [4 /*yield*/, utils_1.utils.sleep(200)];
196
+ case 21:
197
+ _c.sent();
198
+ if (res) {
199
+ // this.connect(wallet);
200
+ }
201
+ _c.label = 22;
202
+ case 22: return [2 /*return*/, { chain: chain, wallet: wallet }];
203
+ case 23:
204
+ e_1 = _c.sent();
205
+ message = e_1.message;
206
+ _b = wallet.sdk || {}, currentProvider = _b.currentProvider, utilsEht = _b.utils;
207
+ if (!(message === "40006" && currentProvider)) return [3 /*break*/, 25];
208
+ return [4 /*yield*/, this.linkAddOrSwitch(reqConnectWalletVo, wallet, chain)];
209
+ case 24: return [2 /*return*/, _c.sent()];
210
+ case 25: throw new Error(/^\d+$/.test(message) ? "wallet_message_" + message : message);
211
+ case 26: return [3 /*break*/, 27];
212
+ case 27: return [2 /*return*/];
213
+ }
214
+ });
215
+ });
216
+ };
217
+ ConnectWallet.linkAddOrSwitch = function (reqConnectWalletVo, wallet, chain) {
218
+ return __awaiter(this, void 0, void 0, function () {
219
+ var _a, currentProvider, utilsEht, chainId, params, address, address, address, address;
220
+ return __generator(this, function (_b) {
221
+ switch (_b.label) {
222
+ case 0:
223
+ _a = wallet.sdk || {}, currentProvider = _a.currentProvider, utilsEht = _a.utils;
224
+ chainId = chain.chainId;
225
+ params = Chains_1.chains.ethereumChainParams[reqConnectWalletVo.chain];
226
+ if (!params) return [3 /*break*/, 8];
227
+ return [4 /*yield*/, currentProvider.request({
228
+ method: "wallet_addEthereumChain",
229
+ params: params
230
+ })];
231
+ case 1:
232
+ _b.sent();
233
+ return [4 /*yield*/, this.isChainIdEq(wallet, chainId, utilsEht)];
234
+ case 2:
235
+ if (!_b.sent()) return [3 /*break*/, 7];
236
+ if (!(wallet.type === 'WalletConnect')) return [3 /*break*/, 4];
237
+ return [4 /*yield*/, wallet.sdk.eth.getAccounts()];
238
+ case 3:
239
+ address = (_b.sent())[0];
240
+ wallet.address = address;
241
+ return [3 /*break*/, 6];
242
+ case 4: return [4 /*yield*/, wallet.sdk.eth.requestAccounts()];
243
+ case 5:
244
+ address = (_b.sent())[0];
245
+ wallet.address = address;
246
+ _b.label = 6;
247
+ case 6: return [2 /*return*/, { chain: chain, wallet: wallet }];
248
+ case 7: return [3 /*break*/, 17];
249
+ case 8:
250
+ if (!(chainId == '1' || chainId == '3' || chainId == '4')) return [3 /*break*/, 16];
251
+ return [4 /*yield*/, currentProvider.request({
252
+ method: 'wallet_switchEthereumChain',
253
+ params: [{
254
+ chainId: utilsEht.toHex(chainId)
255
+ }],
256
+ })];
257
+ case 9:
258
+ _b.sent();
259
+ return [4 /*yield*/, this.isChainIdEq(wallet, chainId, utilsEht)];
260
+ case 10:
261
+ if (!_b.sent()) return [3 /*break*/, 15];
262
+ if (!(wallet.type === 'WalletConnect')) return [3 /*break*/, 12];
263
+ return [4 /*yield*/, wallet.sdk.eth.getAccounts()];
264
+ case 11:
265
+ address = (_b.sent())[0];
266
+ wallet.address = address;
267
+ return [3 /*break*/, 14];
268
+ case 12: return [4 /*yield*/, wallet.sdk.eth.requestAccounts()];
269
+ case 13:
270
+ address = (_b.sent())[0];
271
+ wallet.address = address;
272
+ _b.label = 14;
273
+ case 14: return [2 /*return*/, { chain: chain, wallet: wallet }];
274
+ case 15: return [3 /*break*/, 17];
275
+ case 16: throw new Error('Network error');
276
+ case 17: return [2 /*return*/];
277
+ }
278
+ });
279
+ });
280
+ };
281
+ return ConnectWallet;
282
+ }());
283
+ exports.ConnectWallet = ConnectWallet;
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NotoMobile = void 0;
4
+ var QRCode = require("./qrcode").QRCode;
5
+ // import { QRCode } from "./qrcode";
6
+ var axios = require('axios');
7
+ var NotoMobile = /** @class */ (function () {
8
+ function NotoMobile(qrData) {
9
+ this.time = 0;
10
+ var id = qrData.id, qrCode = qrData.qrCode;
11
+ this.id = id;
12
+ this.qrCode = JSON.stringify(qrCode);
13
+ this.setCloseStyle();
14
+ this.show();
15
+ }
16
+ NotoMobile.prototype.$on = function (key, callBack) {
17
+ if (key == 'close')
18
+ this.close = callBack;
19
+ };
20
+ NotoMobile.prototype.loop = function () {
21
+ var _this = this;
22
+ axios.get('https://ethapi.openocean.finance/v1/ont/qrcode/result/' + this.id).then(function (res) {
23
+ var _a = res.data, action = _a.action, state = _a.state, account = _a.account;
24
+ if (state === '0') {
25
+ _this.close('success', action, account);
26
+ _this.cancel();
27
+ }
28
+ // else if (state === '1') {
29
+ // this.close('error', action, account)
30
+ // this.cancel()
31
+ // }
32
+ else {
33
+ _this.time++;
34
+ if (_this.time > 120) {
35
+ _this.close('error', 'over time');
36
+ _this.cancel();
37
+ return;
38
+ }
39
+ _this.outTime = setTimeout(function () {
40
+ _this.loop();
41
+ }, 1000);
42
+ }
43
+ }).catch(function (e) {
44
+ console.log(e);
45
+ _this.close('error', e);
46
+ _this.cancel();
47
+ });
48
+ };
49
+ NotoMobile.prototype.setCloseStyle = function () {
50
+ var k = document.getElementById('qrcodeStyle09');
51
+ if (k)
52
+ return;
53
+ var style = document.createElement('style');
54
+ style.type = "text/css";
55
+ style.id = 'qrcodeStyle09';
56
+ document.head.appendChild(style);
57
+ style.innerHTML = "\n #qrcodeBox div,#qrcodeBox span{box-sizing: border-box;}\n #qrcodeBox #close8 :hover{cursor:pointer;opacity:0.5;}\n #qrcodeBox #close8 >div:before,#qrcodeBox #close8 >div:after{\n content: '';position: absolute;height: 2px;width: 100%;top: 50%;left: 0;margin-top: -1px;background: #000;border-radius:5px;\n }\n #qrcodeBox #close8 >div:before{transform: rotate(45deg);}\n #qrcodeBox #close8 >div:after{transform: rotate(-45deg);}\n #qrcodeBox #qrcode img{ display:inline-block;}\n ";
58
+ };
59
+ NotoMobile.prototype.createQrcode = function (w) {
60
+ var _this = this;
61
+ if (!document.getElementById("qrcode")) {
62
+ setTimeout(function () {
63
+ _this.createQrcode(w);
64
+ }, 100);
65
+ }
66
+ var qrcode = new QRCode(document.getElementById("qrcode"), {
67
+ text: this.qrCode,
68
+ width: w,
69
+ height: w,
70
+ colorDark: "#000000",
71
+ colorLight: "#ffffff",
72
+ correctLevel: QRCode.CorrectLevel.H
73
+ });
74
+ this.loop();
75
+ };
76
+ NotoMobile.prototype.show = function () {
77
+ var _this = this;
78
+ // 获取整个页面的宽和高
79
+ var page_width = document.documentElement.scrollWidth;
80
+ var page_height = document.documentElement.scrollHeight;
81
+ // 获取浏览器的宽和高
82
+ var b_width = document.documentElement.clientWidth;
83
+ var b_height = document.documentElement.clientHeight;
84
+ this.mask = document.createElement("div");
85
+ this.mask.id = "mask";
86
+ this.mask.style.width = page_width + "px";
87
+ this.mask.style.height = page_height + "px";
88
+ this.mask.style.position = 'absolute';
89
+ this.mask.style.background = 'rgba(37,41,46,.95)';
90
+ this.mask.style.zIndex = '999';
91
+ this.mask.style.top = '0';
92
+ this.mask.style.left = '0';
93
+ document.body.appendChild(this.mask);
94
+ var width = 0;
95
+ var height = 0;
96
+ var headHeight = 60;
97
+ var headHeight1 = 50;
98
+ var qrcodeWidth = 0;
99
+ var padding = 50;
100
+ // pc
101
+ if (b_width > b_height) {
102
+ height = b_height;
103
+ width = b_height - headHeight1 - headHeight - headHeight / 2;
104
+ qrcodeWidth = width - padding * 2;
105
+ }
106
+ else {
107
+ // phone
108
+ padding = 30;
109
+ headHeight = 50;
110
+ headHeight1 = 50;
111
+ width = b_width - 60;
112
+ height = width + headHeight1 + headHeight + headHeight / 2;
113
+ qrcodeWidth = width - padding * 2;
114
+ }
115
+ this.qrcodeBox = document.createElement("div");
116
+ this.qrcodeBox.id = "qrcodeBox";
117
+ this.qrcodeBox.style.left = (b_width - width) / 2 + "px";
118
+ this.qrcodeBox.style.top = (b_height - height) / 2 + "px";
119
+ this.qrcodeBox.style.height = height + "px";
120
+ this.qrcodeBox.style.width = width + "px";
121
+ this.qrcodeBox.style.position = 'absolute';
122
+ this.qrcodeBox.style.zIndex = '10000';
123
+ // qrcodeBox.style.padding = '0 30px 0 30px'
124
+ this.qrcodeBox.innerHTML =
125
+ "<div style=\"font-size: 22px;height:100%;padding-top:".concat(headHeight, "px;padding-bottom:").concat(headHeight / 2, "px;position:relative;\">\n <div style=\"color:#ffffff;line-height: ").concat(headHeight, "px;position:absolute;top:0;left:0;width:100%\">\n <img style=\"vertical-align: middle; width: 30px;height:30px\" src=\"https://cloudstorage.openocean.finance/openocean/img/icon-onto-white.b4f61a37.svg\"/>\n <span style=\"vertical-align: middle;\">Onto Mobile</span>\n <div id=\"close8\" style=\"margin-top: 20px;position: relative;float: right;background: #fff;border-radius: 100px;width:25px;height:25px;padding:5px;display: inline-block;\">\n <div style=\"position: relative;width:100%;height:100%;display: block;\"></div>\n </div>\n </div>\n <div id=\"qrcodeb\" style=\"padding-top:").concat(headHeight1, "px;position:relative;height:100%;width:100%;background:#fff;text-align: center;\">\n <div style=\"position:absolute;top:0;left:0;width:100%;font-size:").concat(width > 400 ? 18 : 14, "px;color:rgba(60,66,82,.6);line-height: ").concat(headHeight1 + padding, "px;\">Scan QR code with a Onto wallet</div>\n <div style=\"display: flex;justify-content: center;align-items: center;height:100%;height:100%;\">\n <div id=\"qrcode\"></div>\n </div>\n </div>\n </div>\n ");
126
+ document.body.appendChild(this.qrcodeBox);
127
+ var qrcodeb = document.getElementById("qrcodeb");
128
+ qrcodeb.style.borderRadius = "20px";
129
+ qrcodeb.style.boxSizing = 'border-box';
130
+ this.createQrcode(qrcodeWidth);
131
+ var close = window.document.getElementById("close8");
132
+ close.onclick = function () {
133
+ _this.cancel();
134
+ };
135
+ this.mask.onclick = function () {
136
+ _this.cancel();
137
+ };
138
+ };
139
+ NotoMobile.prototype.cancel = function () {
140
+ this.time = 0;
141
+ this.outTime ? clearTimeout(this.outTime) : '';
142
+ document.body.removeChild(this.mask);
143
+ document.body.removeChild(this.qrcodeBox);
144
+ };
145
+ return NotoMobile;
146
+ }());
147
+ exports.NotoMobile = NotoMobile;