main: Added receive page

This commit is contained in:
Nathan Woodburn 2023-06-07 14:47:59 +10:00
parent 1ee4483619
commit fc0b111701
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
5 changed files with 217 additions and 30 deletions

View File

@ -1,4 +1,9 @@
namespace FireWallet
using Color = System.Drawing.Color;
using Point = System.Drawing.Point;
using Size = System.Drawing.Size;
using SizeF = System.Drawing.SizeF;
namespace FireWallet
{
partial class CreateForm
{

View File

@ -9,6 +9,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BarCode" Version="2023.6.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

View File

@ -1,4 +1,9 @@
namespace FireWallet
using Color = System.Drawing.Color;
using Point = System.Drawing.Point;
using Size = System.Drawing.Size;
using SizeF = System.Drawing.SizeF;
namespace FireWallet
{
partial class MainForm
{
@ -70,6 +75,11 @@
labelSendingAmount = new Label();
labelSendingTo = new Label();
labelSendPrompt = new Label();
panelRecieve = new Panel();
pictureBoxReceiveQR = new PictureBox();
labelReceive2 = new Label();
textBoxReceiveAddress = new TextBox();
labelReceive1 = new Label();
statusStripmain.SuspendLayout();
panelaccount.SuspendLayout();
groupBoxaccount.SuspendLayout();
@ -78,6 +88,8 @@
groupBoxinfo.SuspendLayout();
groupBoxbalance.SuspendLayout();
panelSend.SuspendLayout();
panelRecieve.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxReceiveQR).BeginInit();
SuspendLayout();
//
// statusStripmain
@ -248,6 +260,7 @@
buttonNavReceive.TabStop = false;
buttonNavReceive.Text = "Receive";
buttonNavReceive.UseVisualStyleBackColor = true;
buttonNavReceive.Click += ReceivePanel_Click;
//
// buttonNavSend
//
@ -393,7 +406,7 @@
panelSend.Controls.Add(labelSendingAmount);
panelSend.Controls.Add(labelSendingTo);
panelSend.Controls.Add(labelSendPrompt);
panelSend.Location = new Point(120, 25);
panelSend.Location = new Point(448, 170);
panelSend.Name = "panelSend";
panelSend.Size = new Size(974, 521);
panelSend.TabIndex = 2;
@ -408,6 +421,7 @@
checkBoxSendSubFee.Name = "checkBoxSendSubFee";
checkBoxSendSubFee.Size = new Size(206, 25);
checkBoxSendSubFee.TabIndex = 16;
checkBoxSendSubFee.TabStop = false;
checkBoxSendSubFee.Text = "Subtract Fee from Output";
checkBoxSendSubFee.UseVisualStyleBackColor = true;
//
@ -419,6 +433,7 @@
buttonSendMax.Name = "buttonSendMax";
buttonSendMax.Size = new Size(81, 29);
buttonSendMax.TabIndex = 15;
buttonSendMax.TabStop = false;
buttonSendMax.Text = "Max";
buttonSendMax.UseVisualStyleBackColor = true;
buttonSendMax.Click += buttonSendMax_Click;
@ -430,7 +445,7 @@
buttonSendHNS.Location = new Point(361, 315);
buttonSendHNS.Name = "buttonSendHNS";
buttonSendHNS.Size = new Size(150, 46);
buttonSendHNS.TabIndex = 14;
buttonSendHNS.TabIndex = 3;
buttonSendHNS.Text = "Send";
buttonSendHNS.UseVisualStyleBackColor = true;
buttonSendHNS.Click += buttonSendHNS_Click;
@ -462,7 +477,7 @@
textBoxSendingAmount.Location = new Point(346, 159);
textBoxSendingAmount.Name = "textBoxSendingAmount";
textBoxSendingAmount.Size = new Size(344, 29);
textBoxSendingAmount.TabIndex = 11;
textBoxSendingAmount.TabIndex = 2;
textBoxSendingAmount.Leave += textBoxSendingAmount_Leave;
//
// textBoxSendingTo
@ -471,7 +486,7 @@
textBoxSendingTo.Location = new Point(346, 98);
textBoxSendingTo.Name = "textBoxSendingTo";
textBoxSendingTo.Size = new Size(344, 29);
textBoxSendingTo.TabIndex = 11;
textBoxSendingTo.TabIndex = 1;
textBoxSendingTo.Leave += textBoxSendingTo_Leave;
//
// labelSendingMax
@ -514,11 +529,63 @@
labelSendPrompt.TabIndex = 0;
labelSendPrompt.Text = "Send HNS";
//
// panelRecieve
//
panelRecieve.Controls.Add(pictureBoxReceiveQR);
panelRecieve.Controls.Add(labelReceive2);
panelRecieve.Controls.Add(textBoxReceiveAddress);
panelRecieve.Controls.Add(labelReceive1);
panelRecieve.Location = new Point(120, 25);
panelRecieve.Name = "panelRecieve";
panelRecieve.Size = new Size(995, 523);
panelRecieve.TabIndex = 17;
panelRecieve.Visible = false;
//
// pictureBoxReceiveQR
//
pictureBoxReceiveQR.Location = new Point(391, 190);
pictureBoxReceiveQR.Name = "pictureBoxReceiveQR";
pictureBoxReceiveQR.Size = new Size(300, 300);
pictureBoxReceiveQR.SizeMode = PictureBoxSizeMode.AutoSize;
pictureBoxReceiveQR.TabIndex = 20;
pictureBoxReceiveQR.TabStop = false;
//
// labelReceive2
//
labelReceive2.AutoSize = true;
labelReceive2.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
labelReceive2.Location = new Point(463, 148);
labelReceive2.Name = "labelReceive2";
labelReceive2.Size = new Size(205, 21);
labelReceive2.TabIndex = 19;
labelReceive2.Text = "Click your address to copy it";
//
// textBoxReceiveAddress
//
textBoxReceiveAddress.Font = new Font("Segoe UI", 14F, FontStyle.Regular, GraphicsUnit.Point);
textBoxReceiveAddress.Location = new Point(299, 110);
textBoxReceiveAddress.Name = "textBoxReceiveAddress";
textBoxReceiveAddress.ReadOnly = true;
textBoxReceiveAddress.Size = new Size(464, 32);
textBoxReceiveAddress.TabIndex = 18;
textBoxReceiveAddress.Click += textBoxRecieveAddress_Click;
//
// labelReceive1
//
labelReceive1.AutoSize = true;
labelReceive1.Font = new Font("Segoe UI", 14F, FontStyle.Regular, GraphicsUnit.Point);
labelReceive1.Location = new Point(361, 77);
labelReceive1.Name = "labelReceive1";
labelReceive1.Size = new Size(252, 25);
labelReceive1.TabIndex = 0;
labelReceive1.Text = "Here is your receive address:";
//
// MainForm
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1152, 575);
Controls.Add(panelRecieve);
Controls.Add(panelSend);
Controls.Add(panelPortfolio);
Controls.Add(panelNav);
@ -542,6 +609,9 @@
groupBoxbalance.PerformLayout();
panelSend.ResumeLayout(false);
panelSend.PerformLayout();
panelRecieve.ResumeLayout(false);
panelRecieve.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxReceiveQR).EndInit();
ResumeLayout(false);
PerformLayout();
}
@ -589,5 +659,10 @@
private Button buttonSendHNS;
private Button buttonSendMax;
private CheckBox checkBoxSendSubFee;
private Panel panelRecieve;
private Label labelReceive1;
private TextBox textBoxReceiveAddress;
private Label labelReceive2;
private PictureBox pictureBoxReceiveQR;
}
}

View File

@ -1,8 +1,15 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Runtime.InteropServices;
using System.Security.Policy;
using System.Windows.Forms;
using Newtonsoft.Json.Linq;
using Point = System.Drawing.Point;
using Size = System.Drawing.Size;
using IronBarCode;
namespace FireWallet
{
@ -451,6 +458,7 @@ namespace FireWallet
panelaccount.Visible = true;
panelNav.Visible = false;
panelSend.Visible = false;
panelRecieve.Visible = false;
toolStripStatusLabelaccount.Text = "Account: Not Logged In";
screen = 0;
@ -478,7 +486,7 @@ namespace FireWallet
JObject resp = JObject.Parse(response);
decimal available = Convert.ToDecimal(resp["unconfirmed"].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);
@ -561,6 +569,19 @@ namespace FireWallet
return "Error";
}
}
private async Task<string> GetAddress()
{
string content = "{\"account\":\"default\"}";
string path = "wallet/" + account + "/address";
string APIresponse = await APIPost(path, true, content);
if (APIresponse == "Error")
{
AddLog("GetAddress Error");
return "Error";
}
JObject resp = JObject.Parse(APIresponse);
return resp["address"].ToString();
}
private async void GetTXHistory()
{
@ -703,14 +724,16 @@ namespace FireWallet
}
}
#endregion
#region Nav
private async void PortfolioPanel_Click(object sender, EventArgs e)
{
buttonNavSend.BackColor = ColorTranslator.FromHtml(theme["background"]);
buttonNavSend.ForeColor = ColorTranslator.FromHtml(theme["foreground"]);
panelSend.Hide();
panelPortfolio.Show();
panelRecieve.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"]);
await UpdateBalance();
GetTXHistory();
labelBalance.Text = "Available: " + balance.ToString() + " HNS";
@ -727,8 +750,11 @@ namespace FireWallet
{
panelPortfolio.Hide();
panelSend.Show();
panelRecieve.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"]);
if (theme.ContainsKey("selected-bg") && theme.ContainsKey("selected-fg"))
{
buttonNavSend.BackColor = ColorTranslator.FromHtml(theme["selected-bg"]);
@ -757,29 +783,99 @@ namespace FireWallet
labelSendingFee.Text = "Est. Fee: " + fee + " HNS";
labelSendingError.Hide();
}
private async void ReceivePanel_Click(object sender, EventArgs e)
{
panelSend.Hide();
panelPortfolio.Hide();
panelRecieve.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"]);
if (theme.ContainsKey("selected-bg") && theme.ContainsKey("selected-fg"))
{
buttonNavReceive.BackColor = ColorTranslator.FromHtml(theme["selected-bg"]);
buttonNavReceive.ForeColor = ColorTranslator.FromHtml(theme["selected-fg"]);
}
labelReceive1.Left = (panelRecieve.Width - labelReceive1.Width) / 2;
labelReceive2.Left = (panelRecieve.Width - labelReceive2.Width) / 2;
textBoxReceiveAddress.Left = (panelRecieve.Width - textBoxReceiveAddress.Width) / 2;
string address = await GetAddress();
textBoxReceiveAddress.Text = address;
textBoxReceiveAddress.TextAlign = HorizontalAlignment.Center;
Size size = TextRenderer.MeasureText(textBoxReceiveAddress.Text, textBoxReceiveAddress.Font);
textBoxReceiveAddress.Width = size.Width + 10;
textBoxReceiveAddress.Left = (panelRecieve.Width - textBoxReceiveAddress.Width) / 2;
GeneratedBarcode Qrcode = QRCodeWriter.CreateQrCode(textBoxReceiveAddress.Text);
pictureBoxReceiveQR.Image = Qrcode.Image;
pictureBoxReceiveQR.SizeMode = PictureBoxSizeMode.Zoom;
pictureBoxReceiveQR.Width = panelRecieve.Width / 3;
pictureBoxReceiveQR.Left = (panelRecieve.Width - pictureBoxReceiveQR.Width) / 2;
}
#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)
if (textBoxSendingTo.Text == "") return;
if (textBoxSendingTo.Text.Substring(0, 1) == "@")
{
labelSendingError.Show();
labelSendingError.Text = ex.Message;
labelSendingError.Text = "HIP-02 Not supported yet";
return;
/*
string domain = textBoxSendingTo.Text.Substring(1);
try
{
string address = "";
bool valid = await ValidAddress(address);
if (valid)
{
labelSendingError.Hide();
labelSendingError.Text = "";
}
else
{
labelSendingError.Show();
labelSendingError.Text = "Invalid Address";
}
}
catch (Exception ex)
{
labelSendingError.Show();
labelSendingError.Text = ex.Message;
}*/
}
else
{
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;
}
}
}
@ -797,7 +893,7 @@ namespace FireWallet
labelSendingError.Text = "Invalid Amount";
}
}
private async void buttonSendMax_Click(object sender, EventArgs e)
{
string fee = await GetFee();
@ -844,12 +940,12 @@ namespace FireWallet
{
NotifyForm notify = new NotifyForm("Error Transaction Failed");
notify.ShowDialog();
return;
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);
"Explorer", link);
notifySuccess.ShowDialog();
textBoxSendingTo.Text = "";
textBoxSendingAmount.Text = "";
@ -867,5 +963,11 @@ namespace FireWallet
}
#endregion
private void textBoxRecieveAddress_Click(object sender, EventArgs e)
{
Clipboard.SetText(textBoxReceiveAddress.Text);
labelReceive2.Text = "Copied to clipboard";
labelReceive2.Left = (panelRecieve.Width - labelReceive2.Width) / 2;
}
}
}

View File

@ -1,4 +1,8 @@
namespace FireWallet
using Color = System.Drawing.Color;
using Point = System.Drawing.Point;
using Size = System.Drawing.Size;
using SizeF = System.Drawing.SizeF;
namespace FireWallet
{
partial class NotifyForm
{