Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web view improvements (update interval, settings) #286

Merged
merged 27 commits into from
Apr 16, 2017
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
bcb3be2
Increase page update interval
ckcollab Mar 31, 2017
de08e92
show yearly earnings as well
ckcollab Mar 31, 2017
1a58be0
Display USD with 2 decimal places
ckcollab Mar 31, 2017
45bc439
display total holdings
ckcollab Apr 2, 2017
d2aaf68
fix grabbing totals when totalCoins not defined
ckcollab Apr 2, 2017
94b5f42
use max coins not total coins for total holdings
ckcollab Apr 3, 2017
30cd953
adds toastr and settings for interval + stats
ckcollab Apr 6, 2017
1b026fa
remove cruft
ckcollab Apr 6, 2017
654c6ab
change "init" to "update" as it is ran multiple times
ckcollab Apr 8, 2017
b5567c5
missed an init->update refactor
ckcollab Apr 13, 2017
d1b4516
add EUR to nice currency printing
ckcollab Apr 13, 2017
4e087cb
verify refresh rate value
ckcollab Apr 14, 2017
61081dd
new html header with collapsing menu
Apr 14, 2017
24da4cd
restore default refreshrate to 30 seconds
Apr 14, 2017
ded06c3
added a version parameter to the javascript to force reload
Apr 14, 2017
2e6cac4
added missing scheme in toastr urls
Apr 14, 2017
b97ab45
rename loadSave to loadSettings
Apr 14, 2017
5234536
Added Bitcoin Display Unit to Settings.
Apr 14, 2017
a644a86
Added OutputCurrencyDisplayMode to Settings.
Apr 14, 2017
65fadef
Added Effective Rate Calculation to Settings.
Apr 14, 2017
851c30e
Fix indentation issues
rnevet Apr 15, 2017
d18500e
refactor validating... will still behave weirdly if somehow manages t…
ckcollab Apr 15, 2017
42294a3
Fixed indent issue
rnevet Apr 15, 2017
f98a4ab
Restored btcDisplayUnitsModes saving method
rnevet Apr 15, 2017
d8fb51e
Merge pull request #1 from Mikadily/web_setting
ckcollab Apr 15, 2017
52b6830
Close menu when settings is pressed.
rnevet Apr 16, 2017
b930c92
use icon192
rnevet Apr 16, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions www/lendingbot.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@

<!-- Bootstrap Core CSS -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">

<!-- jQuery Version 1.12.2 -->
<script src="https://code.jquery.com/jquery-1.12.2.min.js"></script>

<!-- Bootstrap Core JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

<script src="lendingbot.js" ></script>

<style>
body {
padding-top: 50px;
Expand Down
30 changes: 22 additions & 8 deletions www/lendingbot.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

var localFile, reader;

var Hour = new Timespan("Hour",1/24);
var Day = new Timespan("Day",1);
var Week = new Timespan("Week",7);
var Month = new Timespan("Month",30);
var timespans = [Month, Week, Day, Hour];
var Hour = new Timespan("Hour", 1/24);
var Day = new Timespan("Day", 1);
var Week = new Timespan("Week", 7);
var Month = new Timespan("Month", 30);
var Year = new Timespan("Year", 365);
var timespans = [Year, Month, Week, Day, Hour];
var summaryCoinRate, summaryCoin;
var earningsOutputCoinRate, earningsOutputCoin;
var outputCurrencyDisplayMode = 'all'
Expand Down Expand Up @@ -69,6 +70,7 @@ function updateRawValues(rawData){
table.innerHTML = "";
var currencies = Object.keys(rawData);
var totalBTCEarnings = {};
var totalCoinsOverall = 0;
for (var keyIndex = 0; keyIndex < currencies.length; ++keyIndex)
{
var currency = currencies[keyIndex];
Expand All @@ -78,6 +80,7 @@ function updateRawValues(rawData){
var totalCoins = parseFloat(rawData[currency]['totalCoins']);
var maxToLend = parseFloat(rawData[currency]['maxToLend']);
var highestBidBTC = parseFloat(rawData[currency]['highestBid']);

if (currency == 'BTC') {
// no bids for BTC provided by poloniex
// this is added so BTC can be handled like other coins for conversions
Expand Down Expand Up @@ -181,11 +184,20 @@ function updateRawValues(rawData){
}
}
}
totalCoinsOverall += earningsOutputCoinRate * maxToLend * highestBidBTC;
}

// add headers
var thead = table.createTHead();

// total
var total_row = thead.insertRow(0);
var total_cell = total_row.appendChild(document.createElement("th"));
total_cell.innerHTML = "Total holdings";
total_cell = total_row.appendChild(document.createElement("th"));
total_cell.setAttribute("colspan", 2);
total_cell.innerHTML = prettyFloat(totalCoinsOverall, 2) + " USD";
Copy link
Collaborator

@rnevet rnevet Apr 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

USD? I guess it should be earningsOutputCoin

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you're doing this in another PR I'll pull this stuff


// show account summary
if (currencies.length > 1 || summaryCoin != earningsOutputCoin) {
earnings = '';
Expand Down Expand Up @@ -214,18 +226,18 @@ function handleLocalFile(file) {
function loadData() {
if (localFile) {
reader.readAsText(localFile, 'utf-8');
setTimeout('loadData()',30000)
setTimeout('loadData()', 10000)
} else {
// expect the botlog.json to be in the same folder on the webserver
var file = 'botlog.json';
$.getJSON(file, function (data) {
updateJson(data);
// reload every 30sec
setTimeout('loadData()',30000)
setTimeout('loadData()', 10000)
}).fail( function(d, textStatus, error) {
$('#status').text("getJSON failed, status: " + textStatus + ", error: "+error);
// retry after 60sec
setTimeout('loadData()',60000)
setTimeout('loadData()', 60000)
});;
}
}
Expand All @@ -246,6 +258,8 @@ function Timespan(name, multiplier) {
}
if (currency == "BTC") {
return displayUnit.formatValue(earnings) + " <span class=" + currencyClass + ">" + displayUnit.name + "</span> / " + name + "<br/>"
} else if (currency == "USD" || currency == "USDT") {
return printFloat(earnings, 2) + " <span class=" + currencyClass + ">" + currency + "</span> / "+ name + "<br/>";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest we just use prettyFloat(earnings,2) instead of trying to guess which currency is a Fiat one.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i.e. I use EUR. ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would change behavior for quite a few coins, I think we want to see Satoshi level resolution most of the times?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What other currencies should we add here? Some currencies may need special printing, in this case for USD it makes sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, the other currencies in this function use printFloat, you want to go in and change these to the style you prefer?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ckcollab "EUR" for example and actually any currency supported by https://blockchain.info/api/exchange_rates_api

I'm thinking about using the prettyFloat as it will provide an accuracy of 2 decimals for any coin and I think that should be good enough, no? or should we make the accuracy configurable?

I'm open for suggestions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: I also add EUR, but maintain consistency with the surrounding code. Then in a separate PR we decide how to handle this particular problem.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed.

} else {
return printFloat(earnings, 8) + " <span class=" + currencyClass + ">" + currency + "</span> / "+ name + "<br/>";
}
Expand Down