- Fixed minor bugs - Added event calls for sell and buy - sell and buy events to check for valid inputs
224 lines
8.5 KiB
HTML
224 lines
8.5 KiB
HTML
<html>
|
|
|
|
<head>
|
|
<style>
|
|
table td,
|
|
table th {
|
|
border: 1px solid black;
|
|
}
|
|
</style>
|
|
<script src="https://sairajzero.github.io/Standard_Operations/cdn/floCrypto.js"></script>
|
|
<script src="fn.js"></script>
|
|
</head>
|
|
|
|
<body>
|
|
<form id="login-form">
|
|
<fieldset>
|
|
<legend>Login</legend>
|
|
<input type="password" name="priv-key" placeholder="Enter Private Key" />
|
|
<input type="text" name="sid" style="display: none;" />
|
|
<input type="button" name="login" value="login" onclick="UI_evt.login();" /><br />
|
|
<input type="checkbox" name="remember-me" checked />RememberMe
|
|
</fieldset>
|
|
</form>
|
|
<div id="user-container">
|
|
<fieldset>
|
|
<legend>User</legend>
|
|
<span id="user_id"></span><br />
|
|
FLO: <span id="flo_bal"></span><br />
|
|
Rupee: <span id="rupee_bal"></span><br />
|
|
<button onclick="UI_evt.logout();">logout</button>
|
|
</fieldset>
|
|
<form id="buy-form">
|
|
<fieldset>
|
|
<legend>Buy</legend>
|
|
<input type="number" name="quantity" placeholder="Enter Quantity" />
|
|
<input type="number" name="max-price" placeholder="Enter Max Price" />
|
|
<input type="button" name="buy" value="buy" onclick="UI_evt.buy();" />
|
|
</fieldset>
|
|
</form>
|
|
<form id="sell-form">
|
|
<fieldset>
|
|
<legend>Sell</legend>
|
|
<input type="number" name="quantity" placeholder="Enter Quantity" />
|
|
<input type="number" name="min-price" placeholder="Enter Min Price" />
|
|
<input type="button" name="sell" value="sell" onclick="UI_evt.sell();" />
|
|
</fieldset>
|
|
</form>
|
|
</div>
|
|
<div id="buy-orders">
|
|
<fieldset>
|
|
<legend>BuyOrders</legend>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Buyer</th>
|
|
<th>Quantity</th>
|
|
<th>Max Price</th>
|
|
<th>Order Placed</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody></tbody>
|
|
</table>
|
|
</fieldset>
|
|
</div>
|
|
<div id="sell-orders">
|
|
<fieldset>
|
|
<legend>SellOrders</legend>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Seller</th>
|
|
<th>Quantity</th>
|
|
<th>Min Price</th>
|
|
<th>Order Placed</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody></tbody>
|
|
</table>
|
|
</fieldset>
|
|
</div>
|
|
<div id="transactions">
|
|
<fieldset>
|
|
<legend>transactions</legend>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Seller</th>
|
|
<th>Buyer</th>
|
|
<th>Quantity</th>
|
|
<th>Unit Value</th>
|
|
<th>Time</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody></tbody>
|
|
</table>
|
|
</fieldset>
|
|
</div>
|
|
|
|
<button onclick="refresh();">refresh</button>
|
|
|
|
<script>
|
|
function list_buy() {
|
|
getBuyList().then(list => {
|
|
let container = document.getElementById("buy-orders").getElementsByTagName("tbody")[0];
|
|
container.innerHTML = '';
|
|
list.forEach(o => {
|
|
let row = container.insertRow();
|
|
row.insertCell().textContent = o.floID;
|
|
row.insertCell().textContent = o.quantity;
|
|
row.insertCell().textContent = o.maxPrice;
|
|
row.insertCell().textContent = new Date(o.time_placed);
|
|
row.dataset["id"] = o.id;
|
|
});
|
|
}).catch(error => console.error(error))
|
|
}
|
|
|
|
function list_sell() {
|
|
getSellList().then(list => {
|
|
let container = document.getElementById("sell-orders").getElementsByTagName("tbody")[0];
|
|
container.innerHTML = '';
|
|
list.forEach(o => {
|
|
let row = container.insertRow();
|
|
row.insertCell().textContent = o.floID;
|
|
row.insertCell().textContent = o.quantity;
|
|
row.insertCell().textContent = o.minPrice;
|
|
row.insertCell().textContent = new Date(o.time_placed);
|
|
row.dataset["id"] = o.id;
|
|
});
|
|
}).catch(error => console.error(error))
|
|
}
|
|
|
|
function list_txns() {
|
|
getTransactionList().then(list => {
|
|
let container = document.getElementById("transactions").getElementsByTagName("tbody")[0];
|
|
container.innerHTML = '';
|
|
list.forEach(o => {
|
|
let row = container.insertRow();
|
|
row.insertCell().textContent = o.seller;
|
|
row.insertCell().textContent = o.buyer;
|
|
row.insertCell().textContent = o.quantity;
|
|
row.insertCell().textContent = o.unitValue;
|
|
row.insertCell().textContent = new Date(o.tx_time);
|
|
});
|
|
}).catch(error => console.error(error))
|
|
}
|
|
|
|
function refresh() {
|
|
console.info("refresh");
|
|
list_buy();
|
|
list_sell();
|
|
list_txns();
|
|
}
|
|
|
|
function account() {
|
|
getAccount().then(acc => {
|
|
console.debug(acc);
|
|
document.getElementById("login-form").style.display = "none";
|
|
document.getElementById('user-container').style.display = "block";
|
|
document.getElementById("user_id").textContent = acc.floID;
|
|
let flo_total = acc.coins.reduce((a, x) => a + x.quantity, 0);
|
|
let flo_locked = acc.sellOrders.reduce((a, x) => a + x.quantity, 0);
|
|
let flo_net = flo_total - flo_locked;
|
|
console.debug("FLO", flo_total, flo_locked, flo_net);
|
|
document.getElementById("flo_bal").textContent = flo_net + "(+" + flo_locked + ")";
|
|
let rupee_total = acc.rupee_total;
|
|
let rupee_locked = acc.buyOrders.reduce((a, x) => a + x.quantity * x.maxPrice, 0);
|
|
let rupee_net = rupee_total - rupee_locked;
|
|
console.debug("RUPEE", rupee_total, rupee_locked, rupee_net);
|
|
document.getElementById("rupee_bal").textContent = rupee_net + "(+" + rupee_locked + ")";
|
|
}).catch(error => {
|
|
if (error instanceof ResponseError) {
|
|
let response = JSON.parse(error.data)
|
|
console.log(error);
|
|
console.log(response);
|
|
document.getElementById('user-container').style.display = "none";
|
|
document.getElementById("login-form").style.display = "block";
|
|
document.forms['login-form']["sid"].value = response.sid;
|
|
} else
|
|
console.error(error);
|
|
})
|
|
}
|
|
|
|
const UI_evt = {};
|
|
|
|
UI_evt.logout = function() {
|
|
logout().then(result => {
|
|
console.warn(result);
|
|
location.reload();
|
|
}).catch(error => console.error(error));
|
|
};
|
|
|
|
UI_evt.login = function() {
|
|
let formInputs = document.forms['login-form'];
|
|
let privKey = formInputs['priv-key'].value;
|
|
let sid = formInputs['sid'].value;
|
|
let rememberMe = formInputs['remember-me'].checked;
|
|
login(privKey, sid, rememberMe).then(result => {
|
|
console.log(result);
|
|
account();
|
|
}).catch(error => console.error(error));
|
|
};
|
|
|
|
UI_evt.sell = function() {
|
|
let formInputs = document.forms['sell-form'];
|
|
sell(parseFloat(formInputs["quantity"].value), parseFloat(formInputs["min-price"].value))
|
|
.then(result => console.log(result))
|
|
.catch(error => console.error(error));
|
|
};
|
|
|
|
UI_evt.buy = function() {
|
|
let formInputs = document.forms['buy-form'];
|
|
buy(parseFloat(formInputs["quantity"].value), parseFloat(formInputs["max-price"].value))
|
|
.then(result => console.log(result))
|
|
.catch(error => console.error(error));
|
|
};
|
|
|
|
(function init() {
|
|
account();
|
|
refresh();
|
|
})();
|
|
</script>
|
|
</body>
|
|
|
|
</html> |