mirror of
https://github.com/Nathanwoodburn/FireWallet.git
synced 2024-11-24 08:08:14 +11:00
main: Started portfolio
This commit is contained in:
parent
b45bfd76d6
commit
2473e4a571
107
FireWallet/MainForm.Designer.cs
generated
107
FireWallet/MainForm.Designer.cs
generated
@ -44,9 +44,18 @@
|
||||
labelaccountpassword = new Label();
|
||||
labelaccountusername = new Label();
|
||||
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();
|
||||
panelaccount.SuspendLayout();
|
||||
groupBoxaccount.SuspendLayout();
|
||||
panelNav.SuspendLayout();
|
||||
panelPortfolio.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// statusStripmain
|
||||
@ -55,7 +64,7 @@
|
||||
statusStripmain.Items.AddRange(new ToolStripItem[] { toolStripStatusLabelNetwork, toolStripStatusLabelstatus, toolStripStatusLabelaccount, toolStripSplitButtonlogout });
|
||||
statusStripmain.Location = new Point(0, 0);
|
||||
statusStripmain.Name = "statusStripmain";
|
||||
statusStripmain.Size = new Size(1074, 22);
|
||||
statusStripmain.Size = new Size(1152, 22);
|
||||
statusStripmain.SizingGrip = false;
|
||||
statusStripmain.TabIndex = 0;
|
||||
statusStripmain.Text = "statusStrip1";
|
||||
@ -90,7 +99,7 @@
|
||||
toolStripSplitButtonlogout.Size = new Size(53, 20);
|
||||
toolStripSplitButtonlogout.Text = "Log out";
|
||||
toolStripSplitButtonlogout.Visible = false;
|
||||
toolStripSplitButtonlogout.ButtonClick += toolStripSplitButtonlogout_ButtonClickAsync;
|
||||
toolStripSplitButtonlogout.ButtonClick += Logout;
|
||||
//
|
||||
// timerNodeStatus
|
||||
//
|
||||
@ -102,8 +111,7 @@
|
||||
//
|
||||
panelaccount.BackColor = Color.Transparent;
|
||||
panelaccount.Controls.Add(groupBoxaccount);
|
||||
panelaccount.Dock = DockStyle.Fill;
|
||||
panelaccount.Location = new Point(0, 22);
|
||||
panelaccount.Location = new Point(1082, 211);
|
||||
panelaccount.Name = "panelaccount";
|
||||
panelaccount.Size = new Size(1074, 642);
|
||||
panelaccount.TabIndex = 1;
|
||||
@ -144,7 +152,7 @@
|
||||
comboBoxaccount.Name = "comboBoxaccount";
|
||||
comboBoxaccount.Size = new Size(190, 23);
|
||||
comboBoxaccount.TabIndex = 6;
|
||||
comboBoxaccount.DropDownClosed += comboBoxaccount_DropDownClosed;
|
||||
comboBoxaccount.DropDownClosed += AccountChoose;
|
||||
//
|
||||
// textBoxaccountpassword
|
||||
//
|
||||
@ -153,7 +161,7 @@
|
||||
textBoxaccountpassword.Size = new Size(190, 23);
|
||||
textBoxaccountpassword.TabIndex = 5;
|
||||
textBoxaccountpassword.UseSystemPasswordChar = true;
|
||||
textBoxaccountpassword.KeyDown += textBoxaccountpassword_KeyDown;
|
||||
textBoxaccountpassword.KeyDown += PasswordEntered;
|
||||
//
|
||||
// buttonaccountlogin
|
||||
//
|
||||
@ -196,11 +204,86 @@
|
||||
buttonaccountnew.Text = "New";
|
||||
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
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1074, 664);
|
||||
ClientSize = new Size(1152, 575);
|
||||
Controls.Add(panelPortfolio);
|
||||
Controls.Add(panelNav);
|
||||
Controls.Add(panelaccount);
|
||||
Controls.Add(statusStripmain);
|
||||
Name = "MainForm";
|
||||
@ -213,6 +296,9 @@
|
||||
panelaccount.ResumeLayout(false);
|
||||
groupBoxaccount.ResumeLayout(false);
|
||||
groupBoxaccount.PerformLayout();
|
||||
panelNav.ResumeLayout(false);
|
||||
panelPortfolio.ResumeLayout(false);
|
||||
panelPortfolio.PerformLayout();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
@ -234,5 +320,12 @@
|
||||
private TextBox textBoxaccountpassword;
|
||||
private ToolStripStatusLabel toolStripStatusLabelstatus;
|
||||
private ToolStripSplitButton toolStripSplitButtonlogout;
|
||||
private Panel panelNav;
|
||||
private Button buttonPortfolio;
|
||||
private Button buttonSend;
|
||||
private Button buttonReceive;
|
||||
private Panel panelPortfolio;
|
||||
private Label labelLocked;
|
||||
private Label labelBalance;
|
||||
}
|
||||
}
|
@ -13,6 +13,9 @@ namespace FireWallet
|
||||
int Network;
|
||||
string account;
|
||||
string password;
|
||||
double balance;
|
||||
double balanceLocked;
|
||||
int screen; // 0 = login, 1 = portfolio
|
||||
|
||||
#endregion
|
||||
#region Application
|
||||
@ -26,10 +29,20 @@ namespace FireWallet
|
||||
UpdateTheme();
|
||||
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");
|
||||
ResizeForm();
|
||||
panelNav.Visible = false;
|
||||
screen = 0;
|
||||
|
||||
// Prompt for login
|
||||
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("Applying transparency");
|
||||
applyTransparency(theme);
|
||||
@ -172,11 +185,12 @@ namespace FireWallet
|
||||
}
|
||||
}
|
||||
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.BackColor = ColorTranslator.FromHtml(theme["background-alt"]);
|
||||
}
|
||||
if (c.GetType() == typeof(Panel)) c.Dock = DockStyle.Fill;
|
||||
}
|
||||
|
||||
private void applyTransparency(Dictionary<string, string> theme)
|
||||
@ -358,55 +372,41 @@ namespace FireWallet
|
||||
return false;
|
||||
}
|
||||
AddLog("Login successful");
|
||||
UpdateBalance();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
private void timerNodeStatus_Tick(object sender, EventArgs e)
|
||||
{
|
||||
NodeStatus();
|
||||
}
|
||||
#region API
|
||||
HttpClient httpClient = new HttpClient();
|
||||
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"];
|
||||
string ip = nodeSettings["IP"];
|
||||
|
||||
string port = "1203";
|
||||
if (Network == 1)
|
||||
if (await APIGet("", false) == "Error")
|
||||
{
|
||||
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";
|
||||
}
|
||||
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)
|
||||
@ -432,8 +432,9 @@ namespace FireWallet
|
||||
{
|
||||
resp.EnsureSuccessStatusCode();
|
||||
}
|
||||
catch
|
||||
catch (Exception ex)
|
||||
{
|
||||
AddLog("Post Error: " + ex.Message);
|
||||
return "Error";
|
||||
}
|
||||
|
||||
@ -466,11 +467,17 @@ namespace FireWallet
|
||||
// Log errors to log textbox
|
||||
catch (Exception ex)
|
||||
{
|
||||
AddLog("Error: " + ex.Message);
|
||||
AddLog("Get Error: " + ex.Message);
|
||||
return "Error";
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region Timers
|
||||
private void timerNodeStatus_Tick(object sender, EventArgs e)
|
||||
{
|
||||
NodeStatus();
|
||||
}
|
||||
#endregion
|
||||
|
||||
private async void LoginClick(object sender, EventArgs e)
|
||||
{
|
||||
@ -483,10 +490,12 @@ namespace FireWallet
|
||||
textBoxaccountpassword.Text = "";
|
||||
panelaccount.Visible = false;
|
||||
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)
|
||||
{
|
||||
@ -494,12 +503,12 @@ namespace FireWallet
|
||||
}
|
||||
}
|
||||
|
||||
private void comboBoxaccount_DropDownClosed(object sender, EventArgs e)
|
||||
private void AccountChoose(object sender, EventArgs e)
|
||||
{
|
||||
textBoxaccountpassword.Focus();
|
||||
}
|
||||
|
||||
private async void toolStripSplitButtonlogout_ButtonClickAsync(object sender, EventArgs e)
|
||||
private async void Logout(object sender, EventArgs e)
|
||||
{
|
||||
toolStripSplitButtonlogout.Visible = false;
|
||||
string path = "wallet/" + account + "/lock";
|
||||
@ -516,8 +525,18 @@ namespace FireWallet
|
||||
}
|
||||
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)
|
||||
{
|
||||
panelPortfolio.Show();
|
||||
UpdateBalance();
|
||||
labelBalance.Text = "Balance: " + balance.ToString() + " HNS";
|
||||
labelLocked.Text = "Locked: " + balanceLocked.ToString() + " HNS";
|
||||
}
|
||||
}
|
||||
}
|
@ -118,9 +118,9 @@
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<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>
|
||||
</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>
|
Loading…
Reference in New Issue
Block a user