diff --git a/FireWallet/DomainForm.Designer.cs b/FireWallet/DomainForm.Designer.cs index 5ae6e48..c651cf6 100644 --- a/FireWallet/DomainForm.Designer.cs +++ b/FireWallet/DomainForm.Designer.cs @@ -46,9 +46,18 @@ panelDNS = new Panel(); groupBoxBids = new GroupBox(); panelBids = new Panel(); + groupBoxAction = new GroupBox(); + textBoxBlind = new TextBox(); + textBoxBid = new TextBox(); + labelBlind = new Label(); + labelBid = new Label(); + buttonActionAlt = new Button(); + buttonActionMain = new Button(); + buttonExplorer = new Button(); groupBoxStatus.SuspendLayout(); groupBoxDNS.SuspendLayout(); groupBoxBids.SuspendLayout(); + groupBoxAction.SuspendLayout(); SuspendLayout(); // // labelTitle @@ -229,11 +238,101 @@ panelBids.Size = new System.Drawing.Size(956, 291); panelBids.TabIndex = 0; // + // groupBoxAction + // + groupBoxAction.Controls.Add(textBoxBlind); + groupBoxAction.Controls.Add(textBoxBid); + groupBoxAction.Controls.Add(labelBlind); + groupBoxAction.Controls.Add(labelBid); + groupBoxAction.Controls.Add(buttonActionAlt); + groupBoxAction.Controls.Add(buttonActionMain); + groupBoxAction.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point); + groupBoxAction.Location = new System.Drawing.Point(396, 68); + groupBoxAction.Name = "groupBoxAction"; + groupBoxAction.Size = new System.Drawing.Size(575, 173); + groupBoxAction.TabIndex = 14; + groupBoxAction.TabStop = false; + groupBoxAction.Text = "Bid"; + groupBoxAction.Visible = false; + // + // textBoxBlind + // + textBoxBlind.Location = new System.Drawing.Point(60, 64); + textBoxBlind.Name = "textBoxBlind"; + textBoxBlind.Size = new System.Drawing.Size(180, 29); + textBoxBlind.TabIndex = 5; + textBoxBlind.Visible = false; + textBoxBlind.TextChanged += textBoxBlind_TextChanged; + // + // textBoxBid + // + textBoxBid.Location = new System.Drawing.Point(60, 22); + textBoxBid.Name = "textBoxBid"; + textBoxBid.Size = new System.Drawing.Size(180, 29); + textBoxBid.TabIndex = 4; + textBoxBid.Visible = false; + textBoxBid.TextChanged += textBoxBlind_TextChanged; + // + // labelBlind + // + labelBlind.AutoSize = true; + labelBlind.Location = new System.Drawing.Point(6, 67); + labelBlind.Name = "labelBlind"; + labelBlind.Size = new System.Drawing.Size(48, 21); + labelBlind.TabIndex = 3; + labelBlind.Text = "Blind:"; + labelBlind.Visible = false; + // + // labelBid + // + labelBid.AutoSize = true; + labelBid.Location = new System.Drawing.Point(19, 25); + labelBid.Name = "labelBid"; + labelBid.Size = new System.Drawing.Size(35, 21); + labelBid.TabIndex = 2; + labelBid.Text = "Bid:"; + labelBid.Visible = false; + // + // buttonActionAlt + // + buttonActionAlt.FlatStyle = FlatStyle.Flat; + buttonActionAlt.Location = new System.Drawing.Point(253, 130); + buttonActionAlt.Name = "buttonActionAlt"; + buttonActionAlt.Size = new System.Drawing.Size(155, 37); + buttonActionAlt.TabIndex = 1; + buttonActionAlt.Text = "Bid in Batch"; + buttonActionAlt.UseVisualStyleBackColor = true; + // + // buttonActionMain + // + buttonActionMain.FlatStyle = FlatStyle.Flat; + buttonActionMain.Location = new System.Drawing.Point(414, 130); + buttonActionMain.Name = "buttonActionMain"; + buttonActionMain.Size = new System.Drawing.Size(155, 37); + buttonActionMain.TabIndex = 0; + buttonActionMain.Text = "Send Bid"; + buttonActionMain.UseVisualStyleBackColor = true; + buttonActionMain.Click += buttonActionMain_Click; + // + // buttonExplorer + // + buttonExplorer.FlatStyle = FlatStyle.Flat; + buttonExplorer.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point); + buttonExplorer.Location = new System.Drawing.Point(876, 12); + buttonExplorer.Name = "buttonExplorer"; + buttonExplorer.Size = new System.Drawing.Size(98, 34); + buttonExplorer.TabIndex = 15; + buttonExplorer.Text = "Explorer"; + buttonExplorer.UseVisualStyleBackColor = true; + buttonExplorer.Click += Explorer_Click; + // // DomainForm // AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new System.Drawing.Size(986, 572); + Controls.Add(buttonExplorer); + Controls.Add(groupBoxAction); Controls.Add(groupBoxBids); Controls.Add(groupBoxDNS); Controls.Add(groupBoxStatus); @@ -247,6 +346,8 @@ groupBoxStatus.PerformLayout(); groupBoxDNS.ResumeLayout(false); groupBoxBids.ResumeLayout(false); + groupBoxAction.ResumeLayout(false); + groupBoxAction.PerformLayout(); ResumeLayout(false); PerformLayout(); } @@ -271,5 +372,13 @@ private Panel panelDNS; private GroupBox groupBoxBids; private Panel panelBids; + private GroupBox groupBoxAction; + private TextBox textBoxBlind; + private TextBox textBoxBid; + private Label labelBlind; + private Label labelBid; + private Button buttonActionAlt; + private Button buttonActionMain; + private Button buttonExplorer; } } \ No newline at end of file diff --git a/FireWallet/DomainForm.cs b/FireWallet/DomainForm.cs index e270df9..2307f5b 100644 --- a/FireWallet/DomainForm.cs +++ b/FireWallet/DomainForm.cs @@ -2,11 +2,13 @@ using System.Collections.Generic; using System.ComponentModel; using System.Data; +using System.Diagnostics; using System.Drawing; using System.Linq; using System.Net.Http; using System.Runtime.InteropServices; using System.Text; +using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows.Forms; using BitMiracle.LibTiff.Classic; @@ -23,13 +25,21 @@ namespace FireWallet string domain; int network; int height; + bool own; + string state; + string explorerTX; + string explorerName; - public DomainForm(string domain) + public Form OriginalForm { get; set; } + + public DomainForm(string domain, string explorerTX, string explorerName) { InitializeComponent(); this.Text = domain + "/ | FireWallet"; labelTitle.Text = domain + "/"; this.domain = domain; + this.explorerTX = explorerTX; + this.explorerName = explorerName; } #region Theming @@ -208,6 +218,7 @@ namespace FireWallet private void DomainForm_Load(object sender, EventArgs e) { UpdateTheme(); + own = false; StreamReader sr = new StreamReader(dir + "node.txt"); nodeSettings = new Dictionary(); while (!sr.EndOfStream) @@ -227,6 +238,7 @@ namespace FireWallet network = Convert.ToInt32(nodeSettings["Network"]); GetName(); } + #region API private async void GetName() { try @@ -293,13 +305,14 @@ namespace FireWallet else if (state == "BIDDING" || state == "REVEAL") GetBids(state); else groupBoxDNS.Visible = false; - - + //Setup action box + ActionSetup(state); } catch (Exception ex) { // No info -> Domain not yet auctioned labelStatusMain.Text = "Available"; + ActionSetup("AVAILABLE"); AddLog(ex.Message); AddLog(result.ToString()); } @@ -420,10 +433,19 @@ namespace FireWallet if (!response.Contains("\"error\":null")) { AddLog("Syncing Domain"); + Label syncingLabel = new Label(); + syncingLabel.Text = "Syncing Bids..."; + syncingLabel.Location = new System.Drawing.Point(10, 10); + syncingLabel.AutoSize = true; + panelBids.Controls.Add(syncingLabel); + // Error // Try scanning for auction contentBids = "{\"method\": \"importname\", \"params\": [\"" + domain + "\", " + (height - 2000) + "]}"; + await APIPost("", true, contentBids); + contentBids = "{\"method\": \"getauctioninfo\", \"params\": [\"" + domain + "\"]}"; response = await APIPost("", true, contentBids); + panelBids.Controls.Clear(); } if (state == "BIDDING") @@ -466,6 +488,7 @@ namespace FireWallet } else if (state == "REVEAL") { + //! TODO Add reveal info JObject resp = JObject.Parse(response); JObject result = (JObject)resp["result"]; JArray bids = (JArray)result["bids"]; @@ -473,6 +496,7 @@ namespace FireWallet int i = 1; foreach (JObject bid in bids) { + Panel bidPanel = new Panel(); // Count for scroll width bidPanel.Width = panelBids.Width - SystemInformation.VerticalScrollBarWidth - 2; @@ -486,7 +510,6 @@ namespace FireWallet bidNumber.Font = new Font(bidNumber.Font.FontFamily, 11.0f, FontStyle.Bold); bidPanel.Controls.Add(bidNumber); Label bidAmount = new Label(); - bidAmount.Text = convertHNS(bid["lockup"].ToString()) + " HNS"; bidAmount.Location = new System.Drawing.Point(10, 30); bidAmount.AutoSize = true; @@ -517,7 +540,7 @@ namespace FireWallet } - #region API + HttpClient httpClient = new HttpClient(); /// /// Post to HSD API @@ -552,6 +575,7 @@ namespace FireWallet catch (Exception ex) { AddLog("Post Error: " + ex.Message); + AddLog("Post Error: " + await resp.Content.ReadAsStringAsync()); return "Error"; } @@ -601,5 +625,198 @@ namespace FireWallet sw.Dispose(); } #endregion + + private void ActionSetup(string state) + { + this.state = state; + switch (state) + { + case "AVAILABLE": + groupBoxAction.Show(); + groupBoxAction.Text = "Open Auction"; + buttonActionMain.Text = "Send Open"; + buttonActionAlt.Text = "Open in Batch"; + break; + case "BIDDING": + groupBoxAction.Show(); + labelBid.Show(); + textBoxBid.Show(); + labelBlind.Show(); + textBoxBlind.Show(); + break; + case "REVEAL": + groupBoxAction.Show(); + groupBoxAction.Text = "Reveal Bid"; + buttonActionMain.Text = "Send Reveal"; + buttonActionAlt.Text = "Reveal in Batch"; + break; + case "CLOSED": + if (own) + { + if (labelStatusTransferring.Text == "Yes") + { + // Check if can finalize + + } + else + { + groupBoxAction.Show(); + groupBoxAction.Text = "Edit"; + buttonActionMain.Text = "Edit DNS"; + buttonActionAlt.Text = "Edit in Batch"; + } + } + break; + } + } + private void textBoxBlind_TextChanged(object sender, EventArgs e) + { + string cleanedText = Regex.Replace(textBoxBid.Text, "[^0-9.]", ""); + textBoxBid.Text = cleanedText; + cleanedText = Regex.Replace(textBoxBlind.Text, "[^0-9.]", ""); + textBoxBlind.Text = cleanedText; + } + + private async void buttonActionMain_Click(object sender, EventArgs e) + { + if (state == "BIDDING") + { + int count = textBoxBid.Text.Count(c => c == '.'); + int count2 = textBoxBlind.Text.Count(c => c == '.'); + if (count > 1 || count2 > 1) + { + NotifyForm notifyForm = new NotifyForm("Invalid bid amount"); + notifyForm.ShowDialog(); + notifyForm.Dispose(); + return; + } + if (textBoxBid.Text == "" || textBoxBid.Text == ".") + { + textBoxBid.Text = "0"; + } + if (textBoxBlind.Text == "" || textBoxBlind.Text == ".") + { + textBoxBlind.Text = "0"; + } + await APIPost("", true, "{\"method\": \"selectwallet\", \"params\": [\"" + explorerTX + "\"]}"); + decimal bid = Convert.ToDecimal(textBoxBid.Text); + decimal blind = Convert.ToDecimal(textBoxBlind.Text); + decimal lockup = bid + blind; + string content = "{\"method\": \"sendbid\", \"params\": [\"" + domain + "\", " + bid.ToString() + ", " + lockup.ToString() + "]}"; + + string response = await APIPost("", true, content); + + if (response == "Error") + { + NotifyForm notifyForm = new NotifyForm("Error sending bid"); + notifyForm.ShowDialog(); + notifyForm.Dispose(); + } + else + { + JObject jObject = JObject.Parse(response); + if (jObject["result"].ToString() == "") + { + JObject error = (JObject)jObject["error"]; + string message = (string)error["message"]; + NotifyForm notifyForm2 = new NotifyForm("Error sending bid: \n" + message); + notifyForm2.ShowDialog(); + notifyForm2.Dispose(); + return; + } + JObject result = (JObject)jObject["result"]; + string hash = (string)result["hash"]; + + NotifyForm notifyForm = new NotifyForm("Bid sent: " + hash, "Explorer", explorerTX + hash); + notifyForm.ShowDialog(); + notifyForm.Dispose(); + + } + + } + else if (state == "REVEAL") + { + await APIPost("", true, "{\"method\": \"selectwallet\", \"params\": [\"" + explorerTX + "\"]}"); + decimal bid = Convert.ToDecimal(textBoxBid.Text); + decimal blind = Convert.ToDecimal(textBoxBlind.Text); + decimal lockup = bid + blind; + string content = "{\"method\": \"sendreveal\", \"params\": [\"" + domain + "\"]}"; + + string response = await APIPost("", true, content); + + if (response == "Error") + { + NotifyForm notifyForm = new NotifyForm("Error sending reveal"); + notifyForm.ShowDialog(); + notifyForm.Dispose(); + } + else + { + JObject jObject = JObject.Parse(response); + if (jObject["result"].ToString() == "") + { + JObject error = (JObject)jObject["error"]; + string message = (string)error["message"]; + NotifyForm notifyForm2 = new NotifyForm("Error sending reveal: \n" + message); + notifyForm2.ShowDialog(); + notifyForm2.Dispose(); + return; + } + JObject result = (JObject)jObject["result"]; + string hash = (string)result["hash"]; + + NotifyForm notifyForm = new NotifyForm("Reveal sent: " + hash, "Explorer", explorerTX + hash); + notifyForm.ShowDialog(); + notifyForm.Dispose(); + + } + } + else if (state == "AVAILABLE") + { + await APIPost("", true, "{\"method\": \"selectwallet\", \"params\": [\"" + explorerTX + "\"]}"); + decimal bid = Convert.ToDecimal(textBoxBid.Text); + decimal blind = Convert.ToDecimal(textBoxBlind.Text); + decimal lockup = bid + blind; + string content = "{\"method\": \"sendopen\", \"params\": [\"" + domain + "\"]}"; + + string response = await APIPost("", true, content); + + if (response == "Error") + { + NotifyForm notifyForm = new NotifyForm("Error sending open"); + notifyForm.ShowDialog(); + notifyForm.Dispose(); + } + else + { + JObject jObject = JObject.Parse(response); + if (jObject["result"].ToString() == "") + { + JObject error = (JObject)jObject["error"]; + string message = (string)error["message"]; + NotifyForm notifyForm2 = new NotifyForm("Error sending open: \n" + message); + notifyForm2.ShowDialog(); + notifyForm2.Dispose(); + return; + } + JObject result = (JObject)jObject["result"]; + string hash = (string)result["hash"]; + + NotifyForm notifyForm = new NotifyForm("Open sent: " + hash, "Explorer", explorerTX + hash); + notifyForm.ShowDialog(); + notifyForm.Dispose(); + } + } + } + + private void Explorer_Click(object sender, EventArgs e) + { + ProcessStartInfo psi = new ProcessStartInfo + { + FileName = explorerName + domain, + UseShellExecute = true + }; + Process.Start(psi); + } } } diff --git a/FireWallet/MainForm.cs b/FireWallet/MainForm.cs index 8f534af..0b16e82 100644 --- a/FireWallet/MainForm.cs +++ b/FireWallet/MainForm.cs @@ -10,6 +10,7 @@ using Newtonsoft.Json.Linq; using Point = System.Drawing.Point; using Size = System.Drawing.Size; using IronBarCode; +using static System.Windows.Forms.DataFormats; namespace FireWallet { @@ -129,6 +130,8 @@ namespace FireWallet sw.WriteLine("explorer-tx: https://niami.io/tx/"); sw.WriteLine("explorer-addr: https://niami.io/address/"); sw.WriteLine("explorer-block: https://niami.io/block/"); + sw.WriteLine("explorer-domain: https://niami.io/domain/"); + sw.WriteLine("confirmations: 1"); sw.Dispose(); } @@ -146,7 +149,7 @@ namespace FireWallet #endregion #region Logging - private void AddLog(string message) + public void AddLog(string message) { StreamWriter sw = new StreamWriter(dir + "log.txt", true); sw.WriteLine(DateTime.Now.ToString() + ": " + message); @@ -463,7 +466,7 @@ namespace FireWallet panelPortfolio.Visible = false; toolStripStatusLabelaccount.Text = "Account: Not Logged In"; screen = 0; - + textBoxaccountpassword.Focus(); } #endregion #region API @@ -622,8 +625,10 @@ namespace FireWallet Control[] tmpControls = new Control[txCount]; for (int i = 0; i < txCount; i++) { + // Get last tx JObject tx = JObject.Parse(txs[txs.Count - 1 - i].ToString()); + string hash = tx["hash"].ToString(); string date = tx["mdate"].ToString(); @@ -641,7 +646,20 @@ namespace FireWallet Location = new Point(10, 5) } ); - + int confirmations = Convert.ToInt32(tx["confirmations"].ToString()); + if (userSettings.ContainsKey("confirmations")) + { + if (confirmations < Convert.ToInt32(userSettings["confirmations"])) + { + Label txPending = new Label() + { + Text = "Pending", + Location = new Point(100, 5) + }; + tmpPanel.Controls.Add(txPending); + txPending.BringToFront(); + } + } Label labelHash = new Label() { Text = "Hash: " + hash.Substring(0, 10) + "..." + hash.Substring(hash.Length - 10), @@ -1007,7 +1025,9 @@ namespace FireWallet if (e.KeyValue == 13) { e.SuppressKeyPress = true; - DomainForm domainForm = new DomainForm(textBoxDomainSearch.Text); + DomainForm domainForm = new DomainForm(textBoxDomainSearch.Text, userSettings["explorer-tx"], userSettings["explorer-domain"]); + domainForm.OriginalForm = this; + domainForm.Show(); }