code cleanup

This commit is contained in:
Nathan Parikh 2017-10-11 09:22:46 -05:00
parent c0eb800259
commit 649a26299c

View File

@ -48,12 +48,13 @@ function append(parent, el) {
const ul = document.getElementById('prices'); // Get the list where we will place coins const ul = document.getElementById('prices'); // Get the list where we will place coins
const portfolio_ul = document.getElementById('portfolio-list');; const portfolio_ul = document.getElementById('portfolio-list');;
var url = 'https://min-api.cryptocompare.com/data/pricemultifull?fsyms='+settings.get('user.coins') +'&tsyms='+base +'&extraParams=crypto-price-widget'; var url = 'https://min-api.cryptocompare.com/data/pricemultifull?fsyms='+settings.get('user.coins') +'&tsyms='+base +'&extraParams=crypto-price-widget';
var pinCheck = document.getElementById("pin-to-top"); var pinCheck = document.getElementById("pin-to-top");
function clearData() { function clearData() {
ul.innerHTML = ''; ul.innerHTML = '';
clearTimeout(appRefresh); clearTimeout(appRefresh);
} }
function initData() { function initData() {
//need to redeclare the url variable here to grab the latest user coins, etc. //need to redeclare the url variable here to grab the latest user coins, etc.
var url = 'https://min-api.cryptocompare.com/data/pricemultifull?fsyms='+settings.get('user.coins') +'&tsyms='+base +'&extraParams=crypto-price-widget'; var url = 'https://min-api.cryptocompare.com/data/pricemultifull?fsyms='+settings.get('user.coins') +'&tsyms='+base +'&extraParams=crypto-price-widget';
@ -62,9 +63,7 @@ function initData() {
function(response) { function(response) {
// Examine the response // Examine the response
response.json().then(function(data) { response.json().then(function(data) {
//console.log(url);
console.log(url);
//console.log(data);
let pricesDISPLAY = data.DISPLAY; // display for everything except coin symbol let pricesDISPLAY = data.DISPLAY; // display for everything except coin symbol
let pricesRAW = data.RAW; // raw to get "BTC" instead of bitcoin symbol let pricesRAW = data.RAW; // raw to get "BTC" instead of bitcoin symbol
@ -77,10 +76,7 @@ function initData() {
sym = createNode('span'); sym = createNode('span');
li.setAttribute("class", "price"); li.setAttribute("class", "price");
li.setAttribute("id", "coin-"+[key]); li.setAttribute("id", "coin-"+[key]);
//alert("coin-"+[key])
//console.log(settings.get('coin.'+[key]+'.order'));
//span = document.querySelector("#coin-"+[key]+" span");
span.setAttribute("class", "draggable"); span.setAttribute("class", "draggable");
//when adding a new coin, default sortorder to 999 //when adding a new coin, default sortorder to 999
@ -96,7 +92,6 @@ function initData() {
append(ul, li); append(ul, li);
i++; i++;
} //for } //for
//console.log(data.RAW.BTC.USD.PRICE)
//sort your coins //sort your coins
sortable('#prices', { sortable('#prices', {
@ -213,7 +208,6 @@ function updateData() {
let li = document.getElementById("coin-"+[key]), let li = document.getElementById("coin-"+[key]),
span = document.querySelector("#coin-"+[key]+" span"); span = document.querySelector("#coin-"+[key]+" span");
let coinSymbol = coinRAW[base].FROMSYMBOL; let coinSymbol = coinRAW[base].FROMSYMBOL;
let coinRate = coinDISPLAY[base].PRICE.replace(/ /g,''); //.replace(/ /g,'') removes space after $ let coinRate = coinDISPLAY[base].PRICE.replace(/ /g,''); //.replace(/ /g,'') removes space after $
@ -254,7 +248,6 @@ function updateData() {
if(quantityNumber != null) { if(quantityNumber != null) {
quantityTotal = parseFloat(coinRate.replace(regp, '')) * parseFloat(quantityNumber.replace(regp, '')); quantityTotal = parseFloat(coinRate.replace(regp, '')) * parseFloat(quantityNumber.replace(regp, ''));
} }
// sum of all total coin values // sum of all total coin values
portfolioSum += quantityTotal; portfolioSum += quantityTotal;
// put sum into the markup // put sum into the markup
@ -318,12 +311,8 @@ initData();
document.getElementById('saveCoins').onclick = function(){ document.getElementById('saveCoins').onclick = function(){
var coinForm = document.getElementById('coinlist'); var coinForm = document.getElementById('coinlist');
var selchb = getSelectedChbox(coinForm); // gets the array returned by getSelectedChbox() var selchb = getSelectedChbox(coinForm); // gets the array returned by getSelectedChbox()
//alert(selchb);
settings.set('user.coins', selchb); settings.set('user.coins', selchb);
//clear and reload
// just reloading the entire app because I have yet to figure out how to add/remove a coin from the primary list without a page reload
//location.reload(false);
clearData(); clearData();
initData(); initData();
} }