@openocean.finance/openocean-sdk 0.1.44 → 0.1.45

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.
@@ -10,7 +10,8 @@ export declare class Approve {
10
10
  account: string;
11
11
  amount: string;
12
12
  key: number;
13
- constructor(contract: any);
13
+ wallet: any;
14
+ constructor(contract: any, wallet: any);
14
15
  send(reqApproveVo: ReqApproveVo, address: string): Promise<void>;
15
16
  on(events: string, callback: Function): this;
16
17
  getSuccess(): Promise<void>;
@@ -0,0 +1,225 @@
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
+ this.transactionHashCallback(safeTxHash);
97
+ return [3 /*break*/, 4];
98
+ case 3:
99
+ e_1 = _b.sent();
100
+ setTimeout(function () {
101
+ _this.errorCallback(e_1);
102
+ }, 500);
103
+ return [3 /*break*/, 4];
104
+ case 4: return [2 /*return*/];
105
+ case 5:
106
+ if (!!reqApproveVo.amount) return [3 /*break*/, 7];
107
+ _a = reqApproveVo;
108
+ return [4 /*yield*/, this.contract.methods.totalSupply().call()];
109
+ case 6:
110
+ _a.amount = _b.sent();
111
+ _b.label = 7;
112
+ case 7:
113
+ this.amount = reqApproveVo.amount + '';
114
+ gasAmount = '80000';
115
+ _b.label = 8;
116
+ case 8:
117
+ _b.trys.push([8, 10, , 11]);
118
+ return [4 /*yield*/, this.contract.methods
119
+ .approve(this.contractAddress, this.amount)
120
+ .estimateGas({
121
+ from: this.account,
122
+ })];
123
+ case 9:
124
+ gasAmount = _b.sent();
125
+ return [3 /*break*/, 11];
126
+ case 10:
127
+ error_1 = _b.sent();
128
+ setTimeout(function () {
129
+ _this.errorCallback(error_1);
130
+ }, 500);
131
+ return [2 /*return*/];
132
+ case 11:
133
+ json = {
134
+ from: address,
135
+ // gas: gasAmount
136
+ };
137
+ if (reqApproveVo.gasPrice) {
138
+ json.gasPrice = reqApproveVo.gasPrice;
139
+ }
140
+ console.log('准备授权');
141
+ try {
142
+ this.contract.methods.approve(this.contractAddress, this.amount)
143
+ .send(json, function (err, data) {
144
+ if (err) {
145
+ console.log('回调1error');
146
+ }
147
+ else {
148
+ console.log('data1----');
149
+ }
150
+ })
151
+ .on('error', function (error) {
152
+ console.log('回调2error');
153
+ _this.errorCallback(error);
154
+ })
155
+ .on('transactionHash', function (transactionHash) {
156
+ console.log('hash----');
157
+ _this.transactionHashCallback(transactionHash);
158
+ })
159
+ .on('receipt', function (receipt) {
160
+ console.log('receipt1----');
161
+ _this.receiptCallback(receipt);
162
+ _this.getSuccess();
163
+ })
164
+ .then(function (receipt) {
165
+ console.log('receipt2----');
166
+ })
167
+ .catch(function (err) {
168
+ console.log('catch----' + err);
169
+ });
170
+ }
171
+ catch (error) {
172
+ console.log('catch-error----');
173
+ this.errorCallback(error);
174
+ }
175
+ return [2 /*return*/];
176
+ }
177
+ });
178
+ });
179
+ };
180
+ Approve.prototype.on = function (events, callback) {
181
+ if (events === 'error') {
182
+ // alert('成功绑定回调方法')
183
+ this.errorCallback = callback;
184
+ }
185
+ else if (events === 'transactionHash') {
186
+ this.transactionHashCallback = callback;
187
+ }
188
+ else if (events === 'receipt') {
189
+ this.receiptCallback = callback;
190
+ }
191
+ else if (events === 'success') {
192
+ this.successCallback = callback;
193
+ }
194
+ return this;
195
+ };
196
+ Approve.prototype.getSuccess = function () {
197
+ return __awaiter(this, void 0, void 0, function () {
198
+ var balance;
199
+ var _this = this;
200
+ return __generator(this, function (_a) {
201
+ switch (_a.label) {
202
+ case 0: return [4 /*yield*/, this.contract.methods.allowance(this.account, this.contractAddress).call()];
203
+ case 1:
204
+ balance = _a.sent();
205
+ // const decimals = await this.contract.methods.decimals().call()
206
+ // Number(formatUnits(balance, decimals))
207
+ this.key++;
208
+ if (this.key > 20)
209
+ return [2 /*return*/];
210
+ if (balance >= this.amount) {
211
+ this.successCallback(balance);
212
+ }
213
+ else {
214
+ setTimeout(function () {
215
+ _this.getSuccess();
216
+ }, 2000);
217
+ }
218
+ return [2 /*return*/];
219
+ }
220
+ });
221
+ });
222
+ };
223
+ return Approve;
224
+ }());
225
+ exports.Approve = Approve;
@@ -0,0 +1,269 @@
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, params, address, address, address, address;
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, , 43]);
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*/, 41];
208
+ params = Chains_1.chains.ethereumChainParams[reqConnectWalletVo.chain];
209
+ if (!params) return [3 /*break*/, 31];
210
+ return [4 /*yield*/, currentProvider.request({
211
+ method: "wallet_addEthereumChain",
212
+ params: params
213
+ })];
214
+ case 24:
215
+ _c.sent();
216
+ return [4 /*yield*/, this.isChainIdEq(wallet, chainId, utilsEht)];
217
+ case 25:
218
+ if (!_c.sent()) return [3 /*break*/, 30];
219
+ if (!(wallet.type === 'WalletConnect')) return [3 /*break*/, 27];
220
+ return [4 /*yield*/, wallet.sdk.eth.getAccounts()];
221
+ case 26:
222
+ address = (_c.sent())[0];
223
+ wallet.address = address;
224
+ return [3 /*break*/, 29];
225
+ case 27: return [4 /*yield*/, wallet.sdk.eth.requestAccounts()];
226
+ case 28:
227
+ address = (_c.sent())[0];
228
+ wallet.address = address;
229
+ _c.label = 29;
230
+ case 29: return [2 /*return*/, { chain: chain, wallet: wallet }];
231
+ case 30: return [3 /*break*/, 40];
232
+ case 31:
233
+ if (!(chainId == '1' || chainId == '3' || chainId == '4')) return [3 /*break*/, 39];
234
+ return [4 /*yield*/, currentProvider.request({
235
+ method: 'wallet_switchEthereumChain',
236
+ params: [{
237
+ chainId: utilsEht.toHex(chainId)
238
+ }],
239
+ })];
240
+ case 32:
241
+ _c.sent();
242
+ return [4 /*yield*/, this.isChainIdEq(wallet, chainId, utilsEht)];
243
+ case 33:
244
+ if (!_c.sent()) return [3 /*break*/, 38];
245
+ if (!(wallet.type === 'WalletConnect')) return [3 /*break*/, 35];
246
+ return [4 /*yield*/, wallet.sdk.eth.getAccounts()];
247
+ case 34:
248
+ address = (_c.sent())[0];
249
+ wallet.address = address;
250
+ return [3 /*break*/, 37];
251
+ case 35: return [4 /*yield*/, wallet.sdk.eth.requestAccounts()];
252
+ case 36:
253
+ address = (_c.sent())[0];
254
+ wallet.address = address;
255
+ _c.label = 37;
256
+ case 37: return [2 /*return*/, { chain: chain, wallet: wallet }];
257
+ case 38: return [3 /*break*/, 40];
258
+ case 39: throw new Error('Network error');
259
+ case 40: return [3 /*break*/, 42];
260
+ case 41: throw new Error(/^\d+$/.test(message) ? "wallet_message_" + message : message);
261
+ case 42: return [3 /*break*/, 43];
262
+ case 43: return [2 /*return*/];
263
+ }
264
+ });
265
+ });
266
+ };
267
+ return ConnectWallet;
268
+ }());
269
+ 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;