Fixed LBC query issue on YouTbe Sync page

This commit is contained in:
ポール ウェッブ 2019-02-26 17:35:43 -06:00
parent 29e1458b17
commit 5492a5e4c8

View file

@ -54,23 +54,26 @@ App.prototype._onLoad = function() {
App.prototype._getDataFromCoinMarketCap = function(e) { App.prototype._getDataFromCoinMarketCap = function(e) {
this._xhr = new XMLHttpRequest(); this._xhr = new XMLHttpRequest();
this._xhr.addEventListener('readystatechange',this._onReadyStateChange.bind(this),false); this._xhr.addEventListener('readystatechange',this._onReadyStateChange.bind(this),false);
this._xhr.open('GET','https://api.coinmarketcap.com/v1/ticker/library-credit/'); this._xhr.open('GET','https://api.lbry.io/lbc/exchange_rate');
this._xhr.send(); this._xhr.send();
}; };
App.prototype._onReadyStateChange = function(e) { App.prototype._onReadyStateChange = function(e) {
if (this._xhr.readyState == 4) { if (this._xhr.readyState === 4) {
if (this._xhr.status == 200) { if (this._xhr.status === 200) {
var response = JSON.parse(this._xhr.responseText); const response = JSON.parse(this._xhr.responseText);
var price = parseFloat(response[0].price_usd); const lines = Array.prototype.slice.call(document.getElementsByClassName('line'),0);
var lines = Array.prototype.slice.call(document.getElementsByClassName('line'),0); const price = parseFloat(response.data.lbc_usd);
lines.forEach(function(line) { lines.forEach(function(line) {
var subscriber = line.getElementsByTagName('p')[0]; const subscriber = line.getElementsByTagName('p')[0];
var monthly = line.getElementsByTagName('p')[1]; const monthly = line.getElementsByTagName('p')[1];
var amount = line.getElementsByTagName('p')[2]; const amount = line.getElementsByTagName('p')[2];
var total = parseFloat(monthly.innerHTML.replace(new RegExp(',','g'),'')) * price; const total = parseFloat(monthly.innerHTML.replace(new RegExp(',', 'g'), '')) * price;
amount.innerHTML = this._addCommas(total.toFixed(2)) + ' <i>USD</i>'; amount.innerHTML = this._addCommas(total.toFixed(2)) + ' <i>USD</i>';
},this); },this);
document.getElementsByClassName('current-value')[0].innerHTML = "(" + price.toFixed(4) + " USD)"; document.getElementsByClassName('current-value')[0].innerHTML = "(" + price.toFixed(4) + " USD)";
} }
} }
@ -242,7 +245,5 @@ Line.prototype.draw = function(from,to) {
// Let's start :) // Let's start :)
var app = new App(); var app = new App();