Make purchased based on current prices | fix register issue

This commit is contained in:
2026-03-08 21:11:17 -07:00
parent 2eab9d99ba
commit 5f371dddbc
3 changed files with 31 additions and 3 deletions
+14 -3
View File
@@ -119,6 +119,10 @@
async Task LoginSession(){
string dbPrefix = $"[{userName.ToLower()}]:"; // Set the DB prefix for the get and set
string passwordhash = dbDriver.Get( dbPrefix + "password" ); // Pull the password hash
if (string.IsNullOrEmpty(passwordhash)){
loginError = "no account found with that username";
return;
}
if (BCrypt.Verify( passWord, passwordhash )){ // If the password is valid
List<PurchasedStock>? stocks = JsonConvert.DeserializeObject<List<PurchasedStock>>( dbDriver.Get( dbPrefix + "Stocks" ) );
bool moneyLoaded = float.TryParse(dbDriver.Get( dbPrefix + "money" ), out float moneyResult);
@@ -148,6 +152,11 @@
TrackedStocks = new List<PurchasedStock>(),
Money = 1000
};
(bool, string) result = PaymentProcessor.CreatePayment(Session.UserName);
if (!result.Item1){
resultError = result.Item2;
}
PaymentKey = result.Item2;
}else{
loginError = "account is taken";
}
@@ -243,7 +252,6 @@
string buyStockSymbol = "";
string buyStockQuantity = "";
float StockPrice = 0;
void buyStock(){
if (Session != null){
string dbPrefix = $"[{userName.ToLower()}]:";
@@ -254,8 +262,11 @@
return;
}
// Get Stock Price
float stockPrice = aiModule.GetCurrentPrice( buyStockSymbol );
// Try Pay for the stock
(bool, string) result = PaymentProcessor.TryPayment(PaymentKey, QuantityResult * StockPrice);
(bool, string) result = PaymentProcessor.TryPayment(PaymentKey, QuantityResult * stockPrice);
if (!result.Item1){
resultError = result.Item2;
return;
@@ -264,7 +275,7 @@
// Add the stock
Session.TrackedStocks.Add( new PurchasedStock(){
Symbol = buyStockSymbol.ToUpper(),
PurchasePrice = StockPrice,
PurchasePrice = stockPrice,
Quantity = QuantityResult,
PurchaseDate = DateTime.Now
} );