Give $1000 starting out and track money [ Paper trades ]

This commit is contained in:
2026-03-08 20:41:39 -07:00
parent ce4f9a197d
commit 2eab9d99ba
5 changed files with 77 additions and 31 deletions
+23 -22
View File
@@ -33,12 +33,7 @@
<div><h2>Account</h2></div>
<span>UserName: @Session.UserName</span><br />
<div>
@foreach(PurchasedStock cur in Session.TrackedStocks){
<div>@cur.Symbol</div>
<div>@cur.Quantity</div>
<div>@cur.PurchasePrice</div>
<div>@cur.PurchaseDate.ToString("M-dd-yyyy")</div>
}
<span>Money: $@Session.Money</span>
</div>
</div>
<!-- Tool Frame -->
@@ -74,7 +69,10 @@
@foreach (PurchasedStock cur in Session.TrackedStocks){
<div class="signalBlock">
<div>
<p>@cur.Symbol</p>
<p style="text-align: center; font-weight: bold;">@cur.Symbol</p>
<p>Purchased Price: @cur.PurchasePrice</p>
<p>Purchased Quantity: @cur.Quantity</p>
<p>Purchased Date: @cur.PurchaseDate.ToString("M-dd-yyyy")</p>
</div>
<div>
<span>-></span>
@@ -102,20 +100,10 @@
loginSession? Session = null;
// On Page Load
string PaymentKey = "";
protected override async Task OnInitializedAsync(){
(bool, string) result = PaymentProcessor.CreatePayment();
if (!result.Item1){
resultError = result.Item2;
}
PaymentKey = result.Item2;
}
@@ -133,10 +121,17 @@
string passwordhash = dbDriver.Get( dbPrefix + "password" ); // Pull the password hash
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);
Session = new loginSession(){
UserName = userName.ToLower(),
TrackedStocks = stocks != null ? stocks : new List<PurchasedStock>()
TrackedStocks = stocks != null ? stocks : new List<PurchasedStock>(),
Money = moneyLoaded ? moneyResult : 1000
};
(bool, string) result = PaymentProcessor.CreatePayment(Session.UserName);
if (!result.Item1){
resultError = result.Item2;
}
PaymentKey = result.Item2;
}else{
loginError = "wrong password";
}
@@ -147,9 +142,11 @@
string passwordhash = dbDriver.Get( dbPrefix + "password" );
if (string.IsNullOrEmpty(passwordhash)){
dbDriver.Set( dbPrefix + "password", BCrypt.HashPassword( passWord, BCrypt.GenerateSalt() ) );
dbDriver.Set( dbPrefix + "money", "1000" );
Session = new loginSession(){
UserName = userName.ToLower(),
TrackedStocks = new List<PurchasedStock>()
TrackedStocks = new List<PurchasedStock>(),
Money = 1000
};
}else{
loginError = "account is taken";
@@ -273,10 +270,14 @@
} );
dbDriver.Set( dbPrefix + "Stocks", Newtonsoft.Json.JsonConvert.SerializeObject(Session.TrackedStocks) );
// Reload the users money
bool moneyLoaded = float.TryParse(dbDriver.Get( dbPrefix + "money" ), out float moneyResult);
Session.Money = moneyLoaded ? moneyResult : 1000;
// Reset the Impodent Key
result = PaymentProcessor.CreatePayment();
result = PaymentProcessor.CreatePayment(Session.UserName);
if (!result.Item1){
resultError = "[Payment suceeded but new payment session failed] : " + result.Item2;
resultError = "[New payment session failed] : " + result.Item2;
return;
}
PaymentKey = result.Item2;
@@ -67,7 +67,6 @@
.signalBlock > :nth-child(1) {
border: solid #040 1px;
border-radius: 15px;
width: 40px;
padding: 0px 20px;
background-color: greenyellow;
}