From f06bc5b7119d75841ee4d87d287e883bae41bdff Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Thu, 15 Jun 2023 16:47:59 +1000 Subject: [PATCH] mainForm.cs: Added domain sorting feature and updated UI - Added comboBoxDomainSort_DropDownClosed method to update domains - Added comboBoxDomainSort control to panelDomains - Added labelDomainSort control to MainForm.Designer.cs - Updated UpdateDomains method to sort domains based on selected option --- FireWallet/MainForm.Designer.cs | 31 +++++++++++++++++++++++++++++- FireWallet/MainForm.cs | 34 +++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/FireWallet/MainForm.Designer.cs b/FireWallet/MainForm.Designer.cs index 3f63c95..2e25f73 100644 --- a/FireWallet/MainForm.Designer.cs +++ b/FireWallet/MainForm.Designer.cs @@ -95,6 +95,7 @@ namespace FireWallet textBoxReceiveAddress = new TextBox(); labelReceive1 = new Label(); panelDomains = new Panel(); + comboBoxDomainSort = new ComboBox(); buttonExportDomains = new Button(); groupBoxDomains = new GroupBox(); panelDomainList = new Panel(); @@ -122,6 +123,7 @@ namespace FireWallet textBoxExAddr = new TextBox(); labelSettings4 = new Label(); textBoxExTX = new TextBox(); + labelDomainSort = new Label(); statusStripmain.SuspendLayout(); panelaccount.SuspendLayout(); groupBoxaccount.SuspendLayout(); @@ -783,6 +785,8 @@ namespace FireWallet // // panelDomains // + panelDomains.Controls.Add(labelDomainSort); + panelDomains.Controls.Add(comboBoxDomainSort); panelDomains.Controls.Add(buttonRenewAll); panelDomains.Controls.Add(buttonExportDomains); panelDomains.Controls.Add(groupBoxDomains); @@ -794,6 +798,19 @@ namespace FireWallet panelDomains.TabIndex = 18; panelDomains.Visible = false; // + // comboBoxDomainSort + // + comboBoxDomainSort.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxDomainSort.FlatStyle = FlatStyle.Flat; + comboBoxDomainSort.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point); + comboBoxDomainSort.FormattingEnabled = true; + comboBoxDomainSort.Items.AddRange(new object[] { "Default", "Alphabetical", "Expiring", "Value" }); + comboBoxDomainSort.Location = new Point(686, 12); + comboBoxDomainSort.Name = "comboBoxDomainSort"; + comboBoxDomainSort.Size = new Size(121, 29); + comboBoxDomainSort.TabIndex = 11; + comboBoxDomainSort.DropDownClosed += comboBoxDomainSort_DropDownClosed; + // // buttonExportDomains // buttonExportDomains.FlatStyle = FlatStyle.Flat; @@ -1064,17 +1081,27 @@ namespace FireWallet textBoxExTX.Size = new Size(307, 29); textBoxExTX.TabIndex = 1; // + // labelDomainSort + // + labelDomainSort.AutoSize = true; + labelDomainSort.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point); + labelDomainSort.Location = new Point(638, 15); + labelDomainSort.Name = "labelDomainSort"; + labelDomainSort.Size = new Size(42, 21); + labelDomainSort.TabIndex = 12; + labelDomainSort.Text = "Sort:"; + // // MainForm // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(1152, 575); + Controls.Add(panelDomains); Controls.Add(panelSend); Controls.Add(panelSettings); Controls.Add(panelaccount); Controls.Add(panelPortfolio); Controls.Add(panelRecieve); - Controls.Add(panelDomains); Controls.Add(panelNav); Controls.Add(statusStripmain); Icon = (Icon)resources.GetObject("$this.Icon"); @@ -1205,5 +1232,7 @@ namespace FireWallet private ToolStripMenuItem supportDiscordServerToolStripMenuItem; private Label labelHIPArrow; private Label labelSendingHIPAddress; + private ComboBox comboBoxDomainSort; + private Label labelDomainSort; } } \ No newline at end of file diff --git a/FireWallet/MainForm.cs b/FireWallet/MainForm.cs index 81bfc7e..67188fa 100644 --- a/FireWallet/MainForm.cs +++ b/FireWallet/MainForm.cs @@ -1216,6 +1216,8 @@ namespace FireWallet groupBoxDomains.Width = panelDomains.Width - 20; groupBoxDomains.Left = 10; groupBoxDomains.Height = panelDomains.Height - groupBoxDomains.Top - 10; + comboBoxDomainSort.SelectedIndex = 0; + UpdateDomains(); } @@ -1881,6 +1883,33 @@ namespace FireWallet int i = 0; int renewable = 0; panelDomainList.Controls.Clear(); + + // Sort the domains + switch (comboBoxDomainSort.Text) + { + case "Default": + break; + case "Alphabetical": + names = new JArray(names.OrderBy(obj => (string)obj["name"])); + break; + case "Expiring": + names = new JArray(names.OrderBy(obj => + { + JToken daysUntilExpireToken = obj["stats"]?["daysUntilExpire"]; + return (int)(daysUntilExpireToken ?? int.MaxValue); + })); + break; + case "Value": + // Sort by most valuable first + names = new JArray(names.OrderByDescending(obj => + { + JToken valueToken = obj?["value"]; + return (int)(valueToken ?? 0); + })); + break; + } + + foreach (JObject name in names) { Domains[i] = name["name"].ToString(); @@ -2212,5 +2241,10 @@ namespace FireWallet }; Process.Start(psi); } + + private void comboBoxDomainSort_DropDownClosed(object sender, EventArgs e) + { + UpdateDomains(); + } } } \ No newline at end of file