diff --git a/FireWallet/FireWallet.csproj b/FireWallet/FireWallet.csproj index b57c89e..bfb233c 100644 --- a/FireWallet/FireWallet.csproj +++ b/FireWallet/FireWallet.csproj @@ -8,4 +8,8 @@ enable + + + + \ No newline at end of file diff --git a/FireWallet/MainForm.Designer.cs b/FireWallet/MainForm.Designer.cs index 1bcf042..b7e8410 100644 --- a/FireWallet/MainForm.Designer.cs +++ b/FireWallet/MainForm.Designer.cs @@ -37,11 +37,11 @@ groupBoxaccount = new GroupBox(); label1 = new Label(); comboBoxusername = new ComboBox(); - textBox1 = new TextBox(); - button2 = new Button(); + textBoxaccountpassword = new TextBox(); + buttonaccountlogin = new Button(); labelaccountpassword = new Label(); labelaccountusername = new Label(); - button1 = new Button(); + buttonaccountnew = new Button(); statusStripmain.SuspendLayout(); panelaccount.SuspendLayout(); groupBoxaccount.SuspendLayout(); @@ -92,11 +92,11 @@ // groupBoxaccount.Controls.Add(label1); groupBoxaccount.Controls.Add(comboBoxusername); - groupBoxaccount.Controls.Add(textBox1); - groupBoxaccount.Controls.Add(button2); + groupBoxaccount.Controls.Add(textBoxaccountpassword); + groupBoxaccount.Controls.Add(buttonaccountlogin); groupBoxaccount.Controls.Add(labelaccountpassword); groupBoxaccount.Controls.Add(labelaccountusername); - groupBoxaccount.Controls.Add(button1); + groupBoxaccount.Controls.Add(buttonaccountnew); groupBoxaccount.FlatStyle = FlatStyle.Popup; groupBoxaccount.Location = new Point(458, 155); groupBoxaccount.Name = "groupBoxaccount"; @@ -124,23 +124,23 @@ comboBoxusername.Size = new Size(190, 23); comboBoxusername.TabIndex = 6; // - // textBox1 + // textBoxaccountpassword // - textBox1.Location = new Point(97, 101); - textBox1.Name = "textBox1"; - textBox1.Size = new Size(190, 23); - textBox1.TabIndex = 5; - textBox1.UseSystemPasswordChar = true; + textBoxaccountpassword.Location = new Point(97, 101); + textBoxaccountpassword.Name = "textBoxaccountpassword"; + textBoxaccountpassword.Size = new Size(190, 23); + textBoxaccountpassword.TabIndex = 5; + textBoxaccountpassword.UseSystemPasswordChar = true; // - // button2 + // buttonaccountlogin // - button2.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point); - button2.Location = new Point(188, 164); - button2.Name = "button2"; - button2.Size = new Size(99, 41); - button2.TabIndex = 3; - button2.Text = "button2"; - button2.UseVisualStyleBackColor = true; + buttonaccountlogin.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point); + buttonaccountlogin.Location = new Point(188, 164); + buttonaccountlogin.Name = "buttonaccountlogin"; + buttonaccountlogin.Size = new Size(99, 41); + buttonaccountlogin.TabIndex = 3; + buttonaccountlogin.Text = "Login"; + buttonaccountlogin.UseVisualStyleBackColor = true; // // labelaccountpassword // @@ -162,15 +162,15 @@ labelaccountusername.TabIndex = 1; labelaccountusername.Text = "Account:"; // - // button1 + // buttonaccountnew // - button1.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point); - button1.Location = new Point(6, 164); - button1.Name = "button1"; - button1.Size = new Size(99, 41); - button1.TabIndex = 2; - button1.Text = "button1"; - button1.UseVisualStyleBackColor = true; + buttonaccountnew.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point); + buttonaccountnew.Location = new Point(12, 164); + buttonaccountnew.Name = "buttonaccountnew"; + buttonaccountnew.Size = new Size(99, 41); + buttonaccountnew.TabIndex = 2; + buttonaccountnew.Text = "New"; + buttonaccountnew.UseVisualStyleBackColor = true; // // MainForm // @@ -200,13 +200,13 @@ private ToolStripStatusLabel toolStripStatusLabelstatus; private System.Windows.Forms.Timer timerNodeStatus; private Panel panelaccount; - private Button button2; - private Button button1; + private Button buttonaccountlogin; + private Button buttonaccountnew; private Label labelaccountusername; private Label labelaccountpassword; private GroupBox groupBoxaccount; private Label label1; private ComboBox comboBoxusername; - private TextBox textBox1; + private TextBox textBoxaccountpassword; } } \ No newline at end of file diff --git a/FireWallet/MainForm.cs b/FireWallet/MainForm.cs index 8e2ee92..d7592df 100644 --- a/FireWallet/MainForm.cs +++ b/FireWallet/MainForm.cs @@ -1,4 +1,5 @@ using System.Runtime.InteropServices; +using Newtonsoft.Json.Linq; namespace FireWallet { @@ -26,6 +27,9 @@ namespace FireWallet AddLog("Finished loading"); ResizeForm(); + + // Prompt for login + GetAccounts(); } private void MainForm_Closing(object sender, FormClosingEventArgs e) { @@ -283,12 +287,55 @@ namespace FireWallet [DllImport("user32.dll")] internal static extern int SetWindowCompositionAttribute(IntPtr hwnd, ref WindowCompositionAttributeData data); } + private void Form1_Resize(object sender, EventArgs e) + { + ResizeForm(); + } + private void ResizeForm() + { + groupBoxaccount.Left = (this.ClientSize.Width - groupBoxaccount.Width) / 2; + groupBoxaccount.Top = (this.ClientSize.Height - groupBoxaccount.Height) / 2; + } #endregion + #region Accounts + + private async void GetAccounts() + { + await APIGet("wallet", true); + comboBoxusername.Items.Clear(); + if (APIresponse != "Error") + { + JArray jArray = JArray.Parse(APIresponse); + foreach (string account in jArray) + { + comboBoxusername.Items.Add(account); + } + if (comboBoxusername.Items.Count > 0) + { + comboBoxusername.SelectedIndex = 0; + } + else + { + comboBoxusername.Items.Add("No accounts found"); + comboBoxusername.Enabled = false; + } + } + else + { + comboBoxusername.Items.Add("No accounts found"); + comboBoxusername.Enabled = false; + } + } + + #endregion + private void timerNodeStatus_Tick(object sender, EventArgs e) { NodeStatus(); } + #region API + string APIresponse; private async void NodeStatus() { // This will curl the below URL and return the result @@ -326,15 +373,44 @@ namespace FireWallet toolStripStatusLabelstatus.Text = "Status: Node Not Connected"; } } + private async Task APIGet(string path, bool wallet) + { + // This will curl the below URL and return the result + //curl http://x:api-key@127.0.0.1:12039/wallet/$id/account - private void Form1_Resize(object sender, EventArgs e) - { - ResizeForm(); - } - private void ResizeForm() - { - groupBoxaccount.Left = (this.ClientSize.Width - groupBoxaccount.Width) / 2; - groupBoxaccount.Top = (this.ClientSize.Height - groupBoxaccount.Height) / 2; + string key = nodeSettings["Key"]; + string ip = nodeSettings["IP"]; + + string port = "1203"; + if (Network == 1) + { + port = "1303"; + } + if (wallet) port = port + "9"; + else port = port + "7"; + + + // Create HTTP client + HttpClient httpClient = new HttpClient(); + + try + { + HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://" + ip + ":" + port + "/" + path); + // 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(); + APIresponse = await response.Content.ReadAsStringAsync(); + + } + // Log errors to log textbox + catch (Exception ex) + { + AddLog("Error: " + ex.Message); + APIresponse = "Error"; + } } + #endregion } } \ No newline at end of file diff --git a/README.md b/README.md index 5b287a7..dbd6513 100644 --- a/README.md +++ b/README.md @@ -1 +1,2 @@ -# FireWallet \ No newline at end of file +# FireWallet +Experimental wallet for Handshake chain \ No newline at end of file