diff options
-rw-r--r-- | ak-wallet-dev.html | 1104 |
1 files changed, 607 insertions, 497 deletions
diff --git a/ak-wallet-dev.html b/ak-wallet-dev.html index 9879562..32bdffa 100644 --- a/ak-wallet-dev.html +++ b/ak-wallet-dev.html @@ -4,57 +4,63 @@ <meta charset="utf-8"> <title>Dashboard | Arching Kaos</title> <style type="text/css"> - pre { white-space: pre-wrap; } - #stellar-freigher-connect-address-button { - position: fixed; - top: 0; - right: 2vw; - padding: 2vh 2vw; - } + pre { white-space: pre-wrap; } + #stellar-freigher-connect-address-button { + position: fixed; + top: 0; + right: 2vw; + padding: 2vh 2vw; + } + #stats-section div { + border: #0a0a0a 2px solid; + background: darkred; + padding: 2px; + width: fit-content; + } </style> - <link rel="icon" href="https://ipfs.arching-kaos.com/ipfs/QmagKP1zLWaGHLR4191dpvsCYHS8tuPCRYJgfK9Zdr6i9S?filename=logo.png" sizes="32x32"> - <link rel="icon" href="https://ipfs.arching-kaos.com/ipfs/QmagKP1zLWaGHLR4191dpvsCYHS8tuPCRYJgfK9Zdr6i9S?filename=logo.png" sizes="192x192"> - <link rel="apple-touch-icon" href="https://ipfs.arching-kaos.com/ipfs/QmagKP1zLWaGHLR4191dpvsCYHS8tuPCRYJgfK9Zdr6i9S?filename=logo.png"> - <meta name="msapplication-TileImage" content="https://ipfs.arching-kaos.com/ipfs/QmagKP1zLWaGHLR4191dpvsCYHS8tuPCRYJgfK9Zdr6i9S?filename=logo.png"> + <link rel="icon" href="https://ipfs.arching-kaos.com/ipfs/QmagKP1zLWaGHLR4191dpvsCYHS8tuPCRYJgfK9Zdr6i9S?filename=logo.png" sizes="32x32"> + <link rel="icon" href="https://ipfs.arching-kaos.com/ipfs/QmagKP1zLWaGHLR4191dpvsCYHS8tuPCRYJgfK9Zdr6i9S?filename=logo.png" sizes="192x192"> + <link rel="apple-touch-icon" href="https://ipfs.arching-kaos.com/ipfs/QmagKP1zLWaGHLR4191dpvsCYHS8tuPCRYJgfK9Zdr6i9S?filename=logo.png"> + <meta name="msapplication-TileImage" content="https://ipfs.arching-kaos.com/ipfs/QmagKP1zLWaGHLR4191dpvsCYHS8tuPCRYJgfK9Zdr6i9S?filename=logo.png"> <link rel="stylesheet" type="text/css" href="//ipfs.arching-kaos.com/ipfs/Qmcusex5HCKKeKAouXtUiwGoFxZzzsvcmo4dGewKBETwDv?filename=style2.css"> <link rel="stylesheet" type="text/css" href="//ipfs.arching-kaos.com/ipfs/Qme4Lao1ffeyDtn4r9z8ZPCUPipRWJHPJig9Kh9XHw1ete?filename=style.css"> <meta name="viewport" content="width=device-width, initial-scale=1"> <script src="https://cdnjs.cloudflare.com/ajax/libs/stellar-freighter-api/1.1.2/index.min.js"></script> </head> <body> - <div class="header"> - <img src="//ipfs.arching-kaos.com/ipfs/QmcyDhApg19qDcjdCpTFaezXrjfcUrC9MZq9wKo69trRDH"> - <h1 style="text-align: center;">Arching Kaos</h1> - </div> - <hr> - <div id="menu" class="linkin"> - <span id="mypage-section-link"><a href="#mypage-section" onclick="menusel(this)">My page</a> | </span> - <a href="#mixtapes-section" onclick="menusel(this)">Mixtapes</a> | - <a href="#news-section" onclick="menusel(this)">News</a> | - <span id="stellar-balances-link"><a href="#stellar-balances" onclick="menusel(this)">Balances</a> | </span> - <span id="stellar-data-config-link"><a href="#stellar-data-config" onclick="menusel(this)">Data</a> | </span> - <span id="arching-kaos-id-link"><a href="#arching-kaos-id" onclick="menusel(this)">AKID</a> | </span> - <a href="#zchain-data-section" onclick="menusel(this)">zchain</a> | - <a href="#stats-section" onclick="menusel(this)">Stats</a> | - <a href="#chat-section" onclick="menusel(this)">Chat</a> | - <a href="#about-section" onclick="menusel(this)">About</a> - </div> - <hr> + <div class="header"> + <img src="//ipfs.arching-kaos.com/ipfs/QmcyDhApg19qDcjdCpTFaezXrjfcUrC9MZq9wKo69trRDH"> + <h1 style="text-align: center;">Arching Kaos</h1> + </div> + <hr> + <div id="menu" class="linkin"> + <span id="mypage-section-link"><a href="#mypage-section" onclick="menusel(this)">My page</a> | </span> + <a href="#mixtapes-section" onclick="menusel(this)">Mixtapes</a> | + <a href="#news-section" onclick="menusel(this)">News</a> | + <span id="stellar-balances-link"><a href="#stellar-balances" onclick="menusel(this)">Balances</a> | </span> + <span id="stellar-data-config-link"><a href="#stellar-data-config" onclick="menusel(this)">Data</a> | </span> + <span id="arching-kaos-id-link"><a href="#arching-kaos-id" onclick="menusel(this)">AKID</a> | </span> + <a href="#zchain-data-section" onclick="menusel(this)">zchain</a> | + <a href="#stats-section" onclick="menusel(this)">Stats</a> | + <a href="#chat-section" onclick="menusel(this)">Chat</a> | + <a href="#about-section" onclick="menusel(this)">About</a> + </div> + <hr> <p class="sub-input" id="stellar-freigher-connect-address-button" onclick="connect()" >Connect with Stellar address</p> <div> - <div id="about-section"> - <h2>About</h2> - <p>Arching Kaos is a project about radio, music, communications and decentralization. On site, you can listen to the latest mixes of music (menu entry "Mixtapes"), read latest news of the network and chat.</p> - <p>Note that to participate you will need to set up your Arching Kaos set, which is not so convinient yet (under development).</p> - <p>Furthermore, if you are using Freighter extension you can additionally see:</p> - <ol> - <li>Your balances on your wallet</li> - <li>Your configuration IPNS address (if any)</li> - <li>Your Arching Kaos configuration (if any)</li> - <li>Your zchain (...)</li> - <li>Your posted newsfeed (...)</li> - </ol> - <p>Finally, on the stats page you can find people that are participating over the Stellar Network, using the ARCHINGKAOS token/asset/coin.</p> + <div id="about-section"> + <h2>About</h2> + <p>Arching Kaos is a project about radio, music, communications and decentralization. On site, you can listen to the latest mixes of music (menu entry "Mixtapes"), read latest news of the network and chat.</p> + <p>Note that to participate you will need to set up your Arching Kaos set, which is not so convinient yet (under development).</p> + <p>Furthermore, if you are using Freighter extension you can additionally see:</p> + <ol> + <li>Your balances on your wallet</li> + <li>Your configuration IPNS address (if any)</li> + <li>Your Arching Kaos configuration (if any)</li> + <li>Your zchain (...)</li> + <li>Your posted newsfeed (...)</li> + </ol> + <p>Finally, on the stats page you can find people that are participating over the Stellar Network, using the ARCHINGKAOS token/asset/coin.</p> </div> <div id="stellar-balances"><h2>Balances</h2></div> <div id="stellar-data-config"><h2>Data</h2><p>The following was found on your wallet's "config" variable:</p></div> @@ -63,474 +69,578 @@ <div id="news-section"><h2>News</h2></div> <div id="mixtapes-section"><h2>Mixtapes</h2></div> <div id="chat-section"><h2>Chat</h2> - <iframe src="https://irc.arching-kaos.com" style="width: -moz-available; height: 80vh;"></iframe> + <iframe src="https://irc.arching-kaos.com" style="width: -moz-available; height: 80vh;"></iframe> </div> <div id="stats-section"><h2>Stats</h2></div> <div id="mypage-section"> - <h2>My page</h2> - <div id="my-news"></div> - <div id="my-mixtapes"></div> - <div id="my-zchain"></div> + <h2>My page</h2> + <div id="my-news"></div> + <div id="my-mixtapes"></div> + <div id="my-zchain"></div> </div> </div> <hr> <div class="footer"> - Arching Kaos <a target="_blank" href="https://git.kaotisk-hund.com/arching-kaos-tools/.git">Tools</a>, <a target="_blank" href="https://arching-kaos.org">Org</a>, <a target="_blank" href="https://arching-kaos.net">Net</a> | - Powered by <a target="_blank" href="https://www.kaotisk-hund.com">Kaotisk Hund</a>. + Arching Kaos <a target="_blank" href="https://git.kaotisk-hund.com/arching-kaos-tools/.git">Tools</a>, <a target="_blank" href="https://arching-kaos.org">Org</a>, <a target="_blank" href="https://arching-kaos.net">Net</a> | + Powered by <a target="_blank" href="https://www.kaotisk-hund.com">Kaotisk Hund</a>. </div> </body> <script src="//cdnjs.cloudflare.com/ajax/libs/stellar-sdk/10.0.1/stellar-sdk.js"></script> <script> - var profilemenuids = [] - var menuids = ['#about-section','#zchain-data-section','#news-section','#stats-section','#mixtapes-section','#chat-section','#mypage-section','#stellar-balances','#stellar-data-config','#arching-kaos-id']; - function menuinit(){ - menuids.forEach(m=>document.querySelector(m).hidden=true) - } - menuinit() - document.querySelector('#about-section').hidden=false + var profilemenuids = [] + /* + * Array of all the menu-panes IDs + */ + var menuids = ['#about-section','#zchain-data-section','#news-section','#stats-section','#mixtapes-section','#chat-section','#mypage-section','#stellar-balances','#stellar-data-config','#arching-kaos-id']; + // Function to hide all the panes + function menuinit(){ + menuids.forEach(m=>document.querySelector(m).hidden=true) + } + // And call + menuinit() + // We bring up the default pane ( #about-section ) + document.querySelector('#about-section').hidden=false - function menusel(m){ - menuinit(); - console.log(m) - document.querySelector(m.hash).hidden=false - } - function gettrustlines(){ - var url='https://horizon.stellar.org/assets?asset_code=ARCHINGKAOS&asset_issuer=GB4QVKD6NW3CSNO5TNPARAWNPPXOPSSTKB35XCWB7PUNBIQTK3DVELB2' - fetch(url, { - method:'GET', - headers:{ - Accept: 'application/json' - } - }).then(response=>{ - if(response.ok){ - response.json().then(json=>{ - var stats = document.querySelector('#stats-section') - var small = document.createElement("small") - small.innerHTML = 'Connected trustlines: ' + json._embedded.records[0].accounts.authorized - stats.appendChild(small) - }) - } - }) - } - gettrustlines() - function getholders(a=0){ - var url='https://horizon.stellar.org/accounts?asset=ARCHINGKAOS:GB4QVKD6NW3CSNO5TNPARAWNPPXOPSSTKB35XCWB7PUNBIQTK3DVELB2&limit=200' - fetch(url, { - method:'GET', - headers:{ - Accept: 'application/json' - } - }).then(response=>{ - if(response.ok){ - response.json().then(json=>{ - var stats = document.querySelector('#stats-section') - json._embedded.records.forEach(r=>{ - var p = document.createElement("p") - p.innerHTML = r.account_id - p.id = r.account_id - checkforconfig(r.account_id) - stats.appendChild(p) - }) - // if (json._links.next) getholders(json._links.next.href) - }) - } - }) - } - getholders() + /* + * Function called on clicks on the menu bar + * Unhides the pane connected to the clicked menu entry + */ + function menusel(m){ + menuinit(); + console.log(m) + document.querySelector(m.hash).hidden=false + } - function checkforconfig(addr) { - url='https://horizon.stellar.org/accounts/'+addr+'/data/config' - fetch(url, { - method:'GET', - headers:{ - Accept: 'application/json' - } - }).then(response=>{ - if(response.ok){ - response.json().then(json=>{ - var cnf = document.createElement("p") - cnf.innerHTML = atob(json.value) - document.querySelector('#'+addr).appendChild(cnf) - getnickname(atob(json.value),addr) - }) - } - }) - } - function getnickname(a,eid){ - url='https://ipfs.arching-kaos.com/ipns/'+a - fetch(url, { - method:'GET', - headers:{ - Accept: 'application/json' - } - }).then(response=>{ - if(response.ok){ - response.json().then(json=>{ - /* Could be json object with - * - genesis - * - gpg - * - profile { - * - nickname - * } - * - zchain - */ - var divs = document.querySelector('#'+eid) - if(json.genesis){ - var p = document.createElement("p") - p.innerHTML="Genesis: " +json.genesis - divs.appendChild(p) - } - if(json.gpg){ - var p = document.createElement("p") - p.innerHTML="GPG: " +json.gpg - divs.appendChild(p) - } - if(json.profile.nickname){ - var p = document.createElement("p") - p.innerHTML="Nickname: " +json.profile.nickname - divs.appendChild(p) - } - if(json.zchain){ - var p = document.createElement("p") - p.innerHTML="zchain: " +json.zchain - divs.appendChild(p) - } - zseek(json.zchain) - }) - } - }) - } - var server = new StellarSdk.Server('https://horizon.stellar.org'); - function letme(a){ - server.accounts() - .accountId(a) - .call().then(function(r){ const L = r; putit(r); }); - } - function putit(i){ - var ta=document.querySelector("#stellar-balances") - readit(i) - for (b in i.balances) { - x = i.balances[b] - console.log(x) - var as = document.createElement("p") - as.innerHTML = x.balance + " "+ ( x.asset_code && x.asset_code != "undefined" ? x.asset_code : 'XLM') - ta.appendChild(as) - } - } - async function dataf(i){ - url='https://horizon.stellar.org/accounts/'+i+'/data/config' - - fetch(url, { - method:'GET', - headers:{ - Accept: 'application/json' - } - }).then(response=>{ - if(response.ok){ - response.json().then(json=>{ - var cnf = document.createElement("p") - cnf.innerHTML = atob(json.value) - document.querySelector('#stellar-data-config').appendChild(cnf) - akiseek(atob(json.value)) - }) - } - }) - } - function akiseek(i){ - url='https://ipfs.arching-kaos.com/ipns/'+i - fetch(url, { - method:'GET', - headers:{ - Accept: 'application/json' - } - }).then(response=>{ - if(response.ok){ - response.json().then(json=>{ - /* Could be json object with - * - genesis - * - gpg - * - profile { - * - nickname - * } - * - zchain - */ - var divs = document.querySelector('#arching-kaos-id'); - if(json.genesis){ - var p = document.createElement("p") - p.innerHTML="Genesis: " +json.genesis - divs.appendChild(p) - } - if(json.gpg){ - var p = document.createElement("p") - p.innerHTML="GPG: " +json.gpg - divs.appendChild(p) - } - if(json.profile.nickname){ - var p = document.createElement("p") - p.innerHTML="Nickname: " +json.profile.nickname - divs.appendChild(p) - } - if(json.zchain){ - var p = document.createElement("p") - p.innerHTML="zchain: " +json.zchain - divs.appendChild(p) - } - zseek(json.zchain) - }) - } - }) - } - function zseek(i){ - url = 'https://ipfs.arching-kaos.com/ipns/'+i - fetch(url, { - method:'GET', - headers:{ - Accept: 'application/json' - } - }).then(response=>{ - if(response.ok){ - response.json().then(json=>{ - /* Could be json object with - * - block - * - block_signature - */ - var divs = document.querySelector('#zchain-data-section'); - if(json.block){ - var p = document.createElement("p") - p.innerHTML="Block: " +json.block - divs.appendChild(p) - } - if(json.block_signature){ - var p = document.createElement("p") - p.innerHTML="Signature: " +json.block_signature - divs.appendChild(p) - } - divs.appendChild(document.createElement("hr")); - seekblock(json.block) - }) - } - }) - } - function seekblock(i){ - url = 'https://ipfs.arching-kaos.com/ipfs/'+i - fetch(url, { - method:'GET', - headers:{ - Accept: 'application/json' - } - }).then(response=>{ - if(response.ok){ - response.json().then(json=>{ - /* Could be json object with - * - action - * - data - * - gpg - * - timestamp - * - previous - * - detach - */ - var divs = document.querySelector('#zchain-data-section'); - if(json.action){ - var p = document.createElement("p") - p.innerHTML="Action: " +json.action - divs.appendChild(p) - } - if(json.detach){ - var p = document.createElement("p") - p.innerHTML="Detach: " +json.detach - divs.appendChild(p) - } - if(json.gpg){ - var p = document.createElement("p") - p.innerHTML="GPG: " +json.gpg - divs.appendChild(p) - } - if(json.data){ - var p = document.createElement("p") - var a = document.createElement("a") - a.href = 'https://ipfs.arching-kaos.com/ipfs/'+json.data - a.innerHTML = json.data - p.innerHTML="Data: " - p.appendChild(a) - divs.appendChild(p) - } - if(json.timestamp){ - var p = document.createElement("p") - p.innerHTML="Timestamp: " +json.timestamp - divs.appendChild(p) - } - if(json.previous){ - var p = document.createElement("p") - p.innerHTML="Previous: " +json.previous - divs.appendChild(p) - } - divs.appendChild(document.createElement("hr")); - exe(json.action,json.data) - if(json.previous!="QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwQH") seekzblock(json.previous) - }) - } - }) - } - function seekzblock(i){ - url = 'https://ipfs.arching-kaos.com/ipfs/'+i - fetch(url, { - method:'GET', - headers:{ - Accept: 'application/json' - } - }).then(response=>{ - if(response.ok){ - response.json().then(json=>{ - /* Could be json object with - * - block - * - block_signature - */ - var divs = document.querySelector('#zchain-data-section'); - if(json.block){ - var p = document.createElement("p") - p.innerHTML="Block: " +json.block - p.id=i - divs.appendChild(p) - } - if(json.block_signature){ - var p = document.createElement("p") - p.innerHTML="Signature: " +json.block_signature - divs.appendChild(p) - } - divs.appendChild(document.createElement("hr")); - seekblock(json.block) - }) - } - }) - } - function exe(a,d){ - gurl = 'https://ipfs.arching-kaos.com/ipfs/' - fetch(gurl+d, { - method:'GET', - headers:{ - Accept: 'application/json' - } - }).then(response=>{ - if(response.ok){ - response.json().then(json=>{ - /* Could be json object with - * - block - * - block_signature - */ - if (a == "news/add") { - var divs = document.querySelector('#news-section'); - var art = document.createElement("article"); - art.id = d - if(json.title){ - var h3 = document.createElement("h3") - h3.innerHTML = json.title - art.appendChild(h3) - } - if(json.datetime){ - var small = document.createElement("small") - small.innerHTML="Published: " +json.datetime - art.appendChild(small) - } - if(json.ipfs){ - getipfstext(json.ipfs,art.id) - } - divs.appendChild(art) - divs.appendChild(document.createElement("hr")); + /* + * Get Trustlines for ARCHINGKAOS asset + * Returns DOM element with number of trustlines + */ + function gettrustlines(){ + var url='https://horizon.stellar.org/assets?asset_code=ARCHINGKAOS&asset_issuer=GB4QVKD6NW3CSNO5TNPARAWNPPXOPSSTKB35XCWB7PUNBIQTK3DVELB2' + fetch(url, { + method:'GET', + headers:{ + Accept: 'application/json' + } + }).then(response=>{ + if(response.ok){ + response.json().then(json=>{ + var stats = document.querySelector('#stats-section') + var small = document.createElement("small") + small.innerHTML = 'Connected trustlines: ' + json._embedded.records[0].accounts.authorized + stats.appendChild(small) + }) + } + }) + } + gettrustlines() + /* + * Get addresses that trust the asset + * Limit is 200 addresses cause horizon API limitations. + * + * TODO: Crawl through the pagination + * + * Returns div DOM elements for each found address, embedding + * the address both in innerHTML and in id of the div. + */ + function getholders(a=0){ + var url='https://horizon.stellar.org/accounts?asset=ARCHINGKAOS:GB4QVKD6NW3CSNO5TNPARAWNPPXOPSSTKB35XCWB7PUNBIQTK3DVELB2&limit=200' + fetch(url, { + method:'GET', + headers:{ + Accept: 'application/json' + } + }).then(response=>{ + if(response.ok){ + response.json().then(json=>{ + var stats = document.querySelector('#stats-section') + json._embedded.records.forEach(r=>{ + var p = document.createElement("div") + p.innerHTML = r.account_id + p.id = r.account_id + checkforconfig(r.account_id) + stats.appendChild(p) + }) + // if (json._links.next) getholders(json._links.next.href) + }) + } + }) + } + getholders() - } - if (a == "mixtape/add") { - var divs = document.querySelector('#mixtapes-section'); - var art = document.createElement("article"); - art.id = d - if(json.title){ - var h3 = document.createElement("h3") - h3.innerHTML = json.title - art.appendChild(h3) - } - if(json.artist){ - var h4 = document.createElement("h4") - h4.innerHTML = json.artist - art.appendChild(h4) - } - if(json.datetime){ - var small = document.createElement("small") - small.innerHTML="Published: " +json.datetime - art.appendChild(small) - } - if(json.ipfs){ - var audio = document.createElement("audio") - audio.setAttribute('controls','') - var source = document.createElement("source") - source.src = 'https://ipfs.arching-kaos.com/ipfs/' + json.ipfs - audio.appendChild(source) - art.appendChild(audio) - } - divs.appendChild(art) - } - // seekblock(json.block) - }) - } - }) - } - function getipfstext(ipfs,articleid){ - url = 'https://ipfs.arching-kaos.com/ipfs/'+ipfs - fetch(url, { - method:'GET', - headers:{ - Accept: 'text/plain' - } - }).then(response=>{ - if(response.ok){ - response.text().then(text=>{ - var divs = document.querySelector('#'+articleid); - if(text){ - var pre = document.createElement("pre") - var lines = text.split('\n'); - // remove one line, starting at the first position - lines.splice(0,1); - // join the array back into a single string - var newtext = lines.join('\n'); - pre.innerHTML = newtext - divs.appendChild(pre) - } - // seekblock(json.block) - }) - } - }) - } - function readit(i){ - console.log(i) - } - function putKeyToField(k){ - let base = document.querySelector("#stellar-freigher-connect-address-button") - dataf(k) - base.innerHTML=k - base.onclick='' - } - if (!window.freighterApi.isConnected()) { - document.querySelector("#stellar-freigher-connect-address-button").hidden=true; - document.querySelector("#stellar-balances-link").hidden=true; - document.querySelector("#stellar-data-config-link").hidden=true; - document.querySelector("#arching-kaos-id-link").hidden=true; - document.querySelector("#mypage-section-link").hidden=true; - } - const retrievePublicKey = async () => { - let publicKey = ""; - let error = ""; + /* + * Function that checks the address' variable 'config' to see + * if it's set up. + * + * Returns the IPNS link in the DOM as p element and proceeds to + * get nickname from the variables + */ + function checkforconfig(addr) { + url='https://horizon.stellar.org/accounts/'+addr+'/data/config' + fetch(url, { + method:'GET', + headers:{ + Accept: 'application/json' + } + }).then(response=>{ + if(response.ok){ + response.json().then(json=>{ + var cnf = document.createElement("p") + cnf.innerHTML = atob(json.value) + document.querySelector('#'+addr).appendChild(cnf) + document.querySelector('#'+addr).style="background: darkgreen;" + getnickname(atob(json.value),addr) + }) + } + }) + } - try { - publicKey = await window.freighterApi.getPublicKey() - .then(publicKey => {putKeyToField(publicKey);letme(publicKey)}); - } catch (e) { - error = e; - } - if (error) { - return error; - } - return publicKey; - }; - function connect(){ - const result = retrievePublicKey(); - } + /* + * Function that gets nickname and parses the config variable. + * + * Returns the key:value pairs of the configuration and proceeds + * to get the zchain + */ + function getnickname(a,eid){ + url='https://ipfs.arching-kaos.com/ipns/'+a + fetch(url, { + method:'GET', + headers:{ + Accept: 'application/json' + } + }).then(response=>{ + if(response.ok){ + response.json().then(json=>{ + /* Could be json object with + * - genesis + * - gpg + * - profile { + * - nickname + * } + * - zchain + */ + var divs = document.querySelector('#'+eid) + if(json.genesis){ + var p = document.createElement("p") + p.innerHTML="Genesis: " +json.genesis + divs.appendChild(p) + } + if(json.gpg){ + var p = document.createElement("p") + p.innerHTML="GPG: " +json.gpg + divs.appendChild(p) + } + if(json.profile.nickname){ + var p = document.createElement("p") + p.innerHTML="Nickname: " +json.profile.nickname + divs.appendChild(p) + } + if(json.zchain){ + var p = document.createElement("p") + p.innerHTML="zchain: " +json.zchain + divs.appendChild(p) + } + zseek(json.zchain) + }) + } + }) + } + + /* + * We now connect our client to horizon + */ + var server = new StellarSdk.Server('https://horizon.stellar.org'); + // We ask for the 'a' stellar address the balances + function letme(a){ + server.accounts() + .accountId(a) + .call().then(function(r){ const L = r; putit(r); }); + } + // We print them + function putit(i){ + var ta=document.querySelector("#stellar-balances") + readit(i) + for (b in i.balances) { + x = i.balances[b] + console.log(x) + var as = document.createElement("p") + as.innerHTML = x.balance + " "+ ( x.asset_code && x.asset_code != "undefined" ? x.asset_code : 'XLM') + ta.appendChild(as) + } + } + // We also search for a config file and display it + async function dataf(i){ + url='https://horizon.stellar.org/accounts/'+i+'/data/config' + fetch(url, { + method:'GET', + headers:{ + Accept: 'application/json' + } + }).then(response=>{ + if(response.ok){ + response.json().then(json=>{ + var cnf = document.createElement("p") + cnf.innerHTML = atob(json.value) + document.querySelector('#stellar-data-config').appendChild(cnf) + akiseek(atob(json.value)) + }) + } + }) + } + // Although we implemented something similar already, + // it seems like I was not happy so JRM + // #TODO : Revisit this + + /* + * Function to seek configuration for any address i + * it's used to seek specifically the Freighter user's address. + * + * Returns p DOM elements on #arching-kaos-id pane + */ + function akiseek(i){ + url='https://ipfs.arching-kaos.com/ipns/'+i + fetch(url, { + method:'GET', + headers:{ + Accept: 'application/json' + } + }).then(response=>{ + if(response.ok){ + response.json().then(json=>{ + /* Could be json object with + * - genesis + * - gpg + * - profile { + * - nickname + * } + * - zchain + */ + var divs = document.querySelector('#arching-kaos-id'); + if(json.genesis){ + var p = document.createElement("p") + p.innerHTML="Genesis: " +json.genesis + divs.appendChild(p) + } + if(json.gpg){ + var p = document.createElement("p") + p.innerHTML="GPG: " +json.gpg + divs.appendChild(p) + } + if(json.profile.nickname){ + var p = document.createElement("p") + p.innerHTML="Nickname: " +json.profile.nickname + divs.appendChild(p) + } + if(json.zchain){ + var p = document.createElement("p") + p.innerHTML="zchain: " +json.zchain + divs.appendChild(p) + } + zseek(json.zchain,eid,json) + }) + } + }) + } + /* + * Function to seek Zblocks + * + * Returns Block and Signature for each ZBLOCK found. + * + * Proceeds to the blocks found. + */ + function zseek(i,d,j){ + url = 'https://ipfs.arching-kaos.com/ipns/'+i + fetch(url, { + method:'GET', + headers:{ + Accept: 'application/json' + } + }).then(response=>{ + if(response.ok){ + response.json().then(json=>{ + /* Could be json object with + * - block + * - block_signature + */ + var divs = document.querySelector('#zchain-data-section'); + if(json.block){ + var p = document.createElement("p") + p.innerHTML="Block: " +json.block + divs.appendChild(p) + } + if(json.block_signature){ + var p = document.createElement("p") + p.innerHTML="Signature: " +json.block_signature + divs.appendChild(p) + } + divs.appendChild(document.createElement("hr")); + seekblock(json.block,i,d,j) + }) + } + }) + } + + /* + * Seeks a block and parses it. + * + * Returns each element found in #zchain-data-section pane. + * + * Proceeds to execute the block. + */ + function seekblock(i,l,d,j){ + console.log(i) + url = 'https://ipfs.arching-kaos.com/ipfs/'+i + fetch(url, { + method:'GET', + headers:{ + Accept: 'application/json' + } + }).then(response=>{ + if(response.ok){ + response.json().then(json=>{ + /* Could be json object with + * - action + * - data + * - gpg + * - timestamp + * - previous + * - detach + */ + var divs = document.querySelector('#zchain-data-section'); + if(json.action){ + var p = document.createElement("p") + p.innerHTML="Action: " +json.action + divs.appendChild(p) + } + if(json.detach){ + var p = document.createElement("p") + p.innerHTML="Detach: " +json.detach + divs.appendChild(p) + } + if(json.gpg){ + var p = document.createElement("p") + p.innerHTML="GPG: " +json.gpg + divs.appendChild(p) + } + if(json.data){ + var p = document.createElement("p") + var a = document.createElement("a") + a.href = 'https://ipfs.arching-kaos.com/ipfs/'+json.data + a.innerHTML = json.data + p.innerHTML="Data: " + p.appendChild(a) + divs.appendChild(p) + } + if(json.timestamp){ + var p = document.createElement("p") + p.innerHTML="Timestamp: " +json.timestamp + divs.appendChild(p) + } + if(json.previous){ + var p = document.createElement("p") + p.innerHTML="Previous: " +json.previous + divs.appendChild(p) + } + divs.appendChild(document.createElement("hr")); + exe(json.action,json.data,json,l,d,j) + if(json.previous!="QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwQH") seekzblock(json.previous) + }) + } + }) + } + + // seeks a zblock obviously. another double function + // TODO: figure out why the second one exists + + /* + * Function gets ZBLOCK and parses it + * + * Returns Block and Signature elements on DOM as p + * + * Proceeds to seek the block found + */ + function seekzblock(i){ + url = 'https://ipfs.arching-kaos.com/ipfs/'+i + fetch(url, { + method:'GET', + headers:{ + Accept: 'application/json' + } + }).then(response=>{ + if(response.ok){ + response.json().then(json=>{ + /* Could be json object with + * - block + * - block_signature + */ + var divs = document.querySelector('#zchain-data-section'); + if(json.block){ + var p = document.createElement("p") + p.innerHTML="Block: " +json.block + p.id=i + divs.appendChild(p) + } + if(json.block_signature){ + var p = document.createElement("p") + p.innerHTML="Signature: " +json.block_signature + divs.appendChild(p) + } + divs.appendChild(document.createElement("hr")); + seekblock(json.block) + }) + } + }) + } + + /* + * Function that executes a specified block + * + * Returns the result of execution on the proper page in DOM + */ + function exe(a,d,j,x,y,z){ + console.log(a,d,j,x,y,z) + gurl = 'https://ipfs.arching-kaos.com/ipfs/' + fetch(gurl+d, { + method:'GET', + headers:{ + Accept: 'application/json' + } + }).then(response=>{ + if(response.ok){ + response.json().then(json=>{ + /* Could be json |