Browse Source

auto-calculate on input, default date, display the rate

pull/1/head
Mayel de Borniol 6 years ago
parent
commit
e4735b9d65
2 changed files with 23 additions and 5 deletions
  1. +4
    -0
      index.html
  2. +19
    -5
      index.js

+ 4
- 0
index.html

@ -36,9 +36,11 @@
<div class="col-sm-2"> <div class="col-sm-2">
FC FC
</div> </div>
<!--
<div class="col-sm-5"> <div class="col-sm-5">
<button onclick="calculateEuros()" type="button" class="btn btn-outline-primary">Calculate euros</button> <button onclick="calculateEuros()" type="button" class="btn btn-outline-primary">Calculate euros</button>
</div> </div>
-->
</div> </div>
<br> <br>
<div class="row"> <div class="row">
@ -48,9 +50,11 @@
<div class="col-sm-2"> <div class="col-sm-2">
</div> </div>
<!--
<div class="col-sm-5"> <div class="col-sm-5">
<button onclick="calculateFaircoins()" type="button" class="btn btn-outline-primary">Calculate faircoins</button> <button onclick="calculateFaircoins()" type="button" class="btn btn-outline-primary">Calculate faircoins</button>
</div> </div>
-->
</div> </div>
<br> <br>
<div class="row"> <div class="row">

+ 19
- 5
index.js

@ -6,13 +6,25 @@ var priceData = "";
//get the dataset //get the dataset
$(document).ready(function() { $(document).ready(function() {
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: "http://api.fairplayground.info/rawdata/faircoin_prices.csv", url: "http://api.fairplayground.info/rawdata/faircoin_prices.csv",
dataType: "text", dataType: "text",
success: function(data) {processData(data);}
success: processData
}); });
$('#inputFaircoin').on('input', calculateEuros);
$('#inputEuro').on('input', calculateFaircoins);
$('#inputDate').on('input', calculateEuros);
var strDate = new Date().toISOString().slice(0,10);
$('#inputDate').val(strDate);
}); });
function csvToArray(csv) { function csvToArray(csv) {
var a1 = csv.split("\n"); var a1 = csv.split("\n");
var r = []; var r = [];
@ -22,6 +34,7 @@ function csvToArray(csv) {
} }
return(r); return(r);
} }
function processData(data) { function processData(data) {
priceData = csvToArray(data); priceData = csvToArray(data);
}; };
@ -53,9 +66,10 @@ function calculateEuros() {
var euros = faircoins * selectedPriceData[3]; var euros = faircoins * selectedPriceData[3];
document.getElementById("inputEuro").value= euros; document.getElementById("inputEuro").value= euros;
document.getElementById("result").innerHTML = faircoins + "FC, are " + euros + "€";
toastr.success(faircoins + "FC, are " + euros + "€");
document.getElementById("result").innerHTML = "The official rate was " + parseFloat(selectedPriceData[3]).toString() + " <p>" + faircoins + " FAIR were worth " + euros + " €";
toastr.success(faircoins + " FC, were " + euros + " €");
} }
function calculateFaircoins() { function calculateFaircoins() {
document.getElementById("result").innerHTML=""; document.getElementById("result").innerHTML="";
var euros = document.getElementById("inputEuro").value; var euros = document.getElementById("inputEuro").value;
@ -83,6 +97,6 @@ function calculateFaircoins() {
var faircoins = euros / selectedPriceData[3]; var faircoins = euros / selectedPriceData[3];
document.getElementById("inputFaircoin").value= faircoins; document.getElementById("inputFaircoin").value= faircoins;
document.getElementById("result").innerHTML = euros + "€, are " + faircoins + "FC";
toastr.success(euros + "€, are " + faircoins + "FC");
document.getElementById("result").innerHTML = "The official rate was " + parseFloat(selectedPriceData[3]).toString() + " <p>" + euros + " € were worth " + faircoins + " FC";
toastr.success(euros + "€, are " + faircoins + " FC");
} }

Loading…
Cancel
Save