main: Added node info

This commit is contained in:
Nathan Woodburn 2023-06-06 22:23:05 +10:00
parent 2473e4a571
commit a4c1f0c895
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
2 changed files with 200 additions and 73 deletions

View File

@ -49,6 +49,13 @@
buttonSend = new Button();
buttonPortfolio = new Button();
panelPortfolio = new Panel();
groupBoxTransactions = new GroupBox();
groupBoxinfo = new GroupBox();
labelPendingCount = new Label();
labelSyncPercent = new Label();
labelHeight = new Label();
groupBoxbalance = new GroupBox();
labelBalanceTotal = new Label();
labelLocked = new Label();
labelBalance = new Label();
statusStripmain.SuspendLayout();
@ -56,6 +63,8 @@
groupBoxaccount.SuspendLayout();
panelNav.SuspendLayout();
panelPortfolio.SuspendLayout();
groupBoxinfo.SuspendLayout();
groupBoxbalance.SuspendLayout();
SuspendLayout();
//
// statusStripmain
@ -251,29 +260,106 @@
//
// panelPortfolio
//
panelPortfolio.Controls.Add(labelLocked);
panelPortfolio.Controls.Add(labelBalance);
panelPortfolio.Controls.Add(groupBoxTransactions);
panelPortfolio.Controls.Add(groupBoxinfo);
panelPortfolio.Controls.Add(groupBoxbalance);
panelPortfolio.Location = new Point(120, 25);
panelPortfolio.Name = "panelPortfolio";
panelPortfolio.Size = new Size(956, 538);
panelPortfolio.TabIndex = 7;
panelPortfolio.Visible = false;
//
// groupBoxTransactions
//
groupBoxTransactions.Dock = DockStyle.Bottom;
groupBoxTransactions.Location = new Point(0, 113);
groupBoxTransactions.Name = "groupBoxTransactions";
groupBoxTransactions.Size = new Size(956, 425);
groupBoxTransactions.TabIndex = 8;
groupBoxTransactions.TabStop = false;
groupBoxTransactions.Text = "Transactions";
//
// groupBoxinfo
//
groupBoxinfo.Controls.Add(labelPendingCount);
groupBoxinfo.Controls.Add(labelSyncPercent);
groupBoxinfo.Controls.Add(labelHeight);
groupBoxinfo.Location = new Point(281, 3);
groupBoxinfo.Name = "groupBoxinfo";
groupBoxinfo.Size = new Size(232, 104);
groupBoxinfo.TabIndex = 8;
groupBoxinfo.TabStop = false;
groupBoxinfo.Text = "Info";
//
// labelPendingCount
//
labelPendingCount.AutoSize = true;
labelPendingCount.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
labelPendingCount.Location = new Point(3, 56);
labelPendingCount.Name = "labelPendingCount";
labelPendingCount.Size = new Size(116, 21);
labelPendingCount.TabIndex = 2;
labelPendingCount.Text = "labelPendingTX";
//
// labelSyncPercent
//
labelSyncPercent.AutoSize = true;
labelSyncPercent.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
labelSyncPercent.Location = new Point(133, 14);
labelSyncPercent.Name = "labelSyncPercent";
labelSyncPercent.Size = new Size(89, 21);
labelSyncPercent.TabIndex = 1;
labelSyncPercent.Text = "labelSync%";
//
// labelHeight
//
labelHeight.AutoSize = true;
labelHeight.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
labelHeight.Location = new Point(3, 14);
labelHeight.Name = "labelHeight";
labelHeight.Size = new Size(89, 21);
labelHeight.TabIndex = 0;
labelHeight.Text = "labelHeight";
//
// groupBoxbalance
//
groupBoxbalance.Controls.Add(labelBalanceTotal);
groupBoxbalance.Controls.Add(labelLocked);
groupBoxbalance.Controls.Add(labelBalance);
groupBoxbalance.Location = new Point(12, 3);
groupBoxbalance.Name = "groupBoxbalance";
groupBoxbalance.Size = new Size(263, 104);
groupBoxbalance.TabIndex = 2;
groupBoxbalance.TabStop = false;
groupBoxbalance.Text = "Balance";
//
// labelBalanceTotal
//
labelBalanceTotal.AutoSize = true;
labelBalanceTotal.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
labelBalanceTotal.Location = new Point(21, 60);
labelBalanceTotal.Name = "labelBalanceTotal";
labelBalanceTotal.Size = new Size(75, 21);
labelBalanceTotal.TabIndex = 2;
labelBalanceTotal.Text = "labelTotal";
//
// labelLocked
//
labelLocked.AutoSize = true;
labelLocked.Location = new Point(36, 87);
labelLocked.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
labelLocked.Location = new Point(21, 39);
labelLocked.Name = "labelLocked";
labelLocked.Size = new Size(70, 15);
labelLocked.Size = new Size(92, 21);
labelLocked.TabIndex = 1;
labelLocked.Text = "labelLocked";
//
// labelBalance
//
labelBalance.AutoSize = true;
labelBalance.Location = new Point(36, 37);
labelBalance.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
labelBalance.Location = new Point(21, 18);
labelBalance.Name = "labelBalance";
labelBalance.Size = new Size(73, 15);
labelBalance.Size = new Size(96, 21);
labelBalance.TabIndex = 0;
labelBalance.Text = "labelBalance";
//
@ -298,7 +384,10 @@
groupBoxaccount.PerformLayout();
panelNav.ResumeLayout(false);
panelPortfolio.ResumeLayout(false);
panelPortfolio.PerformLayout();
groupBoxinfo.ResumeLayout(false);
groupBoxinfo.PerformLayout();
groupBoxbalance.ResumeLayout(false);
groupBoxbalance.PerformLayout();
ResumeLayout(false);
PerformLayout();
}
@ -327,5 +416,12 @@
private Panel panelPortfolio;
private Label labelLocked;
private Label labelBalance;
private GroupBox groupBoxbalance;
private Label labelBalanceTotal;
private GroupBox groupBoxinfo;
private Label labelHeight;
private Label labelPendingCount;
private Label labelSyncPercent;
private GroupBox groupBoxTransactions;
}
}

View File

@ -1,5 +1,6 @@
using System.Net.Http;
using System.Runtime.InteropServices;
using System.Security.Policy;
using Newtonsoft.Json.Linq;
namespace FireWallet
@ -16,6 +17,9 @@ namespace FireWallet
double balance;
double balanceLocked;
int screen; // 0 = login, 1 = portfolio
int height;
double syncProgress;
int pendingTransactions;
#endregion
#region Application
@ -25,7 +29,6 @@ namespace FireWallet
}
private void MainForm_Load(object sender, EventArgs e)
{
AddLog("Loading");
UpdateTheme();
LoadNode();
@ -39,7 +42,6 @@ namespace FireWallet
}
panelNav.Dock = DockStyle.Left;
AddLog("Finished loading");
ResizeForm();
panelNav.Visible = false;
screen = 0;
@ -59,11 +61,8 @@ namespace FireWallet
#region Settings
private void LoadNode()
{
AddLog("Loading Node");
if (!File.Exists(dir + "node.txt"))
{
AddLog("Node file not found");
AddLog("Starting Node Setup");
CreateForm cf = new CreateForm();
cf.ShowDialog();
// Initial run
@ -132,7 +131,6 @@ namespace FireWallet
CreateConfig(dir);
}
AddLog("Reading theme file");
// Read file
StreamReader sr = new StreamReader(dir + "theme.txt");
theme = new Dictionary<string, string>();
@ -168,8 +166,6 @@ namespace FireWallet
this.Width = Screen.PrimaryScreen.Bounds.Width / 5 * 3;
this.Height = Screen.PrimaryScreen.Bounds.Height / 5 * 3;
AddLog("Finished applying theme");
AddLog("Applying transparency");
applyTransparency(theme);
@ -342,6 +338,7 @@ namespace FireWallet
comboBoxaccount.Items.Add("No accounts found");
comboBoxaccount.Enabled = false;
}
textBoxaccountpassword.Focus();
}
private async Task<bool> Login()
{
@ -371,12 +368,61 @@ namespace FireWallet
notifyForm.Dispose();
return false;
}
AddLog("Login successful");
UpdateBalance();
return true;
}
private async void LoginClick(object sender, EventArgs e)
{
account = comboBoxaccount.Text;
password = textBoxaccountpassword.Text;
bool loggedin = await Login();
if (loggedin)
{
toolStripStatusLabelaccount.Text = "Account: " + account;
textBoxaccountpassword.Text = "";
panelaccount.Visible = false;
toolStripSplitButtonlogout.Visible = true;
panelNav.Visible = true;
screen = 1;
buttonPortfolio.PerformClick();
}
}
private void PasswordEntered(object sender, KeyEventArgs e)
{
if (e.KeyValue == 13)
{
LoginClick(sender, e);
}
}
private void AccountChoose(object sender, EventArgs e)
{
textBoxaccountpassword.Focus();
}
private async void Logout(object sender, EventArgs e)
{
toolStripSplitButtonlogout.Visible = false;
string path = "wallet/" + account + "/lock";
string content = "";
string APIresponse = await APIPost(path, true, content);
if (!APIresponse.Contains("true"))
{
AddLog("Logout failed");
NotifyForm notifyForm = new NotifyForm("Logout Failed\n" + APIresponse);
notifyForm.ShowDialog();
notifyForm.Dispose();
panelaccount.Visible = true;
return;
}
panelaccount.Visible = true;
panelNav.Visible = false;
toolStripStatusLabelaccount.Text = "Account: Not Logged In";
screen = 0;
}
#endregion
#region API
HttpClient httpClient = new HttpClient();
@ -393,7 +439,7 @@ namespace FireWallet
}
}
private async void UpdateBalance()
private async Task UpdateBalance()
{
string response = await APIGet("wallet/" + account + "/balance?account=default", true);
if (response == "Error") return;
@ -471,72 +517,57 @@ namespace FireWallet
return "Error";
}
}
private async void GetInfo()
{
// Get height and progress
String APIresponse = await APIGet("", false);
JObject resp = JObject.Parse(APIresponse);
JObject chain = JObject.Parse(resp["chain"].ToString());
labelHeight.Text = "Height: " + chain["height"].ToString();
decimal progress = Convert.ToDecimal(chain["progress"].ToString());
labelSyncPercent.Text = "Sync: " + decimal.Round(progress * 100, 2) + "%";
// Get Unconfirmed TX
string path = "wallet/" + account + "/tx/unconfirmed";
APIresponse = await APIGet(path, true);
if (APIresponse == "Error")
{
AddLog("GetInfo Error");
return;
}
JArray txs = JArray.Parse(APIresponse);
labelPendingCount.Text = "Unconfirmed TX: " + resp.Count.ToString();
}
#endregion
#region Timers
private void timerNodeStatus_Tick(object sender, EventArgs e)
{
NodeStatus();
// If logged in, update info
if (panelaccount.Visible == false)
{
GetInfo();
}
}
#endregion
private async void LoginClick(object sender, EventArgs e)
{
account = comboBoxaccount.Text;
password = textBoxaccountpassword.Text;
bool loggedin = await Login();
if (loggedin)
{
toolStripStatusLabelaccount.Text = "Account: " + account;
textBoxaccountpassword.Text = "";
panelaccount.Visible = false;
toolStripSplitButtonlogout.Visible = true;
panelNav.Visible = true;
screen = 1;
}
}
private void PasswordEntered(object sender, KeyEventArgs e)
{
if (e.KeyValue == 13)
{
LoginClick(sender, e);
}
}
private void AccountChoose(object sender, EventArgs e)
{
textBoxaccountpassword.Focus();
}
private async void Logout(object sender, EventArgs e)
{
toolStripSplitButtonlogout.Visible = false;
string path = "wallet/" + account + "/lock";
string content = "";
string APIresponse = await APIPost(path, true, content);
if (!APIresponse.Contains("true"))
{
AddLog("Logout failed");
NotifyForm notifyForm = new NotifyForm("Logout Failed\n" + APIresponse);
notifyForm.ShowDialog();
notifyForm.Dispose();
panelaccount.Visible = true;
return;
}
AddLog("Logout successful");
panelaccount.Visible = true;
panelNav.Visible = false;
toolStripStatusLabelaccount.Text = "Account: Not Logged In";
screen = 0;
}
private void buttonPortfolio_Click(object sender, EventArgs e)
#region Nav
private async void buttonPortfolio_Click(object sender, EventArgs e)
{
panelPortfolio.Show();
UpdateBalance();
labelBalance.Text = "Balance: " + balance.ToString() + " HNS";
await UpdateBalance();
GetInfo();
labelBalance.Text = "Available: " + balance.ToString() + " HNS";
labelLocked.Text = "Locked: " + balanceLocked.ToString() + " HNS";
labelBalanceTotal.Text = "Total: " + (balance + balanceLocked).ToString() + " HNS";
}
#endregion
}
}