diff options
author | kaotisk <kaotisk@arching-kaos.org> | 2023-09-13 03:58:37 +0300 |
---|---|---|
committer | kaotisk <kaotisk@arching-kaos.org> | 2023-09-13 03:58:37 +0300 |
commit | 6d32a51649c246c86ff8c77bb123c6fa860f4e96 (patch) | |
tree | bc7f182d83d785f4d26ee195ef1e3bdfc4dec15b | |
parent | 07836b00b52f922a889d0ea57144d505e8e92207 (diff) | |
download | arching-kaos-web-ui-6d32a51649c246c86ff8c77bb123c6fa860f4e96.tar.gz arching-kaos-web-ui-6d32a51649c246c86ff8c77bb123c6fa860f4e96.tar.bz2 arching-kaos-web-ui-6d32a51649c246c86ff8c77bb123c6fa860f4e96.zip |
Further refactoring
-rw-r--r-- | src/index.html | 1 | ||||
-rw-r--r-- | src/js/app.js | 4 | ||||
-rw-r--r-- | src/js/arching-kaos-fetch.js | 18 | ||||
-rw-r--r-- | src/js/arching-kaos-stellar-network.js | 82 | ||||
-rw-r--r-- | src/js/arching-kaos-tools.js | 286 | ||||
-rw-r--r-- | src/js/environment-setup.js | 16 | ||||
-rw-r--r-- | src/js/url-generators.js | 36 |
7 files changed, 222 insertions, 221 deletions
diff --git a/src/index.html b/src/index.html index 5a72882..0e8bad7 100644 --- a/src/index.html +++ b/src/index.html @@ -207,6 +207,7 @@ <script src="./external/purify.min.js"></script> <script src="./js/environment-setup.js"></script> <script src="./js/arching-kaos-web-ui-settings.js"></script> + <script src="./js/url-generators.js"></script> <script src="./js/arching-kaos-fetch.js"></script> <script src="./js/arching-kaos-log.js"></script> <script src="./js/menu-magic.js"></script> diff --git a/src/js/app.js b/src/js/app.js index 86f201b..11b9658 100644 --- a/src/js/app.js +++ b/src/js/app.js @@ -1,7 +1,3 @@ -// Irrelevant for now -if (DEBUG) console.log(window.location); - - /* * Body and pageLayout resizer to device's resolution. * diff --git a/src/js/arching-kaos-fetch.js b/src/js/arching-kaos-fetch.js index a29a5ae..656cbe0 100644 --- a/src/js/arching-kaos-fetch.js +++ b/src/js/arching-kaos-fetch.js @@ -1,20 +1,4 @@ function archingKaosFetchJSON( url, callback, params ){ -// fetch(url, { -// method:'GET', -// headers:{ -// Accept: 'application/json' -// } -// }).then(response=>{ -// if(response.ok){ -// response.json().then(json=>{ -// callback(json); -// }) -// } else { -// if (DEBUG) console.log(e); -// } -// }).catch( e=>{ -// if (DEBUG) console.log(e); -// }) const request = new XMLHttpRequest(); request.addEventListener("load", ()=>{ var json = JSON.parse(request.response); @@ -54,7 +38,7 @@ async function archingKaosFetchText( url, callback ){ return callback(text); }) } else { - if (DEBUG) console.log(e); + console.log(e); } }) } diff --git a/src/js/arching-kaos-stellar-network.js b/src/js/arching-kaos-stellar-network.js index 9fb45b9..f3e1d94 100644 --- a/src/js/arching-kaos-stellar-network.js +++ b/src/js/arching-kaos-stellar-network.js @@ -1,34 +1,4 @@ -/* - * Array of all the menu-panes IDs - * TODO: Add to menuids stellar relevant -var menuids = [ - '#welcome-section', - '#about-section', - '#zchain-data-section', - '#news-section', - '#stats-section', - '#mixtapes-section', - '#chat-section', - '#mypage-section', - '#stellar-balances', - '#stellar-data-config', - '#arching-kaos-id', - '#files-section' -]; - */ - -// Here we store the participants found -// var participants = []; - -function getTrustlinesURL(){ - return activeSettings.horizonAddresses[activeSettings.horizonSelectedAddress]+ - 'assets?asset_code='+ - activeSettings.stellarAssetsForScanning[activeSettings.stellarDefaultAsset].code+ - '&asset_issuer='+ - activeSettings.stellarAssetsForScanning[activeSettings.stellarDefaultAsset].issuer; -} - function getNumberOfTrustlinesAndRenderThem(json){ var number = json._embedded.records[0].accounts.authorized; var stats = document.querySelector('.stellar-network').querySelector('summary'); @@ -37,24 +7,7 @@ function getNumberOfTrustlinesAndRenderThem(json){ stats.appendChild(small); archingKaosLog("Loading trustlines... Found "+number+"!"); progressPlaceholder.value++; -} - -/* - * Get Trustlines for ARCHINGKAOS asset - * Returns DOM element with number of trustlines - */ -function getTrustlines(){ - archingKaosLog("Loading trustlines..."); - archingKaosFetchJSON(getTrustlinesURL(), getNumberOfTrustlinesAndRenderThem); -} - -function getHoldersOfActiveAssetURL(){ - return activeSettings.horizonAddresses[activeSettings.horizonSelectedAddress]+ - 'accounts?asset='+ - activeSettings.stellarAssetsForScanning[activeSettings.stellarDefaultAsset].code+ - ':'+ - activeSettings.stellarAssetsForScanning[activeSettings.stellarDefaultAsset].issuer+ - '&limit=200'; + stellarParticipants=number; } function renderStellarAddressesAndProceed(json){ var stats = document.querySelector('.stellar-network'); @@ -71,6 +24,27 @@ function renderStellarAddressesAndProceed(json){ }) if (json._links.next) getHolders(json._links.next.href); } +function renderConfigurationIPNSLinkAndProceed(json, stellarAddress){ + var cnf = document.createElement("p"); + if(document.querySelector("#stellar-data-config-not-found")){ + document.querySelector("#stellar-data-config-not-found").hidden = true; + } + cnf.innerText = atob(json.value) + document.querySelector('#'+stellarAddress).appendChild(cnf) + document.querySelector('#'+stellarAddress).style="color: #3dbb3d;" + stellarNetworkConfiguredAddresses += 1; + getConfiguration(atob(json.value),stellarAddress) +} + +/* + * Get Trustlines for ARCHINGKAOS asset + * Returns DOM element with number of trustlines + */ +function getTrustlines(){ + archingKaosLog("Loading trustlines..."); + archingKaosFetchJSON(getTrustlinesURL(), getNumberOfTrustlinesAndRenderThem); +} + /* * Get addresses that trust the asset * Limit is 200 addresses cause horizon API limitations. @@ -102,7 +76,6 @@ function getHolders(a=0){ } archingKaosLog("Searching holders... Done!"); } -// getHolders(); function getStellarConfigurationVariableURL(stellarAddress){ return activeSettings.horizonAddresses[activeSettings.horizonSelectedAddress]+ @@ -112,15 +85,6 @@ function getStellarConfigurationVariableURL(stellarAddress){ activeSettings.stellarConfigVars[activeSettings.stellarDefaultConfig]; } -function renderConfigurationIPNSLinkAndProceed(json, stellarAddress){ - var cnf = document.createElement("p") - if(document.querySelector("#stellar-data-config-not-found")) document.querySelector("#stellar-data-config-not-found").hidden = true; - cnf.innerText = atob(json.value) - document.querySelector('#'+stellarAddress).appendChild(cnf) - document.querySelector('#'+stellarAddress).style="color: #3dbb3d;" - stellarNetworkConfiguredAddresses += 1; - getConfiguration(atob(json.value),stellarAddress) -} /* * Function that checks the address' variable 'config' to see * if it's set up. @@ -246,13 +210,11 @@ const retrievePublicKey = async () => { // Function that initiates the connection with the Wallet ( we just read ) function connect(){ - if (DEBUG) console.log("When pressed: "+stellar_connection_status); if ( stellar_connection_status === 1 ){ showStellar(); } else { const result = retrievePublicKey(); } - if (DEBUG) console.log("After "+stellar_connection_status); } function scanStellarNetworkForPeers(){ diff --git a/src/js/arching-kaos-tools.js b/src/js/arching-kaos-tools.js index d6d1935..92d851b 100644 --- a/src/js/arching-kaos-tools.js +++ b/src/js/arching-kaos-tools.js @@ -1,37 +1,10 @@ -/* - * A new feature for a new future: - * - * We will get `location.search` values to figure out where the visitor wants - * to go. - * - * We should then replace the menu links with these ones. - * - * We should also modify the existing menu mechanism to show/hide depending on - * the "route" we got from `location.search`. - * - */ - -// Irrelevant for now -if (DEBUG) console.log(window.location); - - -/* - * Array of all the menu-panes IDs -var menuids = [ - '#welcome-section', - '#about-section', - '#zchain-data-section', - '#news-section', - '#stats-section', - '#mixtapes-section', - '#chat-section', - '#mypage-section', - '#stellar-balances', - '#stellar-data-config', - '#arching-kaos-id', - '#files-section' -]; -*/ +function getArrayLength(array){ + var len = 0; + for ( e in array ) { + len++; + } + return len; +} function akidRenderAndProceed(json, stellarAddress){ /* Could be json object with @@ -41,6 +14,7 @@ function akidRenderAndProceed(json, stellarAddress){ * - nickname * } * - zchain + * - zlatest */ var divs = document.querySelector('#'+stellarAddress) if(json.genesis){ @@ -63,12 +37,93 @@ function akidRenderAndProceed(json, stellarAddress){ p.innerText="zchain: " +json.zchain divs.appendChild(p) } + if(json.zlatest){ + var p = document.createElement("p") + p.innerText="zlatest: " +json.zlatest + divs.appendChild(p) + } participants[stellarAddress]=json; progressPlaceholder.value++; -// zseek(json.zchain); zseek(json.zchain,stellarAddress,json); } +function renderZblockAndProceed(json, params){ + const [zblockIPFSHash, zchainIPNSLink, zblockElement] = params; + /* Could be json object with + * - block + * - block_signature + */ + // var divs = document.querySelector('#zchain-data-section'); + if(json.block){ + var p = document.createElement("p"); + p.innerText="Block: " +json.block; + p.id=zblockIPFSHash; + zblockElement.appendChild(p); + } + if(json.block_signature){ + var p = document.createElement("p"); + p.innerText="Signature: " +json.block_signature; + zblockElement.appendChild(p); + } + progressPlaceholder.max++; + progressPlaceholder.value++; + seekblock(json.block,zblockIPFSHash,zchainIPNSLink,json); +} +function blockRenderAndProceed(json, params){ + const [zchainIPNSLink, zblockIPFSHash, blockIPFSHash, zblockObject] = params; + /* 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.innerText="Action: " +json.action; + if(detailsPlace!== null) detailsPlace.appendChild(p); + } + if(json.detach){ + var p = document.createElement("p"); + p.innerText="Detach: " +json.detach; + if(detailsPlace!== null) detailsPlace.appendChild(p); + } + if(json.gpg){ + var p = document.createElement("p"); + p.innerText="GPG: " +json.gpg; + if(detailsPlace!== null) detailsPlace.appendChild(p); + } + if(json.data){ + var p = document.createElement("p"); + var a = document.createElement("a"); + a.href = getIPFSURL(json.data); + a.innerText = json.data; + p.innerText="Data: "; + p.appendChild(a); + if(detailsPlace!== null) detailsPlace.appendChild(p); + } + if(json.timestamp){ + var p = document.createElement("p"); + p.innerText="Timestamp: " +json.timestamp; + if(detailsPlace!== null) detailsPlace.appendChild(p); + } + if(json.previous){ + var p = document.createElement("p"); + p.innerText="Previous: " +json.previous; + if(detailsPlace!== null) detailsPlace.appendChild(p); + } + progressPlaceholder.value++; + exe(json.action,json.data,json,zblockIPFSHash,zchainIPNSLink,zblockObject); + if ( checkIfGenesis(json.previous) ){ + archingKaosLog("Done loading " + zchainIPNSLink + " zchain!") + progressPlaceholder.value++; + zchain[zchainIPNSLink] = {loading: "completed"}; + } else { + seekzblock(json.previous, zchainIPNSLink); + } +} /* * Function that gets nickname and parses the config variable. * @@ -81,13 +136,6 @@ function getConfiguration(akidIPNSLink,stellarAddress){ archingKaosFetchJSON(getIPNSURL(akidIPNSLink), akidRenderAndProceed, stellarAddress) } -function getIPNSURL(ipnsKey){ - return activeSettings.ipfsGatewayAddress[activeSettings.ipfsSelectedGatewayAddress]+'ipns/'+ipnsKey; -} - -function getIPFSURL(ipfsHash){ - return activeSettings.ipfsGatewayAddress[activeSettings.ipfsSelectedGatewayAddress]+'ipfs/'+ipfsHash; -} /* * Function to seek Zblocks @@ -117,10 +165,11 @@ function zseek(zchainIPNSLink,stellarAddress,j){ }).then(response=>{ if(response.ok){ var zblock = ""; - if ( DEBUG ) console.log(response); if ( response.headers.has('Etag') ){ zblock = response.headers.get('Etag').replace(/"/g,''); zchain[zchainIPNSLink] = {loading : "started"}; + zchainsFound++; + zchains[zchainIPNSLink] = []; // console.log(zchain); // callHereToSetUpListenerFor(zchain[zchainIPNSLink]); } @@ -152,31 +201,6 @@ function zseek(zchainIPNSLink,stellarAddress,j){ }) } -// seeks a zblock obviously. another double function -// TODO: figure out why the second one exists - -function renderZblockAndProceed(json, params){ - const [zblockIPFSHash, zchainIPNSLink, zblockElement] = params; - /* Could be json object with - * - block - * - block_signature - */ - // var divs = document.querySelector('#zchain-data-section'); - if(json.block){ - var p = document.createElement("p"); - p.innerText="Block: " +json.block; - p.id=zblockIPFSHash; - zblockElement.appendChild(p); - } - if(json.block_signature){ - var p = document.createElement("p"); - p.innerText="Signature: " +json.block_signature; - zblockElement.appendChild(p); - } - progressPlaceholder.max++; - progressPlaceholder.value++; - seekblock(json.block,zblockIPFSHash,zchainIPNSLink); -} /* * Function gets ZBLOCK and parses it * @@ -185,8 +209,6 @@ function renderZblockAndProceed(json, params){ * Proceeds to seek the block found */ function seekzblock(zblockIPFSHash,zchainIPNSLink){ - if (DEBUG) console.log("Zblock:: "+zblockIPFSHash); - if (DEBUG) console.log("Zchain:: "+zchainIPNSLink); var divs = document.querySelector('#zd-' + zchainIPNSLink); var zblockElement = document.createElement("article"); zblockElement.id = 'zb-' + zblockIPFSHash; @@ -201,63 +223,14 @@ function seekzblock(zblockIPFSHash,zchainIPNSLink){ archingKaosFetchJSON(getIPFSURL(zblockIPFSHash), renderZblockAndProceed, [zblockIPFSHash, zchainIPNSLink, zblockElement]); } -function blockRenderAndProceed(json, params){ - const [zchainIPNSLink, zblockIPFSHash, blockIPFSHash, j] = params; - /* 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.innerText="Action: " +json.action; - if(detailsPlace!== null) detailsPlace.appendChild(p); - } - if(json.detach){ - var p = document.createElement("p"); - p.innerText="Detach: " +json.detach; - if(detailsPlace!== null) detailsPlace.appendChild(p); - } - if(json.gpg){ - var p = document.createElement("p"); - p.innerText="GPG: " +json.gpg; - if(detailsPlace!== null) detailsPlace.appendChild(p); - } - if(json.data){ - var p = document.createElement("p"); - var a = document.createElement("a"); - a.href = getIPFSURL(json.data); - a.innerText = json.data; - p.innerText="Data: "; - p.appendChild(a); - if(detailsPlace!== null) detailsPlace.appendChild(p); - } - if(json.timestamp){ - var p = document.createElement("p"); - p.innerText="Timestamp: " +json.timestamp; - if(detailsPlace!== null) detailsPlace.appendChild(p); - } - if(json.previous){ - var p = document.createElement("p"); - p.innerText="Previous: " +json.previous; - if(detailsPlace!== null) detailsPlace.appendChild(p); - } - progressPlaceholder.value++; - exe(json.action,json.data,json,zblockIPFSHash,zchainIPNSLink,j); - if(json.previous!="QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwQH"){ - if (DEBUG) console.log(json.previous, zchainIPNSLink); - seekzblock(json.previous, zchainIPNSLink); +function checkIfGenesis(zblockIPFSHash){ + if(zblockIPFSHash==="QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwQH"){ + return true; } else { - archingKaosLog("Done loading " + zchainIPNSLink + " zchain!") - progressPlaceholder.value++; - zchain[zchainIPNSLink] = {loading: "completed"}; - + return false; } } + /* * Seeks a block and parses it. * @@ -265,13 +238,11 @@ function blockRenderAndProceed(json, params){ * * Proceeds to execute the block. */ -function seekblock(blockIPFSHash,zblockIPFSHash,zchainIPNSLink,j){ - if (DEBUG) console.log("THE CHAIN: " + zchainIPNSLink); - if (DEBUG) console.log("THE ZBLOCK: " + zblockIPFSHash); +function seekblock(blockIPFSHash,zblockIPFSHash,zchainIPNSLink,zblockObject){ detailsPlace = document.querySelector('#zb-'+zblockIPFSHash); archingKaosLog("Seeking block "+blockIPFSHash+"..."); progressPlaceholder.max++; - archingKaosFetchJSON(getIPFSURL(blockIPFSHash), blockRenderAndProceed, [zchainIPNSLink, zblockIPFSHash, blockIPFSHash, j]); + archingKaosFetchJSON(getIPFSURL(blockIPFSHash), blockRenderAndProceed, [zchainIPNSLink, zblockIPFSHash, blockIPFSHash, zblockObject]); } /* @@ -279,8 +250,7 @@ function seekblock(blockIPFSHash,zblockIPFSHash,zchainIPNSLink,j){ * * Returns the result of execution on the proper page in DOM */ -function exe(action,dataIPFSHash,blockObject,zblockIPFSHash,zchainIPNSLink,z){ - if (DEBUG) console.log("Executing...",action,dataIPFSHash,blockObject,zblockIPFSHash,zchainIPNSLink,z) +function exe(action,dataIPFSHash,blockObject,zblockIPFSHash,zchainIPNSLink,zblockObject){ archingKaosLog("Render ZBLOCK "+zblockIPFSHash+" as " + action + " ..."); fetch(getIPFSURL(dataIPFSHash), { method:'GET', @@ -389,17 +359,66 @@ function exe(action,dataIPFSHash,blockObject,zblockIPFSHash,zchainIPNSLink,z){ radio.appendChild(rs); art.appendChild(audio); audio.addEventListener( "loadedmetadata", ()=>{ - console.log(zblockIPFSHash+"'s duration is: "+ audio.duration + " Ceiled: " + Math.ceil(audio.duration) + " added on " + blockObject.timestamp + " or " + json.timestamp + " DIFF: " + (blockObject.timestamp - json.timestamp)); + if ( mixtapes[zblockIPFSHash] === undefined ){ + mixtapes[zblockIPFSHash]={ + zblock:zblockIPFSHash, + block:zblockObject.block, + block_signature:zblockObject.block_signature, + action:action, + previous:blockObject.previous, + data:blockObject.data, + dataExpansion:json, + detach:blockObject.detach, + gpg:blockObject.gpg, + timestamp:blockObject.timestamp, + audioDuration:audio.duration + }; + } + if ( zchainsFound === stellarNetworkConfiguredAddresses ) { + var x = 0; + console.log("::HIT::"); + for ( element in zchain ) { + console.log("::HAT::") + if ( zchain[element].loading === "completed" ){ + x++; + console.log("::HET::") + } + } + if ( x === stellarNetworkConfiguredAddresses ) { + sortedMixtapes = mixtapes.sort(function(a,b){return a.timestamp - b.timestamp}) + console.log("::HUT::") + + } + } + console.log( + zblockIPFSHash+"'s duration is: "+ + audio.duration + + " Ceiled: " + Math.ceil(audio.duration) + + " added on " + blockObject.timestamp + " or " + + json.timestamp + + " DIFF: " + (blockObject.timestamp - json.timestamp) + ); }, false ); } if (document.querySelector("#mixtapes-sec-not-found")) document.querySelector("#mixtapes-sec-not-found").hidden=true; divs.appendChild(art); } else { - if (DEBUG) console.log("Found unknown module/action: "+action); archingKaosLog(action + " module not found"); } - // seekblock(json.block) + zchains[zchainIPNSLink].push({ + zblock:zblockIPFSHash, + block:zblockObject.block, + block_signature:zblockObject.block_signature, + action:action, + previous:blockObject.previous, + data:blockObject.data, + dataExpansion:json, + detach:blockObject.detach, + gpg:blockObject.gpg, + timestamp:blockObject.timestamp + }); + data[dataIPFSHash]=json; progressPlaceholder.max++; progressPlaceholder.value++; }) @@ -434,7 +453,6 @@ function getipfstext(ipfsHash, articleid){ } progressPlaceholder.max++; progressPlaceholder.value++; - // seekblock(json.block) }) } }) diff --git a/src/js/environment-setup.js b/src/js/environment-setup.js index 75431f7..30b102d 100644 --- a/src/js/environment-setup.js +++ b/src/js/environment-setup.js @@ -1,11 +1,17 @@ - -const DEBUG = false - var mixtapeIds = []; +var mixtapes = []; +var sortedMixtapes = []; +var zchainsFound = 0; var holders = []; +var participants = []; var stellarNetworkConfiguredAddresses = 0; -var zchain = new Array; +var stellarParticipants = 0; +var zchain = []; var zchains = new Array; +var zblocks = new Array; +var blocks = new Array; +var data = new Array; +var akid = new Array; var body = document.querySelector('body'); var pageLayout = document.querySelector('.page-layout'); var mainContainer = document.querySelector('.main'); @@ -48,8 +54,6 @@ var logsAreaElement = document.querySelector("#logs-area-element"); var radio = document.querySelector("#radio-player"); var radioButton = document.querySelector("#radio-button-controller"); -// Here we store the participants found -var participants = []; /* * Get addresses that trust the asset * Limit is 200 addresses cause horizon API limitations. diff --git a/src/js/url-generators.js b/src/js/url-generators.js new file mode 100644 index 0000000..d92592d --- /dev/null +++ b/src/js/url-generators.js @@ -0,0 +1,36 @@ +/* + * URL generators + * + * This file contains functions that generate URL + * based on the activeSettings. + * + * Apparently, we need `arching-kaos-web-ui-settings` to be loaded first + * + */ + +function getIPNSURL(ipnsKey){ + return activeSettings.ipfsGatewayAddress[activeSettings.ipfsSelectedGatewayAddress]+'ipns/'+ipnsKey; +} + +function getIPFSURL(ipfsHash){ + return activeSettings.ipfsGatewayAddress[activeSettings.ipfsSelectedGatewayAddress]+'ipfs/'+ipfsHash; +} + +function getHoldersOfActiveAssetURL(){ + return activeSettings.horizonAddresses[activeSettings.horizonSelectedAddress]+ + 'accounts?asset='+ + activeSettings.stellarAssetsForScanning[activeSettings.stellarDefaultAsset].code+ + ':'+ + activeSettings.stellarAssetsForScanning[activeSettings.stellarDefaultAsset].issuer+ + '&limit=200'; +} + +function getTrustlinesURL(){ + return activeSettings.horizonAddresses[activeSettings.horizonSelectedAddress]+ + 'assets?asset_code='+ + activeSettings.stellarAssetsForScanning[activeSettings.stellarDefaultAsset].code+ + '&asset_issuer='+ + activeSettings.stellarAssetsForScanning[activeSettings.stellarDefaultAsset].issuer; +} + +// vim: tabstop=4 shiftwidth=4 expandtab softtabstop=4 |