domain: Added initial domain form

This commit is contained in:
Nathan Woodburn 2023-06-07 17:51:45 +10:00
parent 396c7b30dd
commit 072f32f9a9
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
5 changed files with 1108 additions and 8 deletions

275
FireWallet/DomainForm.Designer.cs generated Normal file
View File

@ -0,0 +1,275 @@
namespace FireWallet
{
partial class DomainForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
labelTitle = new Label();
groupBoxStatus = new GroupBox();
labelStatusTimeToNext = new Label();
labelStatusNextState = new Label();
labelStatusTransferring = new Label();
labelStatus5 = new Label();
labelStatusPaid = new Label();
labelStatus4 = new Label();
labelStatusHighest = new Label();
labelStatus3 = new Label();
labelStatusReserved = new Label();
labelStatus2 = new Label();
labelStatusMain = new Label();
labelStatus1 = new Label();
groupBoxDNS = new GroupBox();
panelDNS = new Panel();
groupBoxBids = new GroupBox();
panelBids = new Panel();
groupBoxStatus.SuspendLayout();
groupBoxDNS.SuspendLayout();
groupBoxBids.SuspendLayout();
SuspendLayout();
//
// labelTitle
//
labelTitle.AutoSize = true;
labelTitle.Font = new Font("Segoe UI", 20F, FontStyle.Regular, GraphicsUnit.Point);
labelTitle.Location = new System.Drawing.Point(12, 9);
labelTitle.Name = "labelTitle";
labelTitle.Size = new System.Drawing.Size(126, 37);
labelTitle.TabIndex = 0;
labelTitle.Text = "labelTitle";
//
// groupBoxStatus
//
groupBoxStatus.Controls.Add(labelStatusTimeToNext);
groupBoxStatus.Controls.Add(labelStatusNextState);
groupBoxStatus.Controls.Add(labelStatusTransferring);
groupBoxStatus.Controls.Add(labelStatus5);
groupBoxStatus.Controls.Add(labelStatusPaid);
groupBoxStatus.Controls.Add(labelStatus4);
groupBoxStatus.Controls.Add(labelStatusHighest);
groupBoxStatus.Controls.Add(labelStatus3);
groupBoxStatus.Controls.Add(labelStatusReserved);
groupBoxStatus.Controls.Add(labelStatus2);
groupBoxStatus.Controls.Add(labelStatusMain);
groupBoxStatus.Controls.Add(labelStatus1);
groupBoxStatus.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
groupBoxStatus.Location = new System.Drawing.Point(12, 68);
groupBoxStatus.Name = "groupBoxStatus";
groupBoxStatus.Size = new System.Drawing.Size(378, 173);
groupBoxStatus.TabIndex = 1;
groupBoxStatus.TabStop = false;
groupBoxStatus.Text = "Info";
//
// labelStatusTimeToNext
//
labelStatusTimeToNext.AutoSize = true;
labelStatusTimeToNext.Location = new System.Drawing.Point(112, 130);
labelStatusTimeToNext.Name = "labelStatusTimeToNext";
labelStatusTimeToNext.Size = new System.Drawing.Size(67, 21);
labelStatusTimeToNext.TabIndex = 11;
labelStatusTimeToNext.Text = "0 Blocks";
//
// labelStatusNextState
//
labelStatusNextState.AutoSize = true;
labelStatusNextState.Location = new System.Drawing.Point(27, 130);
labelStatusNextState.Name = "labelStatusNextState";
labelStatusNextState.Size = new System.Drawing.Size(79, 21);
labelStatusNextState.TabIndex = 10;
labelStatusNextState.Text = "Expires in:";
//
// labelStatusTransferring
//
labelStatusTransferring.AutoSize = true;
labelStatusTransferring.Location = new System.Drawing.Point(112, 109);
labelStatusTransferring.Name = "labelStatusTransferring";
labelStatusTransferring.Size = new System.Drawing.Size(31, 21);
labelStatusTransferring.TabIndex = 9;
labelStatusTransferring.Text = "No";
//
// labelStatus5
//
labelStatus5.AutoSize = true;
labelStatus5.Location = new System.Drawing.Point(9, 109);
labelStatus5.Name = "labelStatus5";
labelStatus5.Size = new System.Drawing.Size(97, 21);
labelStatus5.TabIndex = 8;
labelStatus5.Text = "Transferring:";
//
// labelStatusPaid
//
labelStatusPaid.AutoSize = true;
labelStatusPaid.Location = new System.Drawing.Point(112, 88);
labelStatusPaid.Name = "labelStatusPaid";
labelStatusPaid.Size = new System.Drawing.Size(95, 21);
labelStatusPaid.TabIndex = 7;
labelStatusPaid.Text = "Not Opened";
//
// labelStatus4
//
labelStatus4.AutoSize = true;
labelStatus4.Location = new System.Drawing.Point(26, 88);
labelStatus4.Name = "labelStatus4";
labelStatus4.Size = new System.Drawing.Size(80, 21);
labelStatus4.TabIndex = 6;
labelStatus4.Text = "Price Paid:";
//
// labelStatusHighest
//
labelStatusHighest.AutoSize = true;
labelStatusHighest.Location = new System.Drawing.Point(112, 67);
labelStatusHighest.Name = "labelStatusHighest";
labelStatusHighest.Size = new System.Drawing.Size(95, 21);
labelStatusHighest.TabIndex = 5;
labelStatusHighest.Text = "Not Opened";
//
// labelStatus3
//
labelStatus3.AutoSize = true;
labelStatus3.Location = new System.Drawing.Point(14, 67);
labelStatus3.Name = "labelStatus3";
labelStatus3.Size = new System.Drawing.Size(92, 21);
labelStatus3.TabIndex = 4;
labelStatus3.Text = "Highest Bid:";
//
// labelStatusReserved
//
labelStatusReserved.AutoSize = true;
labelStatusReserved.Location = new System.Drawing.Point(112, 25);
labelStatusReserved.Name = "labelStatusReserved";
labelStatusReserved.Size = new System.Drawing.Size(40, 21);
labelStatusReserved.TabIndex = 3;
labelStatusReserved.Text = "True";
//
// labelStatus2
//
labelStatus2.AutoSize = true;
labelStatus2.Location = new System.Drawing.Point(29, 25);
labelStatus2.Name = "labelStatus2";
labelStatus2.Size = new System.Drawing.Size(77, 21);
labelStatus2.TabIndex = 2;
labelStatus2.Text = "Reserved:";
//
// labelStatusMain
//
labelStatusMain.AutoSize = true;
labelStatusMain.Location = new System.Drawing.Point(112, 46);
labelStatusMain.Name = "labelStatusMain";
labelStatusMain.Size = new System.Drawing.Size(57, 21);
labelStatusMain.TabIndex = 1;
labelStatusMain.Text = "Closed";
//
// labelStatus1
//
labelStatus1.AutoSize = true;
labelStatus1.Location = new System.Drawing.Point(51, 46);
labelStatus1.Name = "labelStatus1";
labelStatus1.Size = new System.Drawing.Size(55, 21);
labelStatus1.TabIndex = 0;
labelStatus1.Text = "Status:";
//
// groupBoxDNS
//
groupBoxDNS.Controls.Add(panelDNS);
groupBoxDNS.Location = new System.Drawing.Point(12, 247);
groupBoxDNS.Name = "groupBoxDNS";
groupBoxDNS.Size = new System.Drawing.Size(962, 313);
groupBoxDNS.TabIndex = 12;
groupBoxDNS.TabStop = false;
groupBoxDNS.Text = "DNS";
//
// panelDNS
//
panelDNS.Dock = DockStyle.Fill;
panelDNS.Location = new System.Drawing.Point(3, 19);
panelDNS.Name = "panelDNS";
panelDNS.Size = new System.Drawing.Size(956, 291);
panelDNS.TabIndex = 0;
//
// groupBoxBids
//
groupBoxBids.Controls.Add(panelBids);
groupBoxBids.Font = new Font("Segoe UI", 9F, FontStyle.Regular, GraphicsUnit.Point);
groupBoxBids.Location = new System.Drawing.Point(12, 247);
groupBoxBids.Name = "groupBoxBids";
groupBoxBids.Size = new System.Drawing.Size(962, 313);
groupBoxBids.TabIndex = 13;
groupBoxBids.TabStop = false;
groupBoxBids.Text = "Bids";
groupBoxBids.Visible = false;
//
// panelBids
//
panelBids.Dock = DockStyle.Fill;
panelBids.Location = new System.Drawing.Point(3, 19);
panelBids.Name = "panelBids";
panelBids.Size = new System.Drawing.Size(956, 291);
panelBids.TabIndex = 0;
//
// DomainForm
//
AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new System.Drawing.Size(986, 572);
Controls.Add(groupBoxBids);
Controls.Add(groupBoxDNS);
Controls.Add(groupBoxStatus);
Controls.Add(labelTitle);
FormBorderStyle = FormBorderStyle.Fixed3D;
MaximizeBox = false;
Name = "DomainForm";
Text = "DomainForm";
Load += DomainForm_Load;
groupBoxStatus.ResumeLayout(false);
groupBoxStatus.PerformLayout();
groupBoxDNS.ResumeLayout(false);
groupBoxBids.ResumeLayout(false);
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label labelTitle;
private GroupBox groupBoxStatus;
private Label labelStatusMain;
private Label labelStatus1;
private Label labelStatusReserved;
private Label labelStatus2;
private Label labelStatusHighest;
private Label labelStatus3;
private Label labelStatusPaid;
private Label labelStatus4;
private Label labelStatus5;
private Label labelStatusTransferring;
private Label labelStatusTimeToNext;
private Label labelStatusNextState;
private GroupBox groupBoxDNS;
private Panel panelDNS;
private GroupBox groupBoxBids;
private Panel panelBids;
}
}

605
FireWallet/DomainForm.cs Normal file
View File

@ -0,0 +1,605 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net.Http;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using BitMiracle.LibTiff.Classic;
using Microsoft.VisualBasic.Devices;
using Newtonsoft.Json.Linq;
namespace FireWallet
{
public partial class DomainForm : Form
{
string dir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\FireWallet\\";
Dictionary<string, string> theme;
Dictionary<string, string> nodeSettings;
string domain;
int network;
int height;
public DomainForm(string domain)
{
InitializeComponent();
this.Text = domain + "/ | FireWallet";
labelTitle.Text = domain + "/";
this.domain = domain;
}
#region Theming
private void UpdateTheme()
{
// Check if file exists
if (!Directory.Exists(dir))
{
CreateConfig(dir);
}
if (!File.Exists(dir + "theme.txt"))
{
CreateConfig(dir);
}
// Read file
StreamReader sr = new StreamReader(dir + "theme.txt");
theme = new Dictionary<string, string>();
while (!sr.EndOfStream)
{
string line = sr.ReadLine();
string[] split = line.Split(':');
theme.Add(split[0].Trim(), split[1].Trim());
}
sr.Dispose();
if (!theme.ContainsKey("background") || !theme.ContainsKey("background-alt") || !theme.ContainsKey("foreground") || !theme.ContainsKey("foreground-alt"))
{
return;
}
// Apply theme
this.BackColor = ColorTranslator.FromHtml(theme["background"]);
// Foreground
this.ForeColor = ColorTranslator.FromHtml(theme["foreground"]);
// Need to specify this for each groupbox to override the black text
foreach (Control c in Controls)
{
ThemeControl(c);
}
// Transparancy
applyTransparency(theme);
}
private void ThemeControl(Control c)
{
if (c.GetType() == typeof(GroupBox) || c.GetType() == typeof(Panel))
{
c.ForeColor = ColorTranslator.FromHtml(theme["foreground"]);
foreach (Control sub in c.Controls)
{
ThemeControl(sub);
}
}
if (c.GetType() == typeof(TextBox) || c.GetType() == typeof(Button)
|| c.GetType() == typeof(ComboBox) || c.GetType() == typeof(StatusStrip))
{
c.ForeColor = ColorTranslator.FromHtml(theme["foreground-alt"]);
c.BackColor = ColorTranslator.FromHtml(theme["background-alt"]);
}
}
private void applyTransparency(Dictionary<string, string> theme)
{
if (theme.ContainsKey("transparent-mode"))
{
switch (theme["transparent-mode"])
{
case "mica":
var accent = new AccentPolicy { AccentState = AccentState.ACCENT_ENABLE_BLURBEHIND };
var accentStructSize = Marshal.SizeOf(accent);
var accentPtr = Marshal.AllocHGlobal(accentStructSize);
Marshal.StructureToPtr(accent, accentPtr, false);
var data = new WindowCompositionAttributeData
{
Attribute = WindowCompositionAttribute.WCA_ACCENT_POLICY,
SizeOfData = accentStructSize,
Data = accentPtr
};
User32.SetWindowCompositionAttribute(Handle, ref data);
Marshal.FreeHGlobal(accentPtr);
break;
case "key":
if (theme.ContainsKey("transparency-key"))
{
switch (theme["transparency-key"])
{
case "alt":
this.TransparencyKey = ColorTranslator.FromHtml(theme["background-alt"]);
break;
case "main":
this.TransparencyKey = ColorTranslator.FromHtml(theme["background"]);
break;
default:
this.TransparencyKey = ColorTranslator.FromHtml(theme["transparency-key"]);
break;
}
}
break;
case "percent":
if (theme.ContainsKey("transparency-percent"))
{
Opacity = Convert.ToDouble(theme["transparency-percent"]) / 100;
}
break;
}
}
}
private void CreateConfig(string dir)
{
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
StreamWriter sw = new StreamWriter(dir + "theme.txt");
sw.WriteLine("background: #000000");
sw.WriteLine("foreground: #8e05c2");
sw.WriteLine("background-alt: #3e065f");
sw.WriteLine("foreground-alt: #ffffff");
sw.WriteLine("transparent-mode: off");
sw.WriteLine("transparency-key: main");
sw.WriteLine("transparency-percent: 90");
sw.Dispose();
}
// Required for mica effect
internal enum AccentState
{
ACCENT_DISABLED = 0,
ACCENT_ENABLE_GRADIENT = 1,
ACCENT_ENABLE_TRANSPARENTGRADIENT = 2,
ACCENT_ENABLE_BLURBEHIND = 3,
ACCENT_INVALID_STATE = 4
}
internal enum WindowCompositionAttribute
{
WCA_ACCENT_POLICY = 19
}
[StructLayout(LayoutKind.Sequential)]
internal struct AccentPolicy
{
public AccentState AccentState;
public int AccentFlags;
public int GradientColor;
public int AnimationId;
}
[StructLayout(LayoutKind.Sequential)]
internal struct WindowCompositionAttributeData
{
public WindowCompositionAttribute Attribute;
public IntPtr Data;
public int SizeOfData;
}
internal static class User32
{
[DllImport("user32.dll")]
internal static extern int SetWindowCompositionAttribute(IntPtr hwnd, ref WindowCompositionAttributeData data);
}
#endregion
private void DomainForm_Load(object sender, EventArgs e)
{
UpdateTheme();
StreamReader sr = new StreamReader(dir + "node.txt");
nodeSettings = new Dictionary<string, string>();
while (!sr.EndOfStream)
{
string line = sr.ReadLine();
string[] split = line.Split(':');
nodeSettings.Add(split[0].Trim(), split[1].Trim());
}
sr.Dispose();
if (!nodeSettings.ContainsKey("Network") || !nodeSettings.ContainsKey("Key") || !nodeSettings.ContainsKey("IP"))
{
this.Close();
return;
}
network = Convert.ToInt32(nodeSettings["Network"]);
GetName();
}
private async void GetName()
{
try
{
string content = "{\"method\": \"getnameinfo\", \"params\": [\"" + domain + "\"]}";
string response = await APIPost("", false, content);
JObject jObject = JObject.Parse(response);
// Get block height
string Nodeinfo = await APIGet("", false);
JObject jObjectInfo = JObject.Parse(Nodeinfo);
JObject chain = (JObject)jObjectInfo["chain"];
height = Convert.ToInt32(chain["height"]);
if (jObject.ContainsKey("result"))
{
JObject result = (JObject)jObject["result"];
JObject start = (JObject)result["start"];
labelStatusReserved.Text = start["reserved"].ToString();
if (result.ContainsKey("info"))
{
try
{
JObject info = (JObject)result["info"];
string state = info["state"].ToString();
labelStatusMain.Text = state;
labelStatusHighest.Text = convertHNS(info["highest"].ToString()) + " HNS";
labelStatusPaid.Text = convertHNS(info["value"].ToString()) + " HNS";
if (info["transfer"].ToString() == "0") labelStatusTransferring.Text = "No";
else labelStatusTransferring.Text = "Yes";
JObject stats = (JObject)info["stats"];
if (state == "CLOSED")
{
string expires = stats["blocksUntilExpire"].ToString() + " Blocks (~" + stats["daysUntilExpire"].ToString() + " days)";
labelStatusTimeToNext.Text = expires;
}
else if (state == "BIDDING")
{
string bidding = stats["blocksUntilReveal"].ToString() + " Blocks (~" + stats["hoursUntilReveal"].ToString() + " hrs)";
labelStatusTimeToNext.Text = bidding;
labelStatusNextState.Text = "Reveal in:";
}
else if (state == "REVEAL")
{
string reveal = stats["blocksUntilClose"].ToString() + " Blocks (~" + stats["hoursUntilClose"].ToString() + " hrs)";
labelStatusTimeToNext.Text = reveal;
labelStatusNextState.Text = "Closing in:";
}
else
{
AddLog("State not added yet: " + state);
AddLog(stats.ToString());
}
// Get DNS if the domain isn't in auction
if (state == "CLOSED") GetDNS();
else if (state == "BIDDING" || state == "REVEAL") GetBids(state);
else groupBoxDNS.Visible = false;
}
catch (Exception ex)
{
// No info -> Domain not yet auctioned
labelStatusMain.Text = "Available";
AddLog(ex.Message);
AddLog(result.ToString());
}
}
}
else
{
labelStatusMain.Text = "Error";
}
}
catch (Exception ex)
{
AddLog(ex.Message);
}
}
private async void GetDNS()
{
// Get DNS records
string contentDNS = "{\"method\": \"getnameresource\", \"params\": [\"" + domain + "\"]}";
string responseDNS = await APIPost("", false, contentDNS);
JObject jObjectDNS = JObject.Parse(responseDNS);
JObject result = (JObject)jObjectDNS["result"];
JArray records = (JArray)result["records"];
// For each record
int i = 0;
foreach (JObject record in records)
{
Panel DNSPanel = new Panel();
// Count for scroll width
DNSPanel.Width = panelDNS.Width - SystemInformation.VerticalScrollBarWidth - 2;
DNSPanel.Height = 60;
DNSPanel.BorderStyle = BorderStyle.FixedSingle;
DNSPanel.Top = 62 * i;
Label DNSType = new Label();
DNSType.Text = record["type"].ToString();
DNSType.Location = new System.Drawing.Point(10, 10);
DNSType.AutoSize = true;
DNSType.Font = new Font(DNSType.Font.FontFamily, 11.0f, FontStyle.Bold);
DNSPanel.Controls.Add(DNSType);
switch (DNSType.Text)
{
case "NS":
Label DNSNS = new Label();
DNSNS.Text = record["ns"].ToString();
DNSNS.Location = new System.Drawing.Point(10, 30);
DNSNS.AutoSize = true;
DNSPanel.Controls.Add(DNSNS);
break;
case "GLUE4":
case "GLUE6":
Label DNSNS1 = new Label();
DNSNS1.Text = record["ns"].ToString();
DNSNS1.Location = new System.Drawing.Point(10, 30);
DNSNS1.AutoSize = true;
DNSPanel.Controls.Add(DNSNS1);
Label address = new Label();
address.Text = record["address"].ToString();
address.Location = new System.Drawing.Point(DNSNS1.Left + DNSNS1.Width + 20, 30);
address.AutoSize = true;
DNSPanel.Controls.Add(address);
break;
case "DS":
Label keyTag = new Label();
keyTag.Text = record["keyTag"].ToString();
keyTag.Location = new System.Drawing.Point(10, 30);
keyTag.AutoSize = true;
DNSPanel.Controls.Add(keyTag);
Label algorithm = new Label();
algorithm.Text = record["algorithm"].ToString();
algorithm.Location = new System.Drawing.Point(keyTag.Left + keyTag.Width + 10, 30);
algorithm.AutoSize = true;
DNSPanel.Controls.Add(algorithm);
Label digestType = new Label();
digestType.Text = record["digestType"].ToString();
digestType.Location = new System.Drawing.Point(algorithm.Left + algorithm.Width + 10, 30);
digestType.AutoSize = true;
DNSPanel.Controls.Add(digestType);
Label digest = new Label();
digest.Text = record["digest"].ToString();
digest.Location = new System.Drawing.Point(digestType.Left + digestType.Width + 10, 30);
digest.AutoSize = true;
DNSPanel.Controls.Add(digest);
break;
case "TXT":
JArray txts = (JArray)record["txt"];
int j = 0;
foreach (string txt in txts)
{
Label DNSTXT = new Label();
DNSTXT.Text = txt;
DNSTXT.Location = new System.Drawing.Point(10, 30 + (j * 20));
DNSTXT.AutoSize = true;
DNSPanel.Controls.Add(DNSTXT);
DNSPanel.Height = 60 + (j * 20);
j++;
}
break;
}
panelDNS.Controls.Add(DNSPanel);
i++;
}
panelDNS.AutoScroll = true;
}
private async void GetBids(string state)
{
groupBoxBids.Visible = true;
panelBids.AutoScroll = true;
// Get Bids
string contentBids = "{\"method\": \"getauctioninfo\", \"params\": [\"" + domain + "\"]}";
string response = await APIPost("", true, contentBids);
if (!response.Contains("\"error\":null"))
{
AddLog("Syncing Domain");
// Error
// Try scanning for auction
contentBids = "{\"method\": \"importname\", \"params\": [\"" + domain + "\", " + (height - 2000) + "]}";
response = await APIPost("", true, contentBids);
}
if (state == "BIDDING")
{
JObject resp = JObject.Parse(response);
JObject result = (JObject)resp["result"];
JArray bids = (JArray)result["bids"];
int i = 1;
foreach (JObject bid in bids)
{
Panel bidPanel = new Panel();
// Count for scroll width
bidPanel.Width = panelBids.Width - SystemInformation.VerticalScrollBarWidth - 2;
bidPanel.Height = 60;
bidPanel.BorderStyle = BorderStyle.FixedSingle;
bidPanel.Top = (62 * i) - 60;
Label bidNumber = new Label();
bidNumber.Text = i.ToString();
bidNumber.Location = new System.Drawing.Point(10, 10);
bidNumber.AutoSize = true;
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;
bidPanel.Controls.Add(bidAmount);
if (bid["own"].ToString() == "True")
{
Label ownBid = new Label();
ownBid.Text = "Own Bid";
ownBid.Location = new System.Drawing.Point(bidAmount.Left + bidAmount.Width + 10, 30);
ownBid.AutoSize = true;
bidPanel.Controls.Add(ownBid);
}
panelBids.Controls.Add(bidPanel);
i++;
}
}
else if (state == "REVEAL")
{
JObject resp = JObject.Parse(response);
JObject result = (JObject)resp["result"];
JArray bids = (JArray)result["bids"];
JArray reveals = (JArray)result["reveals"];
int i = 1;
foreach (JObject bid in bids)
{
Panel bidPanel = new Panel();
// Count for scroll width
bidPanel.Width = panelBids.Width - SystemInformation.VerticalScrollBarWidth - 2;
bidPanel.Height = 60;
bidPanel.BorderStyle = BorderStyle.FixedSingle;
bidPanel.Top = (62 * i) - 60;
Label bidNumber = new Label();
bidNumber.Text = i.ToString();
bidNumber.Location = new System.Drawing.Point(10, 10);
bidNumber.AutoSize = true;
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;
bidPanel.Controls.Add(bidAmount);
if (bid["own"].ToString() == "true")
{
Label ownBid = new Label();
ownBid.Text = "Own Bid";
ownBid.Location = new System.Drawing.Point(bidAmount.Left + bidAmount.Width + 10, 30);
ownBid.AutoSize = true;
bidPanel.Controls.Add(ownBid);
}
panelBids.Controls.Add(bidPanel);
i++;
}
}
}
private string convertHNS(string dollarydoos)
{
decimal hns = Convert.ToDecimal(dollarydoos);
hns = hns / 1000000;
return decimal.Round(hns, 2).ToString();
}
#region API
HttpClient httpClient = new HttpClient();
/// <summary>
/// Post to HSD API
/// </summary>
/// <param name="path">Path to post to</param>
/// <param name="wallet">Whether to use port 12039</param>
/// <param name="content">Content to post</param>
/// <returns></returns>
private async Task<string> APIPost(string path, bool wallet, string content)
{
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";
HttpRequestMessage req = new HttpRequestMessage(HttpMethod.Post, "http://" + ip + ":" + port + "/" + path);
req.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes("x:" + key)));
req.Content = new StringContent(content);
// Send request
HttpResponseMessage resp = await httpClient.SendAsync(req);
try
{
resp.EnsureSuccessStatusCode();
}
catch (Exception ex)
{
AddLog("Post Error: " + ex.Message);
return "Error";
}
return await resp.Content.ReadAsStringAsync();
}
/// <summary>
/// Get from HSD API
/// </summary>
/// <param name="path">Path to get</param>
/// <param name="wallet">Whether to use port 12039</param>
/// <returns></returns>
private async Task<string> APIGet(string path, bool wallet)
{
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";
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();
return await response.Content.ReadAsStringAsync();
}
// Log errors to log textbox
catch (Exception ex)
{
AddLog("Get Error: " + ex.Message);
return "Error";
}
}
private void AddLog(string message)
{
StreamWriter sw = new StreamWriter(dir + "log.txt", true);
sw.WriteLine(DateTime.Now.ToString() + ": " + message);
sw.Dispose();
}
#endregion
}
}

120
FireWallet/DomainForm.resx Normal file
View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing"">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -50,6 +50,7 @@ namespace FireWallet
labelaccountusername = new Label();
buttonaccountnew = new Button();
panelNav = new Panel();
buttonNavDomains = new Button();
buttonNavReceive = new Button();
buttonNavSend = new Button();
buttonNavPortfolio = new Button();
@ -80,6 +81,9 @@ namespace FireWallet
labelReceive2 = new Label();
textBoxReceiveAddress = new TextBox();
labelReceive1 = new Label();
panelDomains = new Panel();
labelDomainSearch = new Label();
textBoxDomainSearch = new TextBox();
statusStripmain.SuspendLayout();
panelaccount.SuspendLayout();
groupBoxaccount.SuspendLayout();
@ -90,6 +94,7 @@ namespace FireWallet
panelSend.SuspendLayout();
panelRecieve.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxReceiveQR).BeginInit();
panelDomains.SuspendLayout();
SuspendLayout();
//
// statusStripmain
@ -204,6 +209,7 @@ namespace FireWallet
buttonaccountlogin.Name = "buttonaccountlogin";
buttonaccountlogin.Size = new Size(99, 41);
buttonaccountlogin.TabIndex = 3;
buttonaccountlogin.TabStop = false;
buttonaccountlogin.Text = "Login";
buttonaccountlogin.UseVisualStyleBackColor = true;
buttonaccountlogin.Click += LoginClick;
@ -235,11 +241,13 @@ namespace FireWallet
buttonaccountnew.Name = "buttonaccountnew";
buttonaccountnew.Size = new Size(99, 41);
buttonaccountnew.TabIndex = 2;
buttonaccountnew.TabStop = false;
buttonaccountnew.Text = "New";
buttonaccountnew.UseVisualStyleBackColor = true;
//
// panelNav
//
panelNav.Controls.Add(buttonNavDomains);
panelNav.Controls.Add(buttonNavReceive);
panelNav.Controls.Add(buttonNavSend);
panelNav.Controls.Add(buttonNavPortfolio);
@ -249,6 +257,19 @@ namespace FireWallet
panelNav.Size = new Size(114, 553);
panelNav.TabIndex = 6;
//
// buttonNavDomains
//
buttonNavDomains.FlatStyle = FlatStyle.Flat;
buttonNavDomains.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
buttonNavDomains.Location = new Point(12, 189);
buttonNavDomains.Name = "buttonNavDomains";
buttonNavDomains.Size = new Size(89, 30);
buttonNavDomains.TabIndex = 2;
buttonNavDomains.TabStop = false;
buttonNavDomains.Text = "Domains";
buttonNavDomains.UseVisualStyleBackColor = true;
buttonNavDomains.Click += buttonNavDomains_Click;
//
// buttonNavReceive
//
buttonNavReceive.FlatStyle = FlatStyle.Flat;
@ -293,7 +314,7 @@ namespace FireWallet
panelPortfolio.Controls.Add(groupBoxTransactions);
panelPortfolio.Controls.Add(groupBoxinfo);
panelPortfolio.Controls.Add(groupBoxbalance);
panelPortfolio.Location = new Point(448, 170);
panelPortfolio.Location = new Point(1085, 47);
panelPortfolio.Name = "panelPortfolio";
panelPortfolio.Size = new Size(956, 538);
panelPortfolio.TabIndex = 7;
@ -406,7 +427,7 @@ namespace FireWallet
panelSend.Controls.Add(labelSendingAmount);
panelSend.Controls.Add(labelSendingTo);
panelSend.Controls.Add(labelSendPrompt);
panelSend.Location = new Point(448, 170);
panelSend.Location = new Point(1113, 42);
panelSend.Name = "panelSend";
panelSend.Size = new Size(974, 521);
panelSend.TabIndex = 2;
@ -535,7 +556,7 @@ namespace FireWallet
panelRecieve.Controls.Add(labelReceive2);
panelRecieve.Controls.Add(textBoxReceiveAddress);
panelRecieve.Controls.Add(labelReceive1);
panelRecieve.Location = new Point(120, 25);
panelRecieve.Location = new Point(1057, 62);
panelRecieve.Name = "panelRecieve";
panelRecieve.Size = new Size(995, 523);
panelRecieve.TabIndex = 17;
@ -580,11 +601,41 @@ namespace FireWallet
labelReceive1.TabIndex = 0;
labelReceive1.Text = "Here is your receive address:";
//
// panelDomains
//
panelDomains.Controls.Add(labelDomainSearch);
panelDomains.Controls.Add(textBoxDomainSearch);
panelDomains.Location = new Point(120, 27);
panelDomains.Name = "panelDomains";
panelDomains.Size = new Size(920, 536);
panelDomains.TabIndex = 18;
panelDomains.Visible = false;
//
// labelDomainSearch
//
labelDomainSearch.AutoSize = true;
labelDomainSearch.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
labelDomainSearch.Location = new Point(92, 47);
labelDomainSearch.Name = "labelDomainSearch";
labelDomainSearch.Size = new Size(57, 21);
labelDomainSearch.TabIndex = 1;
labelDomainSearch.Text = "Search";
//
// textBoxDomainSearch
//
textBoxDomainSearch.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
textBoxDomainSearch.Location = new Point(155, 44);
textBoxDomainSearch.Name = "textBoxDomainSearch";
textBoxDomainSearch.Size = new Size(206, 29);
textBoxDomainSearch.TabIndex = 0;
textBoxDomainSearch.KeyDown += textBoxDomainSearch_KeyDown;
//
// MainForm
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1152, 575);
Controls.Add(panelDomains);
Controls.Add(panelRecieve);
Controls.Add(panelSend);
Controls.Add(panelPortfolio);
@ -612,6 +663,8 @@ namespace FireWallet
panelRecieve.ResumeLayout(false);
panelRecieve.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxReceiveQR).EndInit();
panelDomains.ResumeLayout(false);
panelDomains.PerformLayout();
ResumeLayout(false);
PerformLayout();
}
@ -664,5 +717,9 @@ namespace FireWallet
private TextBox textBoxReceiveAddress;
private Label labelReceive2;
private PictureBox pictureBoxReceiveQR;
private Button buttonNavDomains;
private Panel panelDomains;
private Label labelDomainSearch;
private TextBox textBoxDomainSearch;
}
}

View File

@ -75,7 +75,7 @@ namespace FireWallet
{
if (!File.Exists(dir + "node.txt"))
{
CreateForm cf = new CreateForm();
NodeForm cf = new NodeForm();
cf.ShowDialog();
// Initial run
}
@ -459,6 +459,8 @@ namespace FireWallet
panelNav.Visible = false;
panelSend.Visible = false;
panelRecieve.Visible = false;
panelDomains.Visible = false;
panelPortfolio.Visible = false;
toolStripStatusLabelaccount.Text = "Account: Not Logged In";
screen = 0;
@ -486,9 +488,8 @@ namespace FireWallet
JObject resp = JObject.Parse(response);
decimal available = Convert.ToDecimal(resp["unconfirmed"].ToString()) - Convert.ToDecimal(resp["lockedUnconfirmed"].ToString()) / 1000000;
decimal available = (Convert.ToDecimal(resp["unconfirmed"].ToString()) - Convert.ToDecimal(resp["lockedUnconfirmed"].ToString())) / 1000000;
decimal locked = Convert.ToDecimal(resp["lockedUnconfirmed"].ToString()) / 1000000;
available = available - locked;
available = decimal.Round(available, 2);
locked = decimal.Round(locked, 2);
balance = available;
@ -730,10 +731,13 @@ namespace FireWallet
panelSend.Hide();
panelPortfolio.Show();
panelRecieve.Hide();
panelDomains.Hide();
buttonNavSend.BackColor = ColorTranslator.FromHtml(theme["background"]);
buttonNavSend.ForeColor = ColorTranslator.FromHtml(theme["foreground"]);
buttonNavReceive.BackColor = ColorTranslator.FromHtml(theme["background"]);
buttonNavReceive.ForeColor = ColorTranslator.FromHtml(theme["foreground"]);
buttonNavDomains.BackColor = ColorTranslator.FromHtml(theme["background"]);
buttonNavDomains.ForeColor = ColorTranslator.FromHtml(theme["foreground"]);
await UpdateBalance();
GetTXHistory();
labelBalance.Text = "Available: " + balance.ToString() + " HNS";
@ -751,10 +755,13 @@ namespace FireWallet
panelPortfolio.Hide();
panelSend.Show();
panelRecieve.Hide();
panelDomains.Hide();
buttonNavPortfolio.BackColor = ColorTranslator.FromHtml(theme["background"]);
buttonNavPortfolio.ForeColor = ColorTranslator.FromHtml(theme["foreground"]);
buttonNavReceive.BackColor = ColorTranslator.FromHtml(theme["background"]);
buttonNavReceive.ForeColor = ColorTranslator.FromHtml(theme["foreground"]);
buttonNavDomains.BackColor = ColorTranslator.FromHtml(theme["background"]);
buttonNavDomains.ForeColor = ColorTranslator.FromHtml(theme["foreground"]);
if (theme.ContainsKey("selected-bg") && theme.ContainsKey("selected-fg"))
{
buttonNavSend.BackColor = ColorTranslator.FromHtml(theme["selected-bg"]);
@ -789,11 +796,13 @@ namespace FireWallet
panelSend.Hide();
panelPortfolio.Hide();
panelRecieve.Show();
panelDomains.Hide();
buttonNavSend.BackColor = ColorTranslator.FromHtml(theme["background"]);
buttonNavSend.ForeColor = ColorTranslator.FromHtml(theme["foreground"]);
buttonNavPortfolio.BackColor = ColorTranslator.FromHtml(theme["background"]);
buttonNavPortfolio.ForeColor = ColorTranslator.FromHtml(theme["foreground"]);
buttonNavDomains.BackColor = ColorTranslator.FromHtml(theme["background"]);
buttonNavDomains.ForeColor = ColorTranslator.FromHtml(theme["foreground"]);
if (theme.ContainsKey("selected-bg") && theme.ContainsKey("selected-fg"))
{
@ -820,6 +829,27 @@ namespace FireWallet
}
private void buttonNavDomains_Click(object sender, EventArgs e)
{
panelSend.Hide();
panelPortfolio.Hide();
panelRecieve.Hide();
panelDomains.Show();
buttonNavSend.BackColor = ColorTranslator.FromHtml(theme["background"]);
buttonNavSend.ForeColor = ColorTranslator.FromHtml(theme["foreground"]);
buttonNavPortfolio.BackColor = ColorTranslator.FromHtml(theme["background"]);
buttonNavPortfolio.ForeColor = ColorTranslator.FromHtml(theme["foreground"]);
buttonNavReceive.BackColor = ColorTranslator.FromHtml(theme["background"]);
buttonNavReceive.ForeColor = ColorTranslator.FromHtml(theme["foreground"]);
if (theme.ContainsKey("selected-bg") && theme.ContainsKey("selected-fg"))
{
buttonNavDomains.BackColor = ColorTranslator.FromHtml(theme["selected-bg"]);
buttonNavDomains.ForeColor = ColorTranslator.FromHtml(theme["selected-fg"]);
}
textBoxDomainSearch.Focus();
}
#endregion
#region Send
@ -962,12 +992,25 @@ namespace FireWallet
}
}
#endregion
#region Receive
private void textBoxRecieveAddress_Click(object sender, EventArgs e)
{
Clipboard.SetText(textBoxReceiveAddress.Text);
labelReceive2.Text = "Copied to clipboard";
labelReceive2.Left = (panelRecieve.Width - labelReceive2.Width) / 2;
}
#endregion
private void textBoxDomainSearch_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyValue == 13)
{
e.SuppressKeyPress = true;
DomainForm domainForm = new DomainForm(textBoxDomainSearch.Text);
domainForm.Show();
}
}
}
}