Impliment soft-payments

This commit is contained in:
2026-03-08 19:28:10 -07:00
parent 54ea7c3027
commit 78bdf250ff
7 changed files with 114 additions and 12 deletions
+60 -6
View File
@@ -1,4 +1,5 @@
@page "/"
@using Controllers.Payment
@rendermode InteractiveServer
<PageTitle>Home</PageTitle>
@@ -53,7 +54,10 @@
<button disabled>@trainButtonText</button>
<button disabled>@predictButtonText</button>
}
<span>@PredictError</span>
<button @onclick="buyStock">Buy Stock</button>
<input placeholder="Stock Symbol [NVDA]" @bind="buyStockSymbol" />
<input placeholder="1.0" @bind="buyStockQuantity" />
<span>@resultError</span>
</div>
</div>
}
@@ -103,6 +107,15 @@
new stockPredictionPair(){ Symbol = "FUN" }
};
string PaymentKey = "";
protected override async Task OnInitializedAsync(){
(bool, string) result = PaymentProcessor.CreatePayment();
if (!result.Item1){
resultError = result.Item2;
}
PaymentKey = result.Item2;
}
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
@@ -136,11 +149,11 @@
string pullButtonText = "Pull Data";
string trainButtonText = "Train AI";
string predictButtonText = "Predict AI";
string PredictError = "";
string resultError = "";
bool Debounce = true;
async Task pull(){
PredictError = "";
resultError = "";
if (Debounce){
Debounce = false;
pullButtonText = "Do not refresh the page. The data is pulling.";
@@ -159,7 +172,7 @@
}
async Task train(){
PredictError = "";
resultError = "";
if (Debounce){
Debounce = false;
trainButtonText = "Do not refresh the page. The AI is training.";
@@ -178,7 +191,7 @@
}
async Task predict(){
PredictError = "";
resultError = "";
if (Debounce){
Debounce = false;
predictButtonText = "Do not refresh the page. The AI is predicting";
@@ -190,7 +203,7 @@
if (string.IsNullOrEmpty(Result.Item1)){
cur.Movement = Result.Item2;
}else{
PredictError = Result.Item1;
resultError = Result.Item1;
}
Console.WriteLine("Received Signal [" + cur.Symbol + "] : " + cur.Movement);
});
@@ -205,6 +218,47 @@
}
}
// Stock Manipulation
string buyStockSymbol = "";
string buyStockQuantity = "";
float StockPrice = 0;
void buyStock(){
if (Session != null){
// Try Parse the quantitiy input
bool success = float.TryParse(buyStockQuantity, out float QuantityResult);
if (!success){
resultError = "Quantity field is not a number";
return;
}
// Try Pay for the stock
(bool, string) result = PaymentProcessor.TryPayment(PaymentKey, QuantityResult * StockPrice);
if (!result.Item1){
resultError = result.Item2;
return;
}
// Add the item
Session.TrackedStocks.Add( new PurchasedStock(){
Symbol = buyStockSymbol.ToLower(),
PurchasePrice = StockPrice,
Quantity = QuantityResult,
PurchaseDate = DateTime.Now
} );
// Reset the Impodent Key
result = PaymentProcessor.CreatePayment();
if (!result.Item1){
resultError = "[Payment suceeded but new payment session failed] : " + result.Item2;
return;
}
PaymentKey = result.Item2;
}
}
// Data Types
class stockPredictionPair {
+4 -2
View File
@@ -1,13 +1,14 @@
@using System.Net.Http
@using System.Net.Http.Json
@using DataBase
@using Controllers.Payment
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using static Microsoft.AspNetCore.Components.Web.RenderMode
@using Microsoft.AspNetCore.Components.Web.Virtualization
@using Microsoft.JSInterop
@using PythonInterop
@using Controllers.PythonInterop
@using Controllers.DataBase
@using WebServer
@using WebServer.Components
@using BCrypt.Net;
@@ -15,3 +16,4 @@
@inject DbDriver dbDriver
@inject AIModule aiModule
@inject IPayment PaymentProcessor