Debounce all the long processes

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