update client pages
- Fixed minor bugs - Added event calls for sell and buy - sell and buy events to check for valid inputs
This commit is contained in:
parent
0cc525b28e
commit
0d84962b8a
@ -125,6 +125,10 @@ function logout() {
|
|||||||
|
|
||||||
function buy(quantity, max_price) {
|
function buy(quantity, max_price) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
if (typeof quantity !== "number" || quantity <= 0)
|
||||||
|
return reject(INVALID(`Invalid quantity (${quantity})`));
|
||||||
|
else if (typeof max_price !== "number" || max_price <= 0)
|
||||||
|
return reject(INVALID(`Invalid max_price (${max_price})`));
|
||||||
fetch('/buy', {
|
fetch('/buy', {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
@ -144,6 +148,10 @@ function buy(quantity, max_price) {
|
|||||||
|
|
||||||
function sell(quantity, min_price) {
|
function sell(quantity, min_price) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
if (typeof quantity !== "number" || quantity <= 0)
|
||||||
|
return reject(INVALID(`Invalid quantity (${quantity})`));
|
||||||
|
else if (typeof min_price !== "number" || min_price <= 0)
|
||||||
|
return reject(INVALID(`Invalid min_price (${min_price})`));
|
||||||
fetch('/sell', {
|
fetch('/sell', {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
|
|||||||
@ -17,7 +17,7 @@
|
|||||||
<legend>Login</legend>
|
<legend>Login</legend>
|
||||||
<input type="password" name="priv-key" placeholder="Enter Private Key" />
|
<input type="password" name="priv-key" placeholder="Enter Private Key" />
|
||||||
<input type="text" name="sid" style="display: none;" />
|
<input type="text" name="sid" style="display: none;" />
|
||||||
<input type="button" name="login" value="login" /><br/>
|
<input type="button" name="login" value="login" onclick="UI_evt.login();" /><br />
|
||||||
<input type="checkbox" name="remember-me" checked />RememberMe
|
<input type="checkbox" name="remember-me" checked />RememberMe
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</form>
|
</form>
|
||||||
@ -27,22 +27,22 @@
|
|||||||
<span id="user_id"></span><br />
|
<span id="user_id"></span><br />
|
||||||
FLO: <span id="flo_bal"></span><br />
|
FLO: <span id="flo_bal"></span><br />
|
||||||
Rupee: <span id="rupee_bal"></span><br />
|
Rupee: <span id="rupee_bal"></span><br />
|
||||||
<button id="logout">logout</button>
|
<button onclick="UI_evt.logout();">logout</button>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<form id="buy">
|
<form id="buy-form">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>Buy</legend>
|
<legend>Buy</legend>
|
||||||
<input type="number" name="quantity" placeholder="Enter Quantity" />
|
<input type="number" name="quantity" placeholder="Enter Quantity" />
|
||||||
<input type="number" name="max-price" placeholder="Enter Max Price" />
|
<input type="number" name="max-price" placeholder="Enter Max Price" />
|
||||||
<input type="button" name="buy" value="buy" />
|
<input type="button" name="buy" value="buy" onclick="UI_evt.buy();" />
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</form>
|
</form>
|
||||||
<form id="sell">
|
<form id="sell-form">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>Sell</legend>
|
<legend>Sell</legend>
|
||||||
<input type="number" name="quantity" placeholder="Enter Quantity" />
|
<input type="number" name="quantity" placeholder="Enter Quantity" />
|
||||||
<input type="number" name="min-price" placeholder="Enter Min Price" />
|
<input type="number" name="min-price" placeholder="Enter Min Price" />
|
||||||
<input type="button" name="sell" value="sell" />
|
<input type="button" name="sell" value="sell" onclick="UI_evt.sell();" />
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
@ -153,16 +153,19 @@
|
|||||||
|
|
||||||
function account() {
|
function account() {
|
||||||
getAccount().then(acc => {
|
getAccount().then(acc => {
|
||||||
|
console.debug(acc);
|
||||||
document.getElementById("login-form").style.display = "none";
|
document.getElementById("login-form").style.display = "none";
|
||||||
document.getElementById('user-container').style.display = "block";
|
document.getElementById('user-container').style.display = "block";
|
||||||
document.getElementById("user_id").textContent = acc.floID;
|
document.getElementById("user_id").textContent = acc.floID;
|
||||||
let flo_total = acc.coins.reduce((a, x) => x.quantity, 0);
|
let flo_total = acc.coins.reduce((a, x) => a + x.quantity, 0);
|
||||||
let flo_locked = acc.sellOrders.reduce((a, x) => x.quantity);
|
let flo_locked = acc.sellOrders.reduce((a, x) => a + x.quantity, 0);
|
||||||
let flo_net = flo_total - flo_locked;
|
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 + ")";
|
document.getElementById("flo_bal").textContent = flo_net + "(+" + flo_locked + ")";
|
||||||
let rupee_total = acc.rupee_total;
|
let rupee_total = acc.rupee_total;
|
||||||
let rupee_locked = acc.buyOrders.reduce((a, x) => x.quantity * x.maxPrice, 0);
|
let rupee_locked = acc.buyOrders.reduce((a, x) => a + x.quantity * x.maxPrice, 0);
|
||||||
let rupee_net = rupee_total - rupee_locked;
|
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 + ")";
|
document.getElementById("rupee_bal").textContent = rupee_net + "(+" + rupee_locked + ")";
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
if (error instanceof ResponseError) {
|
if (error instanceof ResponseError) {
|
||||||
@ -177,14 +180,16 @@
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById("logout").onclick = (evt) => {
|
const UI_evt = {};
|
||||||
|
|
||||||
|
UI_evt.logout = function() {
|
||||||
logout().then(result => {
|
logout().then(result => {
|
||||||
console.warn(result);
|
console.warn(result);
|
||||||
location.reload();
|
location.reload();
|
||||||
}).catch(error => console.error(error));
|
}).catch(error => console.error(error));
|
||||||
};
|
};
|
||||||
|
|
||||||
document.forms['login-form']['login'].onclick = evt => {
|
UI_evt.login = function() {
|
||||||
let formInputs = document.forms['login-form'];
|
let formInputs = document.forms['login-form'];
|
||||||
let privKey = formInputs['priv-key'].value;
|
let privKey = formInputs['priv-key'].value;
|
||||||
let sid = formInputs['sid'].value;
|
let sid = formInputs['sid'].value;
|
||||||
@ -193,7 +198,21 @@
|
|||||||
console.log(result);
|
console.log(result);
|
||||||
account();
|
account();
|
||||||
}).catch(error => console.error(error));
|
}).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() {
|
(function init() {
|
||||||
account();
|
account();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user