@ -0,0 +1,3 @@ |
|||||
|
node_modules |
||||
|
package-lock.json |
||||
|
data |
@ -0,0 +1,5 @@ |
|||||
|
# faircoin-calculator |
||||
|
|
||||
|
Very simple Faircoin calculator. |
||||
|
|
||||
|
The price dataset is getted from http://api.fairplayground.info/rawdata/faircoin_prices.csv |
@ -0,0 +1,82 @@ |
|||||
|
<!DOCTYPE html> |
||||
|
<html lang="en"> |
||||
|
|
||||
|
<head> |
||||
|
<title>Faircoin-calculator</title> |
||||
|
<meta charset="utf-8"> |
||||
|
<meta name="viewport" content="width=device-width, initial-scale=1"> |
||||
|
|
||||
|
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"> |
||||
|
</head> |
||||
|
|
||||
|
<body> |
||||
|
|
||||
|
<!-- github --> |
||||
|
<a target="_blank" href="https://github.com/arnaucode/faircoin-calculator"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub"></a> |
||||
|
<!-- /github --> |
||||
|
|
||||
|
<div class="container"> |
||||
|
<div class="row"> |
||||
|
<div class="col-sm-3"></div> |
||||
|
<div class="col-sm-6"> |
||||
|
<div class="card-body"> |
||||
|
<div class="card-title"> |
||||
|
<img src="img/faircoin-logo.png" class="img-fluid" /> |
||||
|
</div> |
||||
|
<div class="row"> |
||||
|
<div class="col-sm-12"> |
||||
|
<input id="inputDate" type="date"> |
||||
|
</div> |
||||
|
</div> |
||||
|
<br> |
||||
|
<div class="row"> |
||||
|
<div class="col-sm-5"> |
||||
|
<input type="number" class="form-control" id="inputFaircoin" placeholder="faircoin"> |
||||
|
</div> |
||||
|
<div class="col-sm-2"> |
||||
|
FC |
||||
|
</div> |
||||
|
<div class="col-sm-5"> |
||||
|
<button onclick="calculateEuros()" type="button" class="btn btn-outline-primary">Calculate euros</button> |
||||
|
</div> |
||||
|
</div> |
||||
|
<br> |
||||
|
<div class="row"> |
||||
|
<div class="col-sm-5"> |
||||
|
<input type="number" class="form-control" id="inputEuro" placeholder="euro"> |
||||
|
</div> |
||||
|
<div class="col-sm-2"> |
||||
|
€ |
||||
|
</div> |
||||
|
<div class="col-sm-5"> |
||||
|
<button onclick="calculateFaircoins()" type="button" class="btn btn-outline-primary">Calculate faircoins</button> |
||||
|
</div> |
||||
|
</div> |
||||
|
<br> |
||||
|
<div class="row"> |
||||
|
<div class="col-sm-12"> |
||||
|
<div id="result"></div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
|
||||
|
<!-- bootstrap --> |
||||
|
<!-- jQuery first, then Popper.js, then Bootstrap JS --> |
||||
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> |
||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script> |
||||
|
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script> |
||||
|
|
||||
|
<!--toastr--> |
||||
|
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/css/toastr.min.css"> |
||||
|
<script src="http://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/js/toastr.min.js"></script> |
||||
|
|
||||
|
<!-- own javascript--> |
||||
|
<script src="index.js"></script> |
||||
|
|
||||
|
|
||||
|
</body> |
||||
|
|
||||
|
</html> |
@ -0,0 +1,88 @@ |
|||||
|
toastr.options = { |
||||
|
"positionClass": "toast-bottom-right" |
||||
|
}; |
||||
|
|
||||
|
var priceData = ""; |
||||
|
|
||||
|
//get the dataset
|
||||
|
$(document).ready(function() { |
||||
|
$.ajax({ |
||||
|
type: "GET", |
||||
|
url: "http://api.fairplayground.info/rawdata/faircoin_prices.csv", |
||||
|
dataType: "text", |
||||
|
success: function(data) {processData(data);} |
||||
|
}); |
||||
|
}); |
||||
|
function csvToArray(csv) { |
||||
|
var a1 = csv.split("\n"); |
||||
|
var r = []; |
||||
|
for(var i=0; i<a1.length; i++) { |
||||
|
var a2 = a1[i].split(","); |
||||
|
r.push(a2); |
||||
|
} |
||||
|
return(r); |
||||
|
} |
||||
|
function processData(data) { |
||||
|
priceData = csvToArray(data); |
||||
|
}; |
||||
|
|
||||
|
function calculateEuros() { |
||||
|
document.getElementById("result").innerHTML=""; |
||||
|
var faircoins = document.getElementById("inputFaircoin").value; |
||||
|
var date = document.getElementById("inputDate").value; |
||||
|
if(!faircoins){ |
||||
|
toastr.warning("please, fill the faircoin input box"); |
||||
|
return; |
||||
|
} |
||||
|
if(!date){ |
||||
|
toastr.warning("no date"); |
||||
|
return; |
||||
|
} |
||||
|
//let's find the date in the priceData
|
||||
|
var selectedPriceData = [] |
||||
|
for(var i=0; i<priceData.length; i++) { |
||||
|
if(priceData[i][0]==date) { |
||||
|
selectedPriceData = priceData[i]; |
||||
|
} |
||||
|
} |
||||
|
if(selectedPriceData.length<1) { |
||||
|
toastr.warning("selected date not found in the dataset"); |
||||
|
return; |
||||
|
} |
||||
|
console.log(selectedPriceData); |
||||
|
|
||||
|
var euros = faircoins * selectedPriceData[3]; |
||||
|
document.getElementById("inputEuro").value= euros; |
||||
|
document.getElementById("result").innerHTML = faircoins + "FC, are " + euros + "€"; |
||||
|
toastr.success(faircoins + "FC, are " + euros + "€"); |
||||
|
} |
||||
|
function calculateFaircoins() { |
||||
|
document.getElementById("result").innerHTML=""; |
||||
|
var euros = document.getElementById("inputEuro").value; |
||||
|
var date = document.getElementById("inputDate").value; |
||||
|
if(!euros){ |
||||
|
toastr.warning("please, fill the euro input box"); |
||||
|
return; |
||||
|
} |
||||
|
if(!date){ |
||||
|
toastr.warning("no date"); |
||||
|
return; |
||||
|
} |
||||
|
//let's find the date in the priceData
|
||||
|
var selectedPriceData = [] |
||||
|
for(var i=0; i<priceData.length; i++) { |
||||
|
if(priceData[i][0]==date) { |
||||
|
selectedPriceData = priceData[i]; |
||||
|
} |
||||
|
} |
||||
|
if(selectedPriceData.length<1) { |
||||
|
toastr.warning("selected date not found in the dataset"); |
||||
|
return; |
||||
|
} |
||||
|
console.log(selectedPriceData); |
||||
|
|
||||
|
var faircoins = euros / selectedPriceData[3]; |
||||
|
document.getElementById("inputFaircoin").value= faircoins; |
||||
|
document.getElementById("result").innerHTML = euros + "€, are " + faircoins + "FC"; |
||||
|
toastr.success(euros + "€, are " + faircoins + "FC"); |
||||
|
} |
@ -0,0 +1,11 @@ |
|||||
|
{ |
||||
|
"name": "faircoin-calculator", |
||||
|
"version": "1.0.0", |
||||
|
"description": "", |
||||
|
"scripts": { |
||||
|
"prestart": "npm install", |
||||
|
"start": "http-server" |
||||
|
}, |
||||
|
"dependencies": { |
||||
|
} |
||||
|
} |