main: Started portfolio

This commit is contained in:
Nathan Woodburn 2023-06-06 18:35:11 +10:00
parent b45bfd76d6
commit 2473e4a571
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
3 changed files with 167 additions and 55 deletions

View File

@ -44,9 +44,18 @@
labelaccountpassword = new Label(); labelaccountpassword = new Label();
labelaccountusername = new Label(); labelaccountusername = new Label();
buttonaccountnew = new Button(); buttonaccountnew = new Button();
panelNav = new Panel();
buttonReceive = new Button();
buttonSend = new Button();
buttonPortfolio = new Button();
panelPortfolio = new Panel();
labelLocked = new Label();
labelBalance = new Label();
statusStripmain.SuspendLayout(); statusStripmain.SuspendLayout();
panelaccount.SuspendLayout(); panelaccount.SuspendLayout();
groupBoxaccount.SuspendLayout(); groupBoxaccount.SuspendLayout();
panelNav.SuspendLayout();
panelPortfolio.SuspendLayout();
SuspendLayout(); SuspendLayout();
// //
// statusStripmain // statusStripmain
@ -55,7 +64,7 @@
statusStripmain.Items.AddRange(new ToolStripItem[] { toolStripStatusLabelNetwork, toolStripStatusLabelstatus, toolStripStatusLabelaccount, toolStripSplitButtonlogout }); statusStripmain.Items.AddRange(new ToolStripItem[] { toolStripStatusLabelNetwork, toolStripStatusLabelstatus, toolStripStatusLabelaccount, toolStripSplitButtonlogout });
statusStripmain.Location = new Point(0, 0); statusStripmain.Location = new Point(0, 0);
statusStripmain.Name = "statusStripmain"; statusStripmain.Name = "statusStripmain";
statusStripmain.Size = new Size(1074, 22); statusStripmain.Size = new Size(1152, 22);
statusStripmain.SizingGrip = false; statusStripmain.SizingGrip = false;
statusStripmain.TabIndex = 0; statusStripmain.TabIndex = 0;
statusStripmain.Text = "statusStrip1"; statusStripmain.Text = "statusStrip1";
@ -90,7 +99,7 @@
toolStripSplitButtonlogout.Size = new Size(53, 20); toolStripSplitButtonlogout.Size = new Size(53, 20);
toolStripSplitButtonlogout.Text = "Log out"; toolStripSplitButtonlogout.Text = "Log out";
toolStripSplitButtonlogout.Visible = false; toolStripSplitButtonlogout.Visible = false;
toolStripSplitButtonlogout.ButtonClick += toolStripSplitButtonlogout_ButtonClickAsync; toolStripSplitButtonlogout.ButtonClick += Logout;
// //
// timerNodeStatus // timerNodeStatus
// //
@ -102,8 +111,7 @@
// //
panelaccount.BackColor = Color.Transparent; panelaccount.BackColor = Color.Transparent;
panelaccount.Controls.Add(groupBoxaccount); panelaccount.Controls.Add(groupBoxaccount);
panelaccount.Dock = DockStyle.Fill; panelaccount.Location = new Point(1082, 211);
panelaccount.Location = new Point(0, 22);
panelaccount.Name = "panelaccount"; panelaccount.Name = "panelaccount";
panelaccount.Size = new Size(1074, 642); panelaccount.Size = new Size(1074, 642);
panelaccount.TabIndex = 1; panelaccount.TabIndex = 1;
@ -144,7 +152,7 @@
comboBoxaccount.Name = "comboBoxaccount"; comboBoxaccount.Name = "comboBoxaccount";
comboBoxaccount.Size = new Size(190, 23); comboBoxaccount.Size = new Size(190, 23);
comboBoxaccount.TabIndex = 6; comboBoxaccount.TabIndex = 6;
comboBoxaccount.DropDownClosed += comboBoxaccount_DropDownClosed; comboBoxaccount.DropDownClosed += AccountChoose;
// //
// textBoxaccountpassword // textBoxaccountpassword
// //
@ -153,7 +161,7 @@
textBoxaccountpassword.Size = new Size(190, 23); textBoxaccountpassword.Size = new Size(190, 23);
textBoxaccountpassword.TabIndex = 5; textBoxaccountpassword.TabIndex = 5;
textBoxaccountpassword.UseSystemPasswordChar = true; textBoxaccountpassword.UseSystemPasswordChar = true;
textBoxaccountpassword.KeyDown += textBoxaccountpassword_KeyDown; textBoxaccountpassword.KeyDown += PasswordEntered;
// //
// buttonaccountlogin // buttonaccountlogin
// //
@ -196,11 +204,86 @@
buttonaccountnew.Text = "New"; buttonaccountnew.Text = "New";
buttonaccountnew.UseVisualStyleBackColor = true; buttonaccountnew.UseVisualStyleBackColor = true;
// //
// panelNav
//
panelNav.Controls.Add(buttonReceive);
panelNav.Controls.Add(buttonSend);
panelNav.Controls.Add(buttonPortfolio);
panelNav.Dock = DockStyle.Left;
panelNav.Location = new Point(0, 22);
panelNav.Name = "panelNav";
panelNav.Size = new Size(114, 553);
panelNav.TabIndex = 6;
//
// buttonReceive
//
buttonReceive.FlatStyle = FlatStyle.Flat;
buttonReceive.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
buttonReceive.Location = new Point(12, 134);
buttonReceive.Name = "buttonReceive";
buttonReceive.Size = new Size(89, 30);
buttonReceive.TabIndex = 1;
buttonReceive.Text = "Receive";
buttonReceive.UseVisualStyleBackColor = true;
//
// buttonSend
//
buttonSend.FlatStyle = FlatStyle.Flat;
buttonSend.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
buttonSend.Location = new Point(12, 80);
buttonSend.Name = "buttonSend";
buttonSend.Size = new Size(89, 30);
buttonSend.TabIndex = 1;
buttonSend.Text = "Send";
buttonSend.UseVisualStyleBackColor = true;
//
// buttonPortfolio
//
buttonPortfolio.FlatStyle = FlatStyle.Flat;
buttonPortfolio.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
buttonPortfolio.Location = new Point(12, 25);
buttonPortfolio.Name = "buttonPortfolio";
buttonPortfolio.Size = new Size(89, 30);
buttonPortfolio.TabIndex = 0;
buttonPortfolio.Text = "Portfolio";
buttonPortfolio.UseVisualStyleBackColor = true;
buttonPortfolio.Click += buttonPortfolio_Click;
//
// panelPortfolio
//
panelPortfolio.Controls.Add(labelLocked);
panelPortfolio.Controls.Add(labelBalance);
panelPortfolio.Location = new Point(120, 25);
panelPortfolio.Name = "panelPortfolio";
panelPortfolio.Size = new Size(956, 538);
panelPortfolio.TabIndex = 7;
panelPortfolio.Visible = false;
//
// labelLocked
//
labelLocked.AutoSize = true;
labelLocked.Location = new Point(36, 87);
labelLocked.Name = "labelLocked";
labelLocked.Size = new Size(70, 15);
labelLocked.TabIndex = 1;
labelLocked.Text = "labelLocked";
//
// labelBalance
//
labelBalance.AutoSize = true;
labelBalance.Location = new Point(36, 37);
labelBalance.Name = "labelBalance";
labelBalance.Size = new Size(73, 15);
labelBalance.TabIndex = 0;
labelBalance.Text = "labelBalance";
//
// MainForm // MainForm
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1074, 664); ClientSize = new Size(1152, 575);
Controls.Add(panelPortfolio);
Controls.Add(panelNav);
Controls.Add(panelaccount); Controls.Add(panelaccount);
Controls.Add(statusStripmain); Controls.Add(statusStripmain);
Name = "MainForm"; Name = "MainForm";
@ -213,6 +296,9 @@
panelaccount.ResumeLayout(false); panelaccount.ResumeLayout(false);
groupBoxaccount.ResumeLayout(false); groupBoxaccount.ResumeLayout(false);
groupBoxaccount.PerformLayout(); groupBoxaccount.PerformLayout();
panelNav.ResumeLayout(false);
panelPortfolio.ResumeLayout(false);
panelPortfolio.PerformLayout();
ResumeLayout(false); ResumeLayout(false);
PerformLayout(); PerformLayout();
} }
@ -234,5 +320,12 @@
private TextBox textBoxaccountpassword; private TextBox textBoxaccountpassword;
private ToolStripStatusLabel toolStripStatusLabelstatus; private ToolStripStatusLabel toolStripStatusLabelstatus;
private ToolStripSplitButton toolStripSplitButtonlogout; private ToolStripSplitButton toolStripSplitButtonlogout;
private Panel panelNav;
private Button buttonPortfolio;
private Button buttonSend;
private Button buttonReceive;
private Panel panelPortfolio;
private Label labelLocked;
private Label labelBalance;
} }
} }

View File

@ -13,6 +13,9 @@ namespace FireWallet
int Network; int Network;
string account; string account;
string password; string password;
double balance;
double balanceLocked;
int screen; // 0 = login, 1 = portfolio
#endregion #endregion
#region Application #region Application
@ -26,10 +29,20 @@ namespace FireWallet
UpdateTheme(); UpdateTheme();
LoadNode(); LoadNode();
// Edit the theme of the navigation panel
panelNav.BackColor = ColorTranslator.FromHtml(theme["background-alt"]);
panelNav.ForeColor = ColorTranslator.FromHtml(theme["foreground-alt"]);
foreach (Control c in panelNav.Controls)
{
c.BackColor = ColorTranslator.FromHtml(theme["background"]);
c.ForeColor = ColorTranslator.FromHtml(theme["foreground"]);
}
panelNav.Dock = DockStyle.Left;
AddLog("Finished loading"); AddLog("Finished loading");
ResizeForm(); ResizeForm();
panelNav.Visible = false;
screen = 0;
// Prompt for login // Prompt for login
GetAccounts(); GetAccounts();
@ -153,8 +166,8 @@ namespace FireWallet
// Transparancy this.Width = Screen.PrimaryScreen.Bounds.Width / 5 * 3;
this.Height = Screen.PrimaryScreen.Bounds.Height / 5 * 3;
AddLog("Finished applying theme"); AddLog("Finished applying theme");
AddLog("Applying transparency"); AddLog("Applying transparency");
applyTransparency(theme); applyTransparency(theme);
@ -172,11 +185,12 @@ namespace FireWallet
} }
} }
if (c.GetType() == typeof(TextBox) || c.GetType() == typeof(Button) if (c.GetType() == typeof(TextBox) || c.GetType() == typeof(Button)
|| c.GetType() == typeof(ComboBox) || c.GetType() == typeof(StatusStrip)) || c.GetType() == typeof(ComboBox) || c.GetType() == typeof(StatusStrip) || c.GetType() == typeof(ToolStrip))
{ {
c.ForeColor = ColorTranslator.FromHtml(theme["foreground-alt"]); c.ForeColor = ColorTranslator.FromHtml(theme["foreground-alt"]);
c.BackColor = ColorTranslator.FromHtml(theme["background-alt"]); c.BackColor = ColorTranslator.FromHtml(theme["background-alt"]);
} }
if (c.GetType() == typeof(Panel)) c.Dock = DockStyle.Fill;
} }
private void applyTransparency(Dictionary<string, string> theme) private void applyTransparency(Dictionary<string, string> theme)
@ -358,55 +372,41 @@ namespace FireWallet
return false; return false;
} }
AddLog("Login successful"); AddLog("Login successful");
UpdateBalance();
return true; return true;
} }
#endregion #endregion
private void timerNodeStatus_Tick(object sender, EventArgs e)
{
NodeStatus();
}
#region API #region API
HttpClient httpClient = new HttpClient(); HttpClient httpClient = new HttpClient();
private async void NodeStatus() private async void NodeStatus()
{ {
// This will curl the below URL and return the result
//curl http://x:api-key@127.0.0.1:12039/wallet/$id/account
string key = nodeSettings["Key"]; if (await APIGet("", false) == "Error")
string ip = nodeSettings["IP"];
string port = "1203";
if (Network == 1)
{ {
port = "1303";
}
// Create HTTP client
HttpClient httpClient = new HttpClient();
try
{
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://" + ip + ":" + port + "7");
// Add API key to header
request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes("x:" + key)));
// Send request and log response
HttpResponseMessage response = await httpClient.SendAsync(request);
response.EnsureSuccessStatusCode();
toolStripStatusLabelstatus.Text = "Status: Node Connected";
}
// Log errors to log textbox
catch (Exception ex)
{
AddLog("Connection Failed: " + ex.Message);
toolStripStatusLabelstatus.Text = "Status: Node Not Connected"; toolStripStatusLabelstatus.Text = "Status: Node Not Connected";
} }
else
{
toolStripStatusLabelstatus.Text = "Status: Node Connected";
}
}
private async void UpdateBalance()
{
string response = await APIGet("wallet/" + account + "/balance?account=default", true);
if (response == "Error") return;
JObject resp = JObject.Parse(response);
double available = Convert.ToDouble(resp["unconfirmed"].ToString()) / 1000000;
double locked = Convert.ToDouble(resp["lockedUnconfirmed"].ToString()) / 1000000;
available = available - locked;
available = Math.Round(available, 2);
locked = Math.Round(locked, 2);
balance = available;
balanceLocked = locked;
} }
private async Task<string> APIPost(string path, bool wallet, string content) private async Task<string> APIPost(string path, bool wallet, string content)
@ -432,8 +432,9 @@ namespace FireWallet
{ {
resp.EnsureSuccessStatusCode(); resp.EnsureSuccessStatusCode();
} }
catch catch (Exception ex)
{ {
AddLog("Post Error: " + ex.Message);
return "Error"; return "Error";
} }
@ -466,11 +467,17 @@ namespace FireWallet
// Log errors to log textbox // Log errors to log textbox
catch (Exception ex) catch (Exception ex)
{ {
AddLog("Error: " + ex.Message); AddLog("Get Error: " + ex.Message);
return "Error"; return "Error";
} }
} }
#endregion #endregion
#region Timers
private void timerNodeStatus_Tick(object sender, EventArgs e)
{
NodeStatus();
}
#endregion
private async void LoginClick(object sender, EventArgs e) private async void LoginClick(object sender, EventArgs e)
{ {
@ -483,10 +490,12 @@ namespace FireWallet
textBoxaccountpassword.Text = ""; textBoxaccountpassword.Text = "";
panelaccount.Visible = false; panelaccount.Visible = false;
toolStripSplitButtonlogout.Visible = true; toolStripSplitButtonlogout.Visible = true;
panelNav.Visible = true;
screen = 1;
} }
} }
private void textBoxaccountpassword_KeyDown(object sender, KeyEventArgs e) private void PasswordEntered(object sender, KeyEventArgs e)
{ {
if (e.KeyValue == 13) if (e.KeyValue == 13)
{ {
@ -494,12 +503,12 @@ namespace FireWallet
} }
} }
private void comboBoxaccount_DropDownClosed(object sender, EventArgs e) private void AccountChoose(object sender, EventArgs e)
{ {
textBoxaccountpassword.Focus(); textBoxaccountpassword.Focus();
} }
private async void toolStripSplitButtonlogout_ButtonClickAsync(object sender, EventArgs e) private async void Logout(object sender, EventArgs e)
{ {
toolStripSplitButtonlogout.Visible = false; toolStripSplitButtonlogout.Visible = false;
string path = "wallet/" + account + "/lock"; string path = "wallet/" + account + "/lock";
@ -516,8 +525,18 @@ namespace FireWallet
} }
AddLog("Logout successful"); AddLog("Logout successful");
panelaccount.Visible = true; panelaccount.Visible = true;
panelNav.Visible = false;
toolStripStatusLabelaccount.Text = "Account: Not Logged In"; toolStripStatusLabelaccount.Text = "Account: Not Logged In";
screen = 0;
} }
private void buttonPortfolio_Click(object sender, EventArgs e)
{
panelPortfolio.Show();
UpdateBalance();
labelBalance.Text = "Balance: " + balance.ToString() + " HNS";
labelLocked.Text = "Locked: " + balanceLocked.ToString() + " HNS";
}
} }
} }

View File

@ -118,9 +118,9 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<metadata name="statusStripmain.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="statusStripmain.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="timerNodeStatus.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>133, 17</value> <value>133, 17</value>
</metadata> </metadata>
<metadata name="timerNodeStatus.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>269, 17</value>
</metadata>
</root> </root>