@openocean.finance/openocean-sdk 0.1.66 → 0.1.67

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,227 @@
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, _b, gasAmount, error_1, json;
56
+ var _this = this;
57
+ return __generator(this, function (_c) {
58
+ switch (_c.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
+ _c.label = 1;
82
+ case 1:
83
+ _c.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 = (_c.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 = _c.sent();
103
+ setTimeout(function () {
104
+ _this.errorCallback(e_1);
105
+ }, 500);
106
+ return [3 /*break*/, 4];
107
+ case 4: return [3 /*break*/, 14];
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 = _c.sent();
114
+ _c.label = 7;
115
+ case 7:
116
+ if (!(this.tokenAddress === "0xfa17b330bcc4e7f3e2456996d89a5a54ab044831")) return [3 /*break*/, 9];
117
+ _b = reqApproveVo;
118
+ return [4 /*yield*/, this.contract.methods.balanceOf(this.account).call()];
119
+ case 8:
120
+ _b.amount = _c.sent();
121
+ if (Number(reqApproveVo.amount) == 0) {
122
+ this.errorCallback('Insufficient Balance.');
123
+ return [2 /*return*/];
124
+ }
125
+ _c.label = 9;
126
+ case 9:
127
+ this.amount = reqApproveVo.amount + '';
128
+ gasAmount = '80000';
129
+ _c.label = 10;
130
+ case 10:
131
+ _c.trys.push([10, 12, , 13]);
132
+ return [4 /*yield*/, this.contract.methods
133
+ .approve(this.contractAddress, this.amount)
134
+ .estimateGas({
135
+ from: this.account,
136
+ })];
137
+ case 11:
138
+ gasAmount = _c.sent();
139
+ return [3 /*break*/, 13];
140
+ case 12:
141
+ error_1 = _c.sent();
142
+ setTimeout(function () {
143
+ _this.errorCallback(error_1);
144
+ }, 500);
145
+ return [2 /*return*/];
146
+ case 13:
147
+ json = {
148
+ from: address,
149
+ };
150
+ if (reqApproveVo.gasPrice) {
151
+ json.gasPrice = reqApproveVo.gasPrice;
152
+ }
153
+ try {
154
+ this.contract.methods.approve(this.contractAddress, this.amount)
155
+ .send(json, function (err, data) {
156
+ if (err) {
157
+ }
158
+ else {
159
+ }
160
+ })
161
+ .on('error', function (error) {
162
+ _this.errorCallback(error);
163
+ })
164
+ .on('transactionHash', function (transactionHash) {
165
+ _this.transactionHashCallback(transactionHash);
166
+ })
167
+ .on('receipt', function (receipt) {
168
+ _this.receiptCallback(receipt);
169
+ _this.getSuccess();
170
+ })
171
+ .then(function (receipt) {
172
+ })
173
+ .catch(function (err) {
174
+ });
175
+ }
176
+ catch (error) {
177
+ this.errorCallback(error);
178
+ }
179
+ _c.label = 14;
180
+ case 14: return [2 /*return*/];
181
+ }
182
+ });
183
+ });
184
+ };
185
+ Approve.prototype.on = function (events, callback) {
186
+ if (events === 'error') {
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
+ this.key++;
210
+ if (this.key > 20)
211
+ return [2 /*return*/];
212
+ if (balance >= Number(this.amount)) {
213
+ this.successCallback(balance);
214
+ }
215
+ else {
216
+ setTimeout(function () {
217
+ _this.getSuccess();
218
+ }, 2000);
219
+ }
220
+ return [2 /*return*/];
221
+ }
222
+ });
223
+ });
224
+ };
225
+ return Approve;
226
+ }());
227
+ exports.Approve = Approve;
@@ -0,0 +1,282 @@
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 < 3)) return [3 /*break*/, 4];
65
+ return [4 /*yield*/, this.isChainIdEq(wallet, chainId, utilsEht, key + 1)];
66
+ case 3: return [2 /*return*/, _a.sent()];
67
+ case 4: throw new Error('User rejected the request.');
68
+ }
69
+ });
70
+ });
71
+ };
72
+ ConnectWallet.link = function (reqConnectWalletVo) {
73
+ return __awaiter(this, void 0, void 0, function () {
74
+ var wallet, chain, chainId, selectedChain, qrData, instance_1, account, res, res, account, res, res, _a, e_1, message, _b, currentProvider, utilsEht;
75
+ return __generator(this, function (_c) {
76
+ switch (_c.label) {
77
+ case 0:
78
+ wallet = Wallets_1.wallets.walletObj[reqConnectWalletVo.walletName];
79
+ if (!wallet)
80
+ wallet = Wallets_1.wallets.walletList.find(function (item) { return item.name == reqConnectWalletVo.walletName; });
81
+ chain = Chains_1.chains.chainObj[reqConnectWalletVo.chain];
82
+ if (!chain)
83
+ throw new Error('Chain error.');
84
+ chainId = chain.chainId;
85
+ selectedChain = chain.key;
86
+ _c.label = 1;
87
+ case 1:
88
+ _c.trys.push([1, 23, , 27]);
89
+ if (!(wallet.type === 'WalletConnect')) return [3 /*break*/, 3];
90
+ wallet.infuraId = '2c7c4d86c2c746c89de722551b606119';
91
+ return [4 /*yield*/, wallet.requestConnect(chainId)];
92
+ case 2:
93
+ _c.sent();
94
+ return [3 /*break*/, 22];
95
+ case 3:
96
+ if (!(wallet.key === 'OntoMobile')) return [3 /*break*/, 6];
97
+ return [4 /*yield*/, axios.get('https://ethapi.openocean.finance/v1/ont/login')];
98
+ case 4:
99
+ qrData = _c.sent();
100
+ wallet.qrData = qrData.data;
101
+ instance_1 = new NotoMobile_1.NotoMobile(qrData.data);
102
+ return [4 /*yield*/, new Promise(function (r, q) {
103
+ instance_1.$on('close', function (result, action, account) {
104
+ if (action === 'login' && result === 'success') {
105
+ r(account);
106
+ }
107
+ else {
108
+ q(action);
109
+ }
110
+ });
111
+ })];
112
+ case 5:
113
+ account = _c.sent();
114
+ wallet.address = account;
115
+ return [3 /*break*/, 22];
116
+ case 6:
117
+ if (!(selectedChain === 'terra')) return [3 /*break*/, 9];
118
+ if (!!wallet.sdk) return [3 /*break*/, 8];
119
+ return [4 /*yield*/, wallet.requestTerraConnect()];
120
+ case 7:
121
+ res = _c.sent();
122
+ if (res) {
123
+ // this.connect(wallet);
124
+ }
125
+ else {
126
+ // const message = {
127
+ // 'XDEFI Wallet': 'wallet_message_40018',
128
+ // 'Terra Station': 'wallet_message_40015'
129
+ // }[wallet.name];
130
+ // showToast(this.$t(message));
131
+ }
132
+ _c.label = 8;
133
+ case 8: return [3 /*break*/, 22];
134
+ case 9:
135
+ if (!(selectedChain === "solana")) return [3 /*break*/, 11];
136
+ return [4 /*yield*/, wallet.requestSolanaConnect()];
137
+ case 10:
138
+ res = _c.sent();
139
+ wallet.customPublicKey = new web3_js_1.PublicKey(res);
140
+ // "https://api.mainnet-beta.solana.com"
141
+ // "https://solana-mainnet.phantom.tech"
142
+ // "https://rpc.ankr.com/solana"
143
+ // https://solana-api.projectserum.com
144
+ // https://mercuria-fronten-1cd8.mainnet.rpcpool.com/
145
+ wallet.connection = new web3_js_1.Connection("https://solana-api.projectserum.com");
146
+ if (res) {
147
+ // this.connect(wallet);
148
+ }
149
+ else {
150
+ // const message = {
151
+ // 'Sollet': 'wallet_message_40010',
152
+ // 'Coin98 Wallet': 'wallet_message_40011',
153
+ // 'Phantom': 'wallet_message_40013',
154
+ // 'Clover Wallet': 'wallet_message_40017',
155
+ // 'Slope Wallet': 'wallet_message_40019',
156
+ // 'Solflare Wallet': 'wallet_message_40020',
157
+ // };
158
+ // return {
159
+ // code: 401,
160
+ // message: message
161
+ // }
162
+ }
163
+ return [3 /*break*/, 22];
164
+ case 11:
165
+ if (!(selectedChain === 'tron')) return [3 /*break*/, 16];
166
+ account = window.tronWeb.defaultAddress.base58;
167
+ if (!!account) return [3 /*break*/, 14];
168
+ return [4 /*yield*/, utils_1.utils.sleep(1000)];
169
+ case 12:
170
+ _c.sent();
171
+ return [4 /*yield*/, this.link(reqConnectWalletVo)];
172
+ case 13: return [2 /*return*/, _c.sent()];
173
+ case 14: return [4 /*yield*/, wallet.requestConnect()];
174
+ case 15:
175
+ res = _c.sent();
176
+ console.log('wallet.requestConnect', res, wallet);
177
+ return [3 /*break*/, 22];
178
+ case 16:
179
+ if (!chainId) return [3 /*break*/, 18];
180
+ return [4 /*yield*/, wallet.requestConnect(chainId)];
181
+ case 17:
182
+ _a = _c.sent();
183
+ return [3 /*break*/, 20];
184
+ case 18: return [4 /*yield*/, wallet.requestConnect()];
185
+ case 19:
186
+ _a = _c.sent();
187
+ _c.label = 20;
188
+ case 20:
189
+ res = _a;
190
+ console.log('wallet.requestConnect', res, wallet);
191
+ return [4 /*yield*/, utils_1.utils.sleep(200)];
192
+ case 21:
193
+ _c.sent();
194
+ if (res) {
195
+ // this.connect(wallet);
196
+ }
197
+ _c.label = 22;
198
+ case 22: return [2 /*return*/, { chain: chain, wallet: wallet }];
199
+ case 23:
200
+ e_1 = _c.sent();
201
+ message = e_1.message;
202
+ _b = wallet.sdk || {}, currentProvider = _b.currentProvider, utilsEht = _b.utils;
203
+ if (reqConnectWalletVo.noSwitch) {
204
+ throw new Error('No Switch');
205
+ }
206
+ if (!(message === "40006" && currentProvider)) return [3 /*break*/, 25];
207
+ return [4 /*yield*/, this.linkAddOrSwitch(reqConnectWalletVo, wallet, chain)];
208
+ case 24: return [2 /*return*/, _c.sent()];
209
+ case 25: throw new Error(message);
210
+ case 26: return [3 /*break*/, 27];
211
+ case 27: return [2 /*return*/];
212
+ }
213
+ });
214
+ });
215
+ };
216
+ ConnectWallet.linkAddOrSwitch = function (reqConnectWalletVo, wallet, chain) {
217
+ return __awaiter(this, void 0, void 0, function () {
218
+ var _a, currentProvider, utilsEht, chainId, params, address, address, address, address;
219
+ return __generator(this, function (_b) {
220
+ switch (_b.label) {
221
+ case 0:
222
+ _a = wallet.sdk || {}, currentProvider = _a.currentProvider, utilsEht = _a.utils;
223
+ chainId = chain.chainId;
224
+ params = Chains_1.chains.ethereumChainParams[reqConnectWalletVo.chain];
225
+ if (!params) return [3 /*break*/, 8];
226
+ return [4 /*yield*/, currentProvider.request({
227
+ method: "wallet_addEthereumChain",
228
+ params: params
229
+ })];
230
+ case 1:
231
+ _b.sent();
232
+ return [4 /*yield*/, this.isChainIdEq(wallet, chainId, utilsEht)];
233
+ case 2:
234
+ if (!_b.sent()) return [3 /*break*/, 7];
235
+ if (!(wallet.type === 'WalletConnect')) return [3 /*break*/, 4];
236
+ return [4 /*yield*/, wallet.sdk.eth.getAccounts()];
237
+ case 3:
238
+ address = (_b.sent())[0];
239
+ wallet.address = address;
240
+ return [3 /*break*/, 6];
241
+ case 4: return [4 /*yield*/, wallet.sdk.eth.requestAccounts()];
242
+ case 5:
243
+ address = (_b.sent())[0];
244
+ wallet.address = address;
245
+ _b.label = 6;
246
+ case 6: return [2 /*return*/, { chain: chain, wallet: wallet }];
247
+ case 7: return [3 /*break*/, 17];
248
+ case 8:
249
+ if (!(chainId == '1' || chainId == '3' || chainId == '4')) return [3 /*break*/, 16];
250
+ return [4 /*yield*/, currentProvider.request({
251
+ method: 'wallet_switchEthereumChain',
252
+ params: [{
253
+ chainId: utilsEht.toHex(chainId)
254
+ }],
255
+ })];
256
+ case 9:
257
+ _b.sent();
258
+ return [4 /*yield*/, this.isChainIdEq(wallet, chainId, utilsEht)];
259
+ case 10:
260
+ if (!_b.sent()) return [3 /*break*/, 15];
261
+ if (!(wallet.type === 'WalletConnect')) return [3 /*break*/, 12];
262
+ return [4 /*yield*/, wallet.sdk.eth.getAccounts()];
263
+ case 11:
264
+ address = (_b.sent())[0];
265
+ wallet.address = address;
266
+ return [3 /*break*/, 14];
267
+ case 12: return [4 /*yield*/, wallet.sdk.eth.requestAccounts()];
268
+ case 13:
269
+ address = (_b.sent())[0];
270
+ wallet.address = address;
271
+ _b.label = 14;
272
+ case 14: return [2 /*return*/, { chain: chain, wallet: wallet }];
273
+ case 15: return [3 /*break*/, 17];
274
+ case 16: throw new Error('Network error');
275
+ case 17: return [2 /*return*/];
276
+ }
277
+ });
278
+ });
279
+ };
280
+ return ConnectWallet;
281
+ }());
282
+ exports.ConnectWallet = ConnectWallet;
@@ -0,0 +1,141 @@
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 {
29
+ _this.time++;
30
+ if (_this.time > 120) {
31
+ _this.close('error', 'over time');
32
+ _this.cancel();
33
+ return;
34
+ }
35
+ _this.outTime = setTimeout(function () {
36
+ _this.loop();
37
+ }, 1000);
38
+ }
39
+ }).catch(function (e) {
40
+ console.log(e);
41
+ _this.close('error', e);
42
+ _this.cancel();
43
+ });
44
+ };
45
+ NotoMobile.prototype.setCloseStyle = function () {
46
+ var k = document.getElementById('qrcodeStyle09');
47
+ if (k)
48
+ return;
49
+ var style = document.createElement('style');
50
+ style.type = "text/css";
51
+ style.id = 'qrcodeStyle09';
52
+ document.head.appendChild(style);
53
+ 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 ";
54
+ };
55
+ NotoMobile.prototype.createQrcode = function (w) {
56
+ var _this = this;
57
+ if (!document.getElementById("qrcode")) {
58
+ setTimeout(function () {
59
+ _this.createQrcode(w);
60
+ }, 100);
61
+ }
62
+ var qrcode = new QRCode(document.getElementById("qrcode"), {
63
+ text: this.qrCode,
64
+ width: w,
65
+ height: w,
66
+ colorDark: "#000000",
67
+ colorLight: "#ffffff",
68
+ correctLevel: QRCode.CorrectLevel.H
69
+ });
70
+ this.loop();
71
+ };
72
+ NotoMobile.prototype.show = function () {
73
+ var _this = this;
74
+ var page_width = document.documentElement.scrollWidth;
75
+ var page_height = document.documentElement.scrollHeight;
76
+ var b_width = document.documentElement.clientWidth;
77
+ var b_height = document.documentElement.clientHeight;
78
+ this.mask = document.createElement("div");
79
+ this.mask.id = "mask";
80
+ this.mask.style.width = page_width + "px";
81
+ this.mask.style.height = page_height + "px";
82
+ this.mask.style.position = 'absolute';
83
+ this.mask.style.background = 'rgba(37,41,46,.95)';
84
+ this.mask.style.zIndex = '999';
85
+ this.mask.style.top = '0';
86
+ this.mask.style.left = '0';
87
+ document.body.appendChild(this.mask);
88
+ var width = 0;
89
+ var height = 0;
90
+ var headHeight = 60;
91
+ var headHeight1 = 50;
92
+ var qrcodeWidth = 0;
93
+ var padding = 50;
94
+ // pc
95
+ if (b_width > b_height) {
96
+ height = b_height;
97
+ width = b_height - headHeight1 - headHeight - headHeight / 2;
98
+ qrcodeWidth = width - padding * 2;
99
+ }
100
+ else {
101
+ // phone
102
+ padding = 30;
103
+ headHeight = 50;
104
+ headHeight1 = 50;
105
+ width = b_width - 60;
106
+ height = width + headHeight1 + headHeight + headHeight / 2;
107
+ qrcodeWidth = width - padding * 2;
108
+ }
109
+ this.qrcodeBox = document.createElement("div");
110
+ this.qrcodeBox.id = "qrcodeBox";
111
+ this.qrcodeBox.style.left = (b_width - width) / 2 + "px";
112
+ this.qrcodeBox.style.top = (b_height - height) / 2 + "px";
113
+ this.qrcodeBox.style.height = height + "px";
114
+ this.qrcodeBox.style.width = width + "px";
115
+ this.qrcodeBox.style.position = 'absolute';
116
+ this.qrcodeBox.style.zIndex = '10000';
117
+ // qrcodeBox.style.padding = '0 30px 0 30px'
118
+ this.qrcodeBox.innerHTML =
119
+ "<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 ");
120
+ document.body.appendChild(this.qrcodeBox);
121
+ var qrcodeb = document.getElementById("qrcodeb");
122
+ qrcodeb.style.borderRadius = "20px";
123
+ qrcodeb.style.boxSizing = 'border-box';
124
+ this.createQrcode(qrcodeWidth);
125
+ var close = window.document.getElementById("close8");
126
+ close.onclick = function () {
127
+ _this.cancel();
128
+ };
129
+ this.mask.onclick = function () {
130
+ _this.cancel();
131
+ };
132
+ };
133
+ NotoMobile.prototype.cancel = function () {
134
+ this.time = 0;
135
+ this.outTime ? clearTimeout(this.outTime) : '';
136
+ document.body.removeChild(this.mask);
137
+ document.body.removeChild(this.qrcodeBox);
138
+ };
139
+ return NotoMobile;
140
+ }());
141
+ exports.NotoMobile = NotoMobile;