diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..62c8935 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea/ \ No newline at end of file diff --git a/scripts/pools.js b/scripts/pools.js index b6d16fb..124280b 100644 --- a/scripts/pools.js +++ b/scripts/pools.js @@ -23,16 +23,13 @@ function shuffleArray(array) { return array; } -// Exposes the pools as a chacheable object for use anywhere -function getCachedPools(success) -{ - if (_poolCache == null) - { +// Exposes the pools as a cacheable object for use anywhere +function getCachedPools(success) { + if (_poolCache == null) { // Promise-interface, so make sure to call success separately in else logic - $.getJSON(_poolURL, function(data) { + $.getJSON(_poolURL, function (data) { _poolCache = data; - if (_poolCache == null) - { + if (_poolCache == null) { // Something went wrong console.log("_poolCache is null, are you able to reach \'" + _poolURL + "\'?"); } @@ -45,8 +42,7 @@ function getCachedPools(success) } // Returns a link with a stylized ticker box colored depending on saturation -function poolTicker(poolExtData) -{ +function poolTicker(poolExtData, hexId, ticker) { // Honestly, this should come from a .css var font = "sans-serif"; var border = "border-radius: 8px; border-style: hidden;" @@ -54,64 +50,62 @@ function poolTicker(poolExtData) var height = "70px"; var margin = "5px"; - if (poolExtData.data.saturated >= 0 && poolExtData.data.saturated <= 0.6) - { - return "" + + if (poolExtData.data.saturation >= 0 && poolExtData.data.saturation <= 0.6) { + return "" + `` + - "" + - "" + + "" + + "" + "
" + poolExtData.data.db_ticker + "
" + (poolExtData.data.saturated * 100).toFixed(2) + "%
" + ticker + "
" + (poolExtData.data.saturation * 100).toFixed(2) + "%
"; } - if (poolExtData.data.saturated > 0.6 && poolExtData.data.saturated <= 0.8) - { - return "" + - `` + - "" + - "" + + if (poolExtData.data.saturation > 0.6 && poolExtData.data.saturation <= 0.8) { + return "" + + `
" + poolExtData.data.db_ticker + "
" + (poolExtData.data.saturated * 100).toFixed(2) + "%
` + + "" + + "" + "
" + ticker + "
" + (poolExtData.data.saturation * 100).toFixed(2) + "%
"; - } - if (poolExtData.data.saturated > 0.8 && poolExtData.data.saturated <= 0.95) - { - return "" + - `` + - "" + - "" + + } + if (poolExtData.data.saturation > 0.8 && poolExtData.data.saturation <= 0.95) { + return "" + + `
" + poolExtData.data.db_ticker + "
" + (poolExtData.data.saturated * 100).toFixed(2) + "%
` + + "" + + "" + "
" + ticker + "
" + (poolExtData.data.saturation * 100).toFixed(2) + "%
"; } - if (poolExtData.data.saturated > 0.95 && poolExtData.data.saturated <= 100) - { - return "" + - `` + - "" + - "" + + if (poolExtData.data.saturation > 0.95 && poolExtData.data.saturation <= 100) { + return "" + + `
" + poolExtData.data.db_ticker + "
" + (poolExtData.data.saturated * 100).toFixed(2) + "%
` + + "" + + "" + "
" + ticker + "
" + (poolExtData.data.saturation * 100).toFixed(2) + "%
"; } - - return "
Missing data
"; + return "
\"" + ticker + "\"
" } -function randPoolTicker(element) -{ - getCachedPools(function(pools) { +function randPoolTicker(element) { + getCachedPools(function (pools) { // Select random pool - randPool = pools[Math.floor(Math.random()*pools.length)]; - - $.getJSON('https://js.adapools.org/pools/' + randPool.poolId + '/summary.json', function(poolExtData) { - element.html(poolTicker(poolExtData)); + randPool = pools[Math.floor(Math.random() * pools.length)]; + $.getJSON('https://js.cexplorer.io/api-static/pool/hex2bech.json', function (hexToBech) { + let bechID = hexToBech.data[randPool.poolId]; + // element.html(something); + $.getJSON('https://js.cexplorer.io/api-static/pool/' + bechID + '.json', function (poolExtData) { + element.html(poolTicker(poolExtData, randPool.poolId, randPool.ticker)); + }); }); }); } -function populatePoolTickersRandomly(element) -{ - getCachedPools(function(pools) { +function populatePoolTickersRandomly(element) { + getCachedPools(function (pools) { // Shuffle pools randomly shuffledPools = shuffleArray(pools); - - $.each(shuffledPools, function(key, pool) { - $.getJSON('https://js.adapools.org/pools/' + pool.poolId + '/summary.json', function(poolExtData) { - element.append(poolTicker(poolExtData)); - }); + $.getJSON('https://js.cexplorer.io/api-static/pool/hex2bech.json', function (hexToBech) { + $.each(shuffledPools, function (key, pool) { + let bechID = hexToBech.data[pool.poolId]; + $.getJSON('https://js.cexplorer.io/api-static/pool/' + bechID + '.json', function (poolExtData) { + element.append(poolTicker(poolExtData, pool.poolId, pool.ticker)); + }); + }); }); }); } \ No newline at end of file