-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
71 lines (67 loc) · 2.64 KB
/
main.js
File metadata and controls
71 lines (67 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
function getExchangeRate(){
// load current btc exchange rate, useful to have
return customFetch('https://blockchain.info/tobtc?currency=USD&value=1&cors=true',false)
.then((data) => {
template.btcUSD = 1/data;
});
}
function loadTemplate(){
getExchangeRate();
document.getElementById('calcText').innerText = template.coin + ' ' + document.getElementById('calcText').innerText
let fields = ['BlockReward','Difficulty','ExchangeRate'];
fields.forEach(function (item){
template['get'+item]().then((data) => {document.getElementById(item).value = data});
})
}
function doCalc(){
let fields = ['hashRate','powerUse','poolFee','powerCost','BlockReward','Difficulty','ExchangeRate'];
let decoded = {};
try {
fields.forEach(function (item) {
decoded[item] = Number(document.getElementById(item).value);
});
}
catch {}
let cost = 0.001 * decoded.powerCost * decoded.powerUse;
let hour = (1 - decoded.poolFee) * decoded.hashRate * 1000000 * 3600 * decoded.BlockReward / (2**32 * decoded.Difficulty);
let ranges = {'Hour' : 1, 'Day' : 24, 'Week' : 24 * 7, 'Year' : 24 * 365};
let out = '';
let prof = '';
for (let label in ranges){
let mult = ranges[label];
let val = (mult * hour).toFixed(template.decimalPlaces);
let usd = (val * decoded.ExchangeRate * template.btcUSD).toFixed(template.decimalPlaces);
let usd_cost = (mult * hour * decoded.ExchangeRate * template.btcUSD - cost * mult).toFixed(template.decimalPlaces)
out = out + `<li><p>One ${label}: <b>${val} ${template.coin}</b>, equal to ${usd} USD</p></li>\n`
prof = prof + `<li><p>One ${label}: ${usd_cost} USD</p></li>\n`
}
document.getElementById("outputWindow").style.display = '';
document.getElementById("outputWindow").innerHTML = `
<h1 style='
font-size:2em;
font-weight:400;
color:#ffffff;
border-bottom:1px solid #ffffff;
margin-bottom:1em;'
>
Expected Mining Return
</h1>
<table>
<tr>
<td>
<p>Returns over time (not accounting for cost):</p>
<ul>
${out}
</ul>
</td>
<td>
<p>Profit over time:</p>
<ul>
${prof}
</ul>
</td>
</tr>
</table>
`;
}
window.onload = loadTemplate;