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 | exports.__esModule = true;
|
42 | exports.loadNftPlugin = exports.getNFTInfo = void 0;
|
43 | var axios_1 = __importDefault(require("axios"));
|
44 | var loadConfig_1 = require("./loadConfig");
|
45 | var logs_1 = require("@ledgerhq/logs");
|
46 | var getNFTInfo = function (contractAddress, chainId, userLoadConfig) { return __awaiter(void 0, void 0, void 0, function () {
|
47 | var nftExplorerBaseURL, url, response, payload, collectionNameLength, collectionNameHex, collectionName;
|
48 | var _a;
|
49 | return __generator(this, function (_b) {
|
50 | switch (_b.label) {
|
51 | case 0:
|
52 | nftExplorerBaseURL = (0, loadConfig_1.getLoadConfig)(userLoadConfig).nftExplorerBaseURL;
|
53 | if (!nftExplorerBaseURL)
|
54 | return [2 ];
|
55 | url = "".concat(nftExplorerBaseURL, "/").concat(chainId, "/contracts/").concat(contractAddress);
|
56 | return [4 , axios_1["default"]
|
57 | .get(url)
|
58 | .then(function (r) { return r.data; })["catch"](function (e) {
|
59 | (0, logs_1.log)("error", "could not fetch from " + url + ": " + String(e));
|
60 | return null;
|
61 | })];
|
62 | case 1:
|
63 | response = _b.sent();
|
64 | if (!response)
|
65 | return [2 ];
|
66 | payload = response["payload"];
|
67 | collectionNameLength = parseInt(payload.slice(4, 6), 16);
|
68 | collectionNameHex = payload.substr(6, collectionNameLength * 2);
|
69 | collectionName = (_a = collectionNameHex
|
70 | .match(/.{2}/g)
|
71 | ) === null || _a === void 0 ? void 0 : _a.reduce(function (acc, curr) { return (acc += String.fromCharCode(parseInt(curr, 16))); }, "");
|
72 | return [2 , {
|
73 | contractAddress: contractAddress,
|
74 | collectionName: collectionName || "",
|
75 | data: payload
|
76 | }];
|
77 | }
|
78 | });
|
79 | }); };
|
80 | exports.getNFTInfo = getNFTInfo;
|
81 | var loadNftPlugin = function (contractAddress, selector, chainId, userLoadConfig) { return __awaiter(void 0, void 0, void 0, function () {
|
82 | var nftExplorerBaseURL, url, response, payload;
|
83 | return __generator(this, function (_a) {
|
84 | switch (_a.label) {
|
85 | case 0:
|
86 | nftExplorerBaseURL = (0, loadConfig_1.getLoadConfig)(userLoadConfig).nftExplorerBaseURL;
|
87 | if (!nftExplorerBaseURL)
|
88 | return [2 ];
|
89 | url = "".concat(nftExplorerBaseURL, "/").concat(chainId, "/contracts/").concat(contractAddress, "/plugin-selector/").concat(selector);
|
90 | return [4 , axios_1["default"]
|
91 | .get(url)
|
92 | .then(function (r) { return r.data; })["catch"](function (e) {
|
93 | (0, logs_1.log)("error", "could not fetch from " + url + ": " + String(e));
|
94 | return null;
|
95 | })];
|
96 | case 1:
|
97 | response = _a.sent();
|
98 | if (!response)
|
99 | return [2 ];
|
100 | payload = response["payload"];
|
101 | return [2 , payload];
|
102 | }
|
103 | });
|
104 | }); };
|
105 | exports.loadNftPlugin = loadNftPlugin;
|
106 |
|
\ | No newline at end of file |