main: Added sending to address

This commit is contained in:
Nathan Woodburn 2023-06-07 13:00:22 +10:00
parent 8d75f308fc
commit e74a6bdbb1
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
2 changed files with 403 additions and 78 deletions

View File

@ -37,7 +37,7 @@
timerNodeStatus = new System.Windows.Forms.Timer(components); timerNodeStatus = new System.Windows.Forms.Timer(components);
panelaccount = new Panel(); panelaccount = new Panel();
groupBoxaccount = new GroupBox(); groupBoxaccount = new GroupBox();
label1 = new Label(); labelloginprompt = new Label();
comboBoxaccount = new ComboBox(); comboBoxaccount = new ComboBox();
textBoxaccountpassword = new TextBox(); textBoxaccountpassword = new TextBox();
buttonaccountlogin = new Button(); buttonaccountlogin = new Button();
@ -45,9 +45,9 @@
labelaccountusername = new Label(); labelaccountusername = new Label();
buttonaccountnew = new Button(); buttonaccountnew = new Button();
panelNav = new Panel(); panelNav = new Panel();
buttonReceive = new Button(); buttonNavReceive = new Button();
buttonSend = new Button(); buttonNavSend = new Button();
buttonPortfolio = new Button(); buttonNavPortfolio = new Button();
panelPortfolio = new Panel(); panelPortfolio = new Panel();
groupBoxTransactions = new GroupBox(); groupBoxTransactions = new GroupBox();
groupBoxinfo = new GroupBox(); groupBoxinfo = new GroupBox();
@ -59,6 +59,17 @@
labelLocked = new Label(); labelLocked = new Label();
labelBalance = new Label(); labelBalance = new Label();
panelSend = new Panel(); panelSend = new Panel();
checkBoxSendSubFee = new CheckBox();
buttonSendMax = new Button();
buttonSendHNS = new Button();
labelSendingError = new Label();
labelSendingFee = new Label();
textBoxSendingAmount = new TextBox();
textBoxSendingTo = new TextBox();
labelSendingMax = new Label();
labelSendingAmount = new Label();
labelSendingTo = new Label();
labelSendPrompt = new Label();
statusStripmain.SuspendLayout(); statusStripmain.SuspendLayout();
panelaccount.SuspendLayout(); panelaccount.SuspendLayout();
groupBoxaccount.SuspendLayout(); groupBoxaccount.SuspendLayout();
@ -66,6 +77,7 @@
panelPortfolio.SuspendLayout(); panelPortfolio.SuspendLayout();
groupBoxinfo.SuspendLayout(); groupBoxinfo.SuspendLayout();
groupBoxbalance.SuspendLayout(); groupBoxbalance.SuspendLayout();
panelSend.SuspendLayout();
SuspendLayout(); SuspendLayout();
// //
// statusStripmain // statusStripmain
@ -128,7 +140,7 @@
// //
// groupBoxaccount // groupBoxaccount
// //
groupBoxaccount.Controls.Add(label1); groupBoxaccount.Controls.Add(labelloginprompt);
groupBoxaccount.Controls.Add(comboBoxaccount); groupBoxaccount.Controls.Add(comboBoxaccount);
groupBoxaccount.Controls.Add(textBoxaccountpassword); groupBoxaccount.Controls.Add(textBoxaccountpassword);
groupBoxaccount.Controls.Add(buttonaccountlogin); groupBoxaccount.Controls.Add(buttonaccountlogin);
@ -143,15 +155,15 @@
groupBoxaccount.TabStop = false; groupBoxaccount.TabStop = false;
groupBoxaccount.Text = "Login"; groupBoxaccount.Text = "Login";
// //
// label1 // labelloginprompt
// //
label1.AutoSize = true; labelloginprompt.AutoSize = true;
label1.Font = new Font("Segoe UI", 15.75F, FontStyle.Regular, GraphicsUnit.Point); labelloginprompt.Font = new Font("Segoe UI", 15.75F, FontStyle.Regular, GraphicsUnit.Point);
label1.Location = new Point(6, 19); labelloginprompt.Location = new Point(6, 19);
label1.Name = "label1"; labelloginprompt.Name = "labelloginprompt";
label1.Size = new Size(281, 30); labelloginprompt.Size = new Size(281, 30);
label1.TabIndex = 7; labelloginprompt.TabIndex = 7;
label1.Text = "Please Login to your account"; labelloginprompt.Text = "Please Login to your account";
// //
// comboBoxaccount // comboBoxaccount
// //
@ -216,49 +228,52 @@
// //
// panelNav // panelNav
// //
panelNav.Controls.Add(buttonReceive); panelNav.Controls.Add(buttonNavReceive);
panelNav.Controls.Add(buttonSend); panelNav.Controls.Add(buttonNavSend);
panelNav.Controls.Add(buttonPortfolio); panelNav.Controls.Add(buttonNavPortfolio);
panelNav.Dock = DockStyle.Left; panelNav.Dock = DockStyle.Left;
panelNav.Location = new Point(0, 22); panelNav.Location = new Point(0, 22);
panelNav.Name = "panelNav"; panelNav.Name = "panelNav";
panelNav.Size = new Size(114, 553); panelNav.Size = new Size(114, 553);
panelNav.TabIndex = 6; panelNav.TabIndex = 6;
// //
// buttonReceive // buttonNavReceive
// //
buttonReceive.FlatStyle = FlatStyle.Flat; buttonNavReceive.FlatStyle = FlatStyle.Flat;
buttonReceive.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point); buttonNavReceive.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
buttonReceive.Location = new Point(12, 134); buttonNavReceive.Location = new Point(12, 134);
buttonReceive.Name = "buttonReceive"; buttonNavReceive.Name = "buttonNavReceive";
buttonReceive.Size = new Size(89, 30); buttonNavReceive.Size = new Size(89, 30);
buttonReceive.TabIndex = 1; buttonNavReceive.TabIndex = 1;
buttonReceive.Text = "Receive"; buttonNavReceive.TabStop = false;
buttonReceive.UseVisualStyleBackColor = true; buttonNavReceive.Text = "Receive";
buttonNavReceive.UseVisualStyleBackColor = true;
// //
// buttonSend // buttonNavSend
// //
buttonSend.FlatStyle = FlatStyle.Flat; buttonNavSend.FlatStyle = FlatStyle.Flat;
buttonSend.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point); buttonNavSend.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
buttonSend.Location = new Point(12, 80); buttonNavSend.Location = new Point(12, 80);
buttonSend.Name = "buttonSend"; buttonNavSend.Name = "buttonNavSend";
buttonSend.Size = new Size(89, 30); buttonNavSend.Size = new Size(89, 30);
buttonSend.TabIndex = 1; buttonNavSend.TabIndex = 1;
buttonSend.Text = "Send"; buttonNavSend.TabStop = false;
buttonSend.UseVisualStyleBackColor = true; buttonNavSend.Text = "Send";
buttonSend.Click += buttonSend_Click; buttonNavSend.UseVisualStyleBackColor = true;
buttonNavSend.Click += SendPanel_Click;
// //
// buttonPortfolio // buttonNavPortfolio
// //
buttonPortfolio.FlatStyle = FlatStyle.Flat; buttonNavPortfolio.FlatStyle = FlatStyle.Flat;
buttonPortfolio.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point); buttonNavPortfolio.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
buttonPortfolio.Location = new Point(12, 25); buttonNavPortfolio.Location = new Point(12, 25);
buttonPortfolio.Name = "buttonPortfolio"; buttonNavPortfolio.Name = "buttonNavPortfolio";
buttonPortfolio.Size = new Size(89, 30); buttonNavPortfolio.Size = new Size(89, 30);
buttonPortfolio.TabIndex = 0; buttonNavPortfolio.TabIndex = 0;
buttonPortfolio.Text = "Portfolio"; buttonNavPortfolio.TabStop = false;
buttonPortfolio.UseVisualStyleBackColor = true; buttonNavPortfolio.Text = "Portfolio";
buttonPortfolio.Click += buttonPortfolio_Click; buttonNavPortfolio.UseVisualStyleBackColor = true;
buttonNavPortfolio.Click += PortfolioPanel_Click;
// //
// panelPortfolio // panelPortfolio
// //
@ -367,12 +382,138 @@
// //
// panelSend // panelSend
// //
panelSend.Controls.Add(checkBoxSendSubFee);
panelSend.Controls.Add(buttonSendMax);
panelSend.Controls.Add(buttonSendHNS);
panelSend.Controls.Add(labelSendingError);
panelSend.Controls.Add(labelSendingFee);
panelSend.Controls.Add(textBoxSendingAmount);
panelSend.Controls.Add(textBoxSendingTo);
panelSend.Controls.Add(labelSendingMax);
panelSend.Controls.Add(labelSendingAmount);
panelSend.Controls.Add(labelSendingTo);
panelSend.Controls.Add(labelSendPrompt);
panelSend.Location = new Point(120, 25); panelSend.Location = new Point(120, 25);
panelSend.Name = "panelSend"; panelSend.Name = "panelSend";
panelSend.Size = new Size(200, 100); panelSend.Size = new Size(974, 521);
panelSend.TabIndex = 2; panelSend.TabIndex = 2;
panelSend.Visible = false; panelSend.Visible = false;
// //
// checkBoxSendSubFee
//
checkBoxSendSubFee.AutoSize = true;
checkBoxSendSubFee.CheckAlign = ContentAlignment.MiddleRight;
checkBoxSendSubFee.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
checkBoxSendSubFee.Location = new Point(254, 258);
checkBoxSendSubFee.Name = "checkBoxSendSubFee";
checkBoxSendSubFee.Size = new Size(206, 25);
checkBoxSendSubFee.TabIndex = 16;
checkBoxSendSubFee.Text = "Subtract Fee from Output";
checkBoxSendSubFee.UseVisualStyleBackColor = true;
//
// buttonSendMax
//
buttonSendMax.FlatStyle = FlatStyle.Flat;
buttonSendMax.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
buttonSendMax.Location = new Point(609, 159);
buttonSendMax.Name = "buttonSendMax";
buttonSendMax.Size = new Size(81, 29);
buttonSendMax.TabIndex = 15;
buttonSendMax.Text = "Max";
buttonSendMax.UseVisualStyleBackColor = true;
buttonSendMax.Click += buttonSendMax_Click;
//
// buttonSendHNS
//
buttonSendHNS.FlatStyle = FlatStyle.Flat;
buttonSendHNS.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
buttonSendHNS.Location = new Point(361, 315);
buttonSendHNS.Name = "buttonSendHNS";
buttonSendHNS.Size = new Size(150, 46);
buttonSendHNS.TabIndex = 14;
buttonSendHNS.Text = "Send";
buttonSendHNS.UseVisualStyleBackColor = true;
buttonSendHNS.Click += buttonSendHNS_Click;
//
// labelSendingError
//
labelSendingError.AutoSize = true;
labelSendingError.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
labelSendingError.Location = new Point(615, 131);
labelSendingError.Name = "labelSendingError";
labelSendingError.Size = new Size(52, 21);
labelSendingError.TabIndex = 13;
labelSendingError.Text = "label1";
labelSendingError.Visible = false;
//
// labelSendingFee
//
labelSendingFee.AutoSize = true;
labelSendingFee.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
labelSendingFee.Location = new Point(254, 234);
labelSendingFee.Name = "labelSendingFee";
labelSendingFee.Size = new Size(109, 21);
labelSendingFee.TabIndex = 12;
labelSendingFee.Text = "Estimated Fee:";
//
// textBoxSendingAmount
//
textBoxSendingAmount.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
textBoxSendingAmount.Location = new Point(346, 159);
textBoxSendingAmount.Name = "textBoxSendingAmount";
textBoxSendingAmount.Size = new Size(344, 29);
textBoxSendingAmount.TabIndex = 11;
textBoxSendingAmount.Leave += textBoxSendingAmount_Leave;
//
// textBoxSendingTo
//
textBoxSendingTo.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
textBoxSendingTo.Location = new Point(346, 98);
textBoxSendingTo.Name = "textBoxSendingTo";
textBoxSendingTo.Size = new Size(344, 29);
textBoxSendingTo.TabIndex = 11;
textBoxSendingTo.Leave += textBoxSendingTo_Leave;
//
// labelSendingMax
//
labelSendingMax.AutoSize = true;
labelSendingMax.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
labelSendingMax.Location = new Point(254, 204);
labelSendingMax.Name = "labelSendingMax";
labelSendingMax.Size = new Size(99, 21);
labelSendingMax.TabIndex = 10;
labelSendingMax.Text = "Max Amount";
//
// labelSendingAmount
//
labelSendingAmount.AutoSize = true;
labelSendingAmount.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
labelSendingAmount.Location = new Point(254, 162);
labelSendingAmount.Name = "labelSendingAmount";
labelSendingAmount.Size = new Size(66, 21);
labelSendingAmount.TabIndex = 9;
labelSendingAmount.Text = "Amount";
//
// labelSendingTo
//
labelSendingTo.AutoSize = true;
labelSendingTo.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
labelSendingTo.Location = new Point(254, 101);
labelSendingTo.Name = "labelSendingTo";
labelSendingTo.Size = new Size(86, 21);
labelSendingTo.TabIndex = 8;
labelSendingTo.Text = "Sending To";
//
// labelSendPrompt
//
labelSendPrompt.AutoSize = true;
labelSendPrompt.Font = new Font("Segoe UI", 15F, FontStyle.Regular, GraphicsUnit.Point);
labelSendPrompt.Location = new Point(395, 38);
labelSendPrompt.Name = "labelSendPrompt";
labelSendPrompt.Size = new Size(101, 28);
labelSendPrompt.TabIndex = 0;
labelSendPrompt.Text = "Send HNS";
//
// MainForm // MainForm
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
@ -399,6 +540,8 @@
groupBoxinfo.PerformLayout(); groupBoxinfo.PerformLayout();
groupBoxbalance.ResumeLayout(false); groupBoxbalance.ResumeLayout(false);
groupBoxbalance.PerformLayout(); groupBoxbalance.PerformLayout();
panelSend.ResumeLayout(false);
panelSend.PerformLayout();
ResumeLayout(false); ResumeLayout(false);
PerformLayout(); PerformLayout();
} }
@ -415,15 +558,15 @@
private Label labelaccountusername; private Label labelaccountusername;
private Label labelaccountpassword; private Label labelaccountpassword;
private GroupBox groupBoxaccount; private GroupBox groupBoxaccount;
private Label label1; private Label labelloginprompt;
private ComboBox comboBoxaccount; private ComboBox comboBoxaccount;
private TextBox textBoxaccountpassword; private TextBox textBoxaccountpassword;
private ToolStripStatusLabel toolStripStatusLabelstatus; private ToolStripStatusLabel toolStripStatusLabelstatus;
private ToolStripSplitButton toolStripSplitButtonlogout; private ToolStripSplitButton toolStripSplitButtonlogout;
private Panel panelNav; private Panel panelNav;
private Button buttonPortfolio; private Button buttonNavPortfolio;
private Button buttonSend; private Button buttonNavSend;
private Button buttonReceive; private Button buttonNavReceive;
private Panel panelPortfolio; private Panel panelPortfolio;
private Label labelLocked; private Label labelLocked;
private Label labelBalance; private Label labelBalance;
@ -435,5 +578,16 @@
private Label labelSyncPercent; private Label labelSyncPercent;
private GroupBox groupBoxTransactions; private GroupBox groupBoxTransactions;
private Panel panelSend; private Panel panelSend;
private Label labelSendPrompt;
private Label labelSendingMax;
private Label labelSendingAmount;
private Label labelSendingTo;
private TextBox textBoxSendingTo;
private TextBox textBoxSendingAmount;
private Label labelSendingFee;
private Label labelSendingError;
private Button buttonSendHNS;
private Button buttonSendMax;
private CheckBox checkBoxSendSubFee;
} }
} }

View File

@ -16,8 +16,8 @@ namespace FireWallet
int Network; int Network;
string account; string account;
string password; string password;
double balance; decimal balance;
double balanceLocked; decimal balanceLocked;
int screen; // 0 = login, 1 = portfolio int screen; // 0 = login, 1 = portfolio
int height; int height;
double syncProgress; double syncProgress;
@ -288,6 +288,7 @@ namespace FireWallet
sw.WriteLine("transparency-percent: 90"); sw.WriteLine("transparency-percent: 90");
sw.WriteLine("selected-bg: #000000"); sw.WriteLine("selected-bg: #000000");
sw.WriteLine("selected-fg: #ffffff"); sw.WriteLine("selected-fg: #ffffff");
sw.WriteLine("error: #ff0000");
sw.Dispose(); sw.Dispose();
AddLog("Created theme file"); AddLog("Created theme file");
@ -415,7 +416,7 @@ namespace FireWallet
toolStripSplitButtonlogout.Visible = true; toolStripSplitButtonlogout.Visible = true;
panelNav.Visible = true; panelNav.Visible = true;
screen = 1; screen = 1;
buttonPortfolio.PerformClick(); buttonNavPortfolio.PerformClick();
} }
} }
@ -449,6 +450,7 @@ namespace FireWallet
} }
panelaccount.Visible = true; panelaccount.Visible = true;
panelNav.Visible = false; panelNav.Visible = false;
panelSend.Visible = false;
toolStripStatusLabelaccount.Text = "Account: Not Logged In"; toolStripStatusLabelaccount.Text = "Account: Not Logged In";
screen = 0; screen = 0;
@ -476,15 +478,21 @@ namespace FireWallet
JObject resp = JObject.Parse(response); JObject resp = JObject.Parse(response);
double available = Convert.ToDouble(resp["unconfirmed"].ToString()) / 1000000; decimal available = Convert.ToDecimal(resp["unconfirmed"].ToString()) / 1000000;
double locked = Convert.ToDouble(resp["lockedUnconfirmed"].ToString()) / 1000000; decimal locked = Convert.ToDecimal(resp["lockedUnconfirmed"].ToString()) / 1000000;
available = available - locked; available = available - locked;
available = Math.Round(available, 2); available = decimal.Round(available, 2);
locked = Math.Round(locked, 2); locked = decimal.Round(locked, 2);
balance = available; balance = available;
balanceLocked = locked; balanceLocked = locked;
} }
/// <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) private async Task<string> APIPost(string path, bool wallet, string content)
{ {
string key = nodeSettings["Key"]; string key = nodeSettings["Key"];
@ -516,6 +524,12 @@ namespace FireWallet
return await resp.Content.ReadAsStringAsync(); 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) private async Task<string> APIGet(string path, bool wallet)
{ {
string key = nodeSettings["Key"]; string key = nodeSettings["Key"];
@ -548,7 +562,7 @@ namespace FireWallet
} }
} }
private async void GetInfo() private async void GetTXHistory()
{ {
// Get height and progress // Get height and progress
String APIresponse = await APIGet("", false); String APIresponse = await APIGet("", false);
@ -650,6 +664,32 @@ namespace FireWallet
} }
private async Task<string> GetFee()
{
try
{
string response = await APIGet("fee", false);
JObject resp = JObject.Parse(response);
decimal fee = Convert.ToDecimal(resp["rate"].ToString());
fee = fee / 1000000;
if (fee < 0.0001m) fee = 1;
return fee.ToString();
//return resp["rate"].ToString();
}
catch
{
return "1";
}
}
private async Task<bool> ValidAddress(string address)
{
string output = await APIPost("", false, "{\"method\": \"validateaddress\",\"params\": [ \"" + address + "\" ]}");
JObject APIresp = JObject.Parse(output);
JObject result = JObject.Parse(APIresp["result"].ToString());
if (result["isvalid"].ToString() == "True") return true;
else return false;
}
#endregion #endregion
#region Timers #region Timers
@ -659,42 +699,173 @@ namespace FireWallet
// If logged in, update info // If logged in, update info
if (panelaccount.Visible == false) if (panelaccount.Visible == false)
{ {
GetInfo(); GetTXHistory();
} }
} }
#endregion #endregion
#region Nav #region Nav
private async void buttonPortfolio_Click(object sender, EventArgs e) private async void PortfolioPanel_Click(object sender, EventArgs e)
{ {
buttonSend.BackColor = ColorTranslator.FromHtml(theme["background"]); buttonNavSend.BackColor = ColorTranslator.FromHtml(theme["background"]);
buttonSend.ForeColor = ColorTranslator.FromHtml(theme["foreground"]); buttonNavSend.ForeColor = ColorTranslator.FromHtml(theme["foreground"]);
panelSend.Hide(); panelSend.Hide();
panelPortfolio.Show(); panelPortfolio.Show();
await UpdateBalance(); await UpdateBalance();
GetInfo(); GetTXHistory();
labelBalance.Text = "Available: " + balance.ToString() + " HNS"; labelBalance.Text = "Available: " + balance.ToString() + " HNS";
labelLocked.Text = "Locked: " + balanceLocked.ToString() + " HNS"; labelLocked.Text = "Locked: " + balanceLocked.ToString() + " HNS";
labelBalanceTotal.Text = "Total: " + (balance + balanceLocked).ToString() + " HNS"; labelBalanceTotal.Text = "Total: " + (balance + balanceLocked).ToString() + " HNS";
if (theme.ContainsKey("selected-bg") && theme.ContainsKey("selected-fg")) if (theme.ContainsKey("selected-bg") && theme.ContainsKey("selected-fg"))
{ {
buttonPortfolio.BackColor = ColorTranslator.FromHtml(theme["selected-bg"]); buttonNavPortfolio.BackColor = ColorTranslator.FromHtml(theme["selected-bg"]);
buttonPortfolio.ForeColor = ColorTranslator.FromHtml(theme["selected-fg"]); buttonNavPortfolio.ForeColor = ColorTranslator.FromHtml(theme["selected-fg"]);
}
}
private async void SendPanel_Click(object sender, EventArgs e)
{
panelPortfolio.Hide();
panelSend.Show();
buttonNavPortfolio.BackColor = ColorTranslator.FromHtml(theme["background"]);
buttonNavPortfolio.ForeColor = ColorTranslator.FromHtml(theme["foreground"]);
if (theme.ContainsKey("selected-bg") && theme.ContainsKey("selected-fg"))
{
buttonNavSend.BackColor = ColorTranslator.FromHtml(theme["selected-bg"]);
buttonNavSend.ForeColor = ColorTranslator.FromHtml(theme["selected-fg"]);
}
if (theme.ContainsKey("error"))
{
labelSendingError.ForeColor = ColorTranslator.FromHtml(theme["error"]);
}
labelSendPrompt.Left = (panelSend.Width - labelSendPrompt.Width) / 2;
buttonSendHNS.Left = (panelSend.Width - buttonSendHNS.Width) / 2;
labelSendingTo.Left = (panelSend.Width - labelSendingTo.Width - textBoxSendingTo.Width) / 2;
labelSendingAmount.Left = labelSendingTo.Left;
textBoxSendingTo.Left = labelSendingTo.Left + labelSendingTo.Width + 10;
textBoxSendingAmount.Left = textBoxSendingTo.Left;
labelSendingMax.Left = labelSendingTo.Left;
labelSendingError.Left = textBoxSendingTo.Left + textBoxSendingTo.Width + 10;
labelSendingFee.Left = labelSendingTo.Left;
buttonSendMax.Left = textBoxSendingAmount.Left + textBoxSendingAmount.Width - buttonSendMax.Width;
checkBoxSendSubFee.Left = labelSendingTo.Left;
labelSendingMax.Text = "Max: " + balance.ToString() + " HNS";
textBoxSendingTo.Focus();
string fee = await GetFee();
labelSendingFee.Text = "Est. Fee: " + fee + " HNS";
labelSendingError.Hide();
}
#endregion
#region Send
private async void textBoxSendingTo_Leave(object sender, EventArgs e)
{
try
{
bool valid = await ValidAddress(textBoxSendingTo.Text);
if (valid)
{
labelSendingError.Hide();
labelSendingError.Text = "";
}
else
{
labelSendingError.Show();
labelSendingError.Text = "Invalid Address";
}
}
catch (Exception ex)
{
labelSendingError.Show();
labelSendingError.Text = ex.Message;
}
}
private void textBoxSendingAmount_Leave(object sender, EventArgs e)
{
decimal amount = 0;
if (decimal.TryParse(textBoxSendingAmount.Text, out amount))
{
labelSendingError.Hide();
labelSendingError.Text = "";
}
else
{
labelSendingError.Show();
labelSendingError.Text = "Invalid Amount";
}
}
private async void buttonSendMax_Click(object sender, EventArgs e)
{
string fee = await GetFee();
decimal feeDecimal = decimal.Parse(fee);
textBoxSendingAmount.Text = (balance - feeDecimal).ToString();
}
private async void buttonSendHNS_Click(object sender, EventArgs e)
{
try
{
string address = textBoxSendingTo.Text;
bool valid = await ValidAddress(address);
if (!valid)
{
labelSendingError.Show();
labelSendingError.Text = "Invalid Address";
return;
}
decimal amount = 0;
if (!decimal.TryParse(textBoxSendingAmount.Text, out amount))
{
labelSendingError.Show();
labelSendingError.Text += " Invalid Amount";
return;
}
string feeString = await GetFee();
decimal fee = decimal.Parse(feeString);
string subtractFee = "false";
if (checkBoxSendSubFee.Checked) subtractFee = "true";
else if (amount > (balance - fee))
{
labelSendingError.Show();
labelSendingError.Text += " Insufficient Funds";
return;
}
AddLog("Sending " + amount.ToString() + " HNS to " + address);
string content = "{\"method\": \"sendtoaddress\",\"params\": [ \"" + address + "\", " +
amount.ToString() + ", \"\", \"\", " + subtractFee + " ]}";
string output = await APIPost("", true, content);
JObject APIresp = JObject.Parse(output);
if (APIresp["error"].ToString() == "null")
{
NotifyForm notify = new NotifyForm("Error Transaction Failed");
notify.ShowDialog();
return;
}
string hash = APIresp["result"].ToString();
string link = userSettings["explorer-tx"] + hash;
NotifyForm notifySuccess = new NotifyForm("Transaction Sent\nThis transaction could take up to 20 minutes to mine",
"Explorer",link);
notifySuccess.ShowDialog();
textBoxSendingTo.Text = "";
textBoxSendingAmount.Text = "";
labelSendingError.Hide();
labelSendingError.Text = "";
buttonNavPortfolio.PerformClick();
}
catch (Exception ex)
{
AddLog(ex.Message);
labelSendingError.Show();
labelSendingError.Text = ex.Message;
} }
} }
#endregion #endregion
private void buttonSend_Click(object sender, EventArgs e)
{
panelPortfolio.Hide();
panelSend.Show();
buttonPortfolio.BackColor = ColorTranslator.FromHtml(theme["background"]);
buttonPortfolio.ForeColor = ColorTranslator.FromHtml(theme["foreground"]);
if (theme.ContainsKey("selected-bg") && theme.ContainsKey("selected-fg"))
{
buttonSend.BackColor = ColorTranslator.FromHtml(theme["selected-bg"]);
buttonSend.ForeColor = ColorTranslator.FromHtml(theme["selected-fg"]);
}
}
} }
} }