Skip to content

Commit

Permalink
Change network API from chainradar to moneroblocks
Browse files Browse the repository at this point in the history
  • Loading branch information
bigreddmachine committed Sep 26, 2016
1 parent 2ab899e commit d245be2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
42 changes: 24 additions & 18 deletions lib/js/network.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function updateNetworkStats() {
// Get Blockchain Explorer Info:
var bchain = new XMLHttpRequest();
bchain.open("GET", "http://chainradar.com/api/v1/mro/status", true);
bchain.open("GET", "http://moneroblocks.info/api/get_stats/", true);
bchain.onreadystatechange = function() {
if (bchain.readyState == 4) {
setChainInfo(JSON.parse(bchain.responseText));
Expand All @@ -12,26 +12,32 @@ function updateNetworkStats() {

function setChainInfo(info) {
// Use parsed data to update Network information:
var totalCoins = coinsFromAtomic(info.alreadyGeneratedCoins);
var total_emission = info.total_emission;
var totalCoins = Number(total_emission.substr(0, total_emission.length-12) + '.'
+ total_emission.substr(total_emission.length-12, total_emission.length));
getBTCrates(totalCoins);


var last_reward = info.last_reward;
var reward = Number(last_reward.substr(0, last_reward.length-12) + '.'
+ last_reward.substr(last_reward.length-12, last_reward.length));

document.getElementById('difficulty').textContent = numberWithCommas(info.difficulty);
document.getElementById('blockheight').textContent = info.height;
document.getElementById('hashrate').textContent = (info.instantHashrate/1000000).toFixed(3) + ' Mh/s';
document.getElementById('hashrate').textContent = (info.hashrate/1000000).toFixed(3) + ' Mh/s';
document.getElementById('totalsupply').textContent = numberWithCommas(totalCoins.toFixed(3)) + ' XMR';
document.getElementById('blockreward').textContent = coinsFromAtomic(info.reward).toFixed(3) + ' XMR';
document.getElementById('blocktime').textContent = unixTimeToDate(info.timestamp);
document.getElementById('blockreward').textContent = reward.toFixed(3) + ' XMR';
document.getElementById('blocktime').textContent = unixTimeToDate(Number(info.last_timestamp));

var a_height = document.createElement('a');
a_height.href = 'http://chainradar.com/xmr/block/' + info.height;
a_height.href = 'http://moneroblocks.info/block/' + info.height;
a_height.target = '_blank';
a_height.class = 'title';

var a_hashrate = document.createElement('a');
a_hashrate.href = 'http://minexmr.com/pools.html';
a_hashrate.href = 'https://monerohash.com/#network';
a_hashrate.target = '_blank';
a_hashrate.class = 'title';

document.getElementById('blockheight').appendChild(a_height).appendChild(a_height.previousSibling);
document.getElementById('hashrate').appendChild(a_hashrate).appendChild(a_hashrate.previousSibling);
}
Expand All @@ -50,7 +56,7 @@ function getBTCrates(totalCoins) {

function getHistoricalBTC(totalCoins,deskresp) {
var USDtoBTC_now = deskresp.bpi.USD.rate_float;

// Get BTXC Historical data from Coindesk:
var coindesk = new XMLHttpRequest();
coindesk.open("GET", "https://api.coindesk.com/v1/bpi/historical/close.json?for=yesterday", true);
Expand All @@ -61,7 +67,7 @@ function getHistoricalBTC(totalCoins,deskresp) {
var day = Object.keys(bpi)[0];
var USDtoBTC_open = bpi[day];
var percentUSDtoBTC = (USDtoBTC_now)/USDtoBTC_open;

// Get XMR historical data from Poloniex:
var t_today = new Date();
var t_starttoday = t_today.setUTCHours(0,0,0,0) / 1000;
Expand All @@ -72,23 +78,23 @@ function getHistoricalBTC(totalCoins,deskresp) {
var poloresp = JSON.parse(polo.responseText);
var BTCtoXMR_open = poloresp[0].open;
var BTCtoXMR_now = poloresp[poloresp.length-1].close;

// Calculate XMR Prices/Cap in various denominations:
var USDtoXMR_open = USDtoBTC_open * BTCtoXMR_open;
var rateBTC = BTCtoXMR_now;
var rateUSD = BTCtoXMR_now * USDtoBTC_now;
var rateGBP = BTCtoXMR_now * deskresp.bpi.GBP.rate_float;
var rateEUR = BTCtoXMR_now * deskresp.bpi.EUR.rate_float;
var marketCapUSD = rateUSD * totalCoins;

// Fill in values on popup:
document.getElementById('USDtoXMR').textContent = rateUSD.toFixed(4);
document.getElementById('openUSDtoXMR').textContent = USDtoXMR_open.toFixed(4);
document.getElementById('GBPtoXMR').textContent = rateGBP.toFixed(4);
document.getElementById('EURtoXMR').textContent = rateEUR.toFixed(4);
document.getElementById('BTCtoXMR').textContent = Number(rateBTC).toFixed(5);
document.getElementById('CapUSD').textContent = '$' + numberWithCommas(marketCapUSD.toFixed(2));

// XMR Percent Gain/Loss in USD:
var percentUSDtoXMR = (rateUSD/USDtoXMR_open - 1) * 100;
document.getElementById('percentUSDtoXMR').textContent = '(' + percentUSDtoXMR.toFixed(2) + '%)';
Expand All @@ -97,7 +103,7 @@ function getHistoricalBTC(totalCoins,deskresp) {
} else {
document.getElementById('percentUSDtoXMR').style.color = "#bb0000";
}

// Show price info:
document.getElementById('usdtable').style.display = 'inline-block';
document.getElementById('captable').style.display = 'inline-block';
Expand All @@ -107,4 +113,4 @@ function getHistoricalBTC(totalCoins,deskresp) {
}
}
coindesk.send();
}
}
3 changes: 1 addition & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
]
},
"permissions": [
"storage",
"*://chainradar.com/"
"storage"
]
}

0 comments on commit d245be2

Please sign in to comment.