let blockchain = new URLSearchParams(window.location.search).get('blockchain') || "tezos" let contract = new URLSearchParams(window.location.search).get('contract') || "" let tokenID = new URLSearchParams(window.location.search).get('token_id') || "" let tokenIDHash = new URLSearchParams(window.location.search).get('token_id_hash') || "" function blockchainAlias(blockchain) { switch (blockchain) { case "tezos": return "tez" case "ethereum": return "eth" default: return "tez" } } function simpleHTTPRequest(url, method, body) { return new Promise(function (resolve, reject) { let xhr = new XMLHttpRequest(); xhr.open(method, url); let xhrParams = (body) ? JSON.stringify(body) : null if (xhrParams) { xhr.setRequestHeader('content-type', 'application/json'); } xhr.onreadystatechange = function () { //Call a function when the state changes. if (xhr.readyState == 4) { if (xhr.status >= 200 && xhr.status < 400) { resolve(JSON.parse(xhr.responseText)) } else { reject(new Error("response is not ok. status: " + xhr.status)) } } } xhr.onerror = function (e) { reject(e) }; xhr.send(xhrParams); }) } function loadProvenance() { let url = 'https://indexer.autonomy.io/nft/query'; let indexID = (blockchain && contract && tokenID) ? [blockchainAlias(blockchain), contract, tokenID ].join("-") : "tez-KT1U6EHmNxJTkvaWJ4ThczG4FSDaHC21ssvi-941349" let reqBody = { "ids": [indexID] } simpleHTTPRequest(url, "POST", reqBody) .then(function (data) { if (data.length == 0) { window.dispatchEvent(new CustomEvent("provenance-request-error", { "detail": { error: new Error("token not found") } })) return } window.dispatchEvent(new CustomEvent("provenance-ready", { "detail": { provenances: data[0].provenance } })) }).catch(function (error) { window.dispatchEvent(new CustomEvent("provenance-request-error", { "detail": { error: error } })) }) } function loadBlockchainInfo() { simpleHTTPRequest("https://api.blockcypher.com/v1/eth/main", "GET") .then(function (data) { window.dispatchEvent(new CustomEvent("blockchain-info-ready", { "detail": { height: data.height } })) }).catch(function (error) { window.dispatchEvent(new CustomEvent("blockchain-info-request-error", { "detail": { error: error } })) }) } function ffinit() { loadProvenance() loadBlockchainInfo() }