Debounce all the long processes

This commit is contained in:
2026-03-09 17:23:56 -07:00
parent b757672bdf
commit dff269103b
+39 -8
View File
@@ -49,9 +49,15 @@
}
<br/>
<div>
<input placeholder="Stock Symbol [NVDA]" @bind="buyStockSymbol" />
<input placeholder="Stock Quantity [1.0]" @bind="buyStockQuantity" />
<button @onclick="buyStock">Buy Stock</button>
@if (Debounce){
<input placeholder="Stock Symbol [NVDA]" @bind="buyStockSymbol" />
<input placeholder="Stock Quantity [1.0]" @bind="buyStockQuantity" />
<button @onclick="buyStock">Buy Stock</button>
} else {
<input disabled placeholder="Stock Symbol [NVDA]" @bind="buyStockSymbol" />
<input disabled placeholder="Stock Quantity [1.0]" @bind="buyStockQuantity" />
<button disabled>Buy Stock</button>
}
</div>
<span>@resultError</span>
</div>
@@ -71,7 +77,11 @@
<p>Purchased Price: @cur.PurchasePrice</p>
<p>Purchased Quantity: @cur.Quantity</p>
<p>Purchased Date: @cur.PurchaseDate.ToString("M-dd-yyyy")</p>
<button @onclick="() => {sellStock(cur);}">Sell All</button>
@if (Debounce){
<button @onclick="async () => {await sellStock(cur);}">Sell All</button>
}else{
<button disabled>Sell All</button>
}
</div>
<div>
<span>-></span>
@@ -218,6 +228,7 @@
await Task.Delay(2000);
predictButtonText = "Predict AI";
Debounce = true;
await Task.Delay(1);
}
}
@@ -231,13 +242,18 @@
string buyStockSymbol = "";
string buyStockQuantity = "";
void buyStock(){
if (Session != null){
async Task buyStock(){
if (Debounce && Session != null){
Debounce = false;
await Task.Delay(1);
string dbPrefix = $"[{userName.ToLower()}]:";
// Try Parse the quantitiy input
bool success = float.TryParse(buyStockQuantity, out float QuantityResult);
if (!success){
resultError = "Quantity field is not a number";
Debounce = true;
await Task.Delay(1);
return;
}
@@ -248,6 +264,8 @@
(bool, string) result = PaymentProcessor.TryPayment(PaymentKey, QuantityResult * stockPrice);
if (!result.Item1){
resultError = result.Item2;
Debounce = true;
await Task.Delay(1);
return;
}
@@ -268,15 +286,21 @@
result = PaymentProcessor.CreatePayment(Session.UserName);
if (!result.Item1){
resultError = "[New payment session failed] : " + result.Item2;
Debounce = true;
await Task.Delay(1);
return;
}
PaymentKey = result.Item2;
Debounce = true;
await Task.Delay(1);
}
}
void sellStock(PurchasedStock stock){
async Task sellStock(PurchasedStock stock){
string dbPrefix = $"[{userName.ToLower()}]:";
if (Session != null){
if (Debounce && Session != null){
Debounce = false;
await Task.Delay(1);
// Get sell price
float sellPrice = stock.Quantity * aiModule.GetCurrentPrice( stock.Symbol );
@@ -285,6 +309,8 @@
(bool, string) result = PaymentProcessor.TrySell(PaymentKey, sellPrice);
if (!result.Item1){
resultError = result.Item2;
Debounce = true;
await Task.Delay(1);
return;
}
@@ -300,9 +326,14 @@
result = PaymentProcessor.CreatePayment(Session.UserName);
if (!result.Item1){
resultError = "[New payment session failed] : " + result.Item2;
Debounce = true;
await Task.Delay(1);
return;
}
PaymentKey = result.Item2;
Debounce = true;
await Task.Delay(1);
}
}
}