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 partial class CreateForm
{ {

View File

@ -9,6 +9,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="BarCode" Version="2023.6.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup> </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 partial class MainForm
{ {
@ -70,6 +75,11 @@
labelSendingAmount = new Label(); labelSendingAmount = new Label();
labelSendingTo = new Label(); labelSendingTo = new Label();
labelSendPrompt = new Label(); labelSendPrompt = new Label();
panelRecieve = new Panel();
pictureBoxReceiveQR = new PictureBox();
labelReceive2 = new Label();
textBoxReceiveAddress = new TextBox();
labelReceive1 = new Label();
statusStripmain.SuspendLayout(); statusStripmain.SuspendLayout();
panelaccount.SuspendLayout(); panelaccount.SuspendLayout();
groupBoxaccount.SuspendLayout(); groupBoxaccount.SuspendLayout();
@ -78,6 +88,8 @@
groupBoxinfo.SuspendLayout(); groupBoxinfo.SuspendLayout();
groupBoxbalance.SuspendLayout(); groupBoxbalance.SuspendLayout();
panelSend.SuspendLayout(); panelSend.SuspendLayout();
panelRecieve.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxReceiveQR).BeginInit();
SuspendLayout(); SuspendLayout();
// //
// statusStripmain // statusStripmain
@ -248,6 +260,7 @@
buttonNavReceive.TabStop = false; buttonNavReceive.TabStop = false;
buttonNavReceive.Text = "Receive"; buttonNavReceive.Text = "Receive";
buttonNavReceive.UseVisualStyleBackColor = true; buttonNavReceive.UseVisualStyleBackColor = true;
buttonNavReceive.Click += ReceivePanel_Click;
// //
// buttonNavSend // buttonNavSend
// //
@ -393,7 +406,7 @@
panelSend.Controls.Add(labelSendingAmount); panelSend.Controls.Add(labelSendingAmount);
panelSend.Controls.Add(labelSendingTo); panelSend.Controls.Add(labelSendingTo);
panelSend.Controls.Add(labelSendPrompt); panelSend.Controls.Add(labelSendPrompt);
panelSend.Location = new Point(120, 25); panelSend.Location = new Point(448, 170);
panelSend.Name = "panelSend"; panelSend.Name = "panelSend";
panelSend.Size = new Size(974, 521); panelSend.Size = new Size(974, 521);
panelSend.TabIndex = 2; panelSend.TabIndex = 2;
@ -408,6 +421,7 @@
checkBoxSendSubFee.Name = "checkBoxSendSubFee"; checkBoxSendSubFee.Name = "checkBoxSendSubFee";
checkBoxSendSubFee.Size = new Size(206, 25); checkBoxSendSubFee.Size = new Size(206, 25);
checkBoxSendSubFee.TabIndex = 16; checkBoxSendSubFee.TabIndex = 16;
checkBoxSendSubFee.TabStop = false;
checkBoxSendSubFee.Text = "Subtract Fee from Output"; checkBoxSendSubFee.Text = "Subtract Fee from Output";
checkBoxSendSubFee.UseVisualStyleBackColor = true; checkBoxSendSubFee.UseVisualStyleBackColor = true;
// //
@ -419,6 +433,7 @@
buttonSendMax.Name = "buttonSendMax"; buttonSendMax.Name = "buttonSendMax";
buttonSendMax.Size = new Size(81, 29); buttonSendMax.Size = new Size(81, 29);
buttonSendMax.TabIndex = 15; buttonSendMax.TabIndex = 15;
buttonSendMax.TabStop = false;
buttonSendMax.Text = "Max"; buttonSendMax.Text = "Max";
buttonSendMax.UseVisualStyleBackColor = true; buttonSendMax.UseVisualStyleBackColor = true;
buttonSendMax.Click += buttonSendMax_Click; buttonSendMax.Click += buttonSendMax_Click;
@ -430,7 +445,7 @@
buttonSendHNS.Location = new Point(361, 315); buttonSendHNS.Location = new Point(361, 315);
buttonSendHNS.Name = "buttonSendHNS"; buttonSendHNS.Name = "buttonSendHNS";
buttonSendHNS.Size = new Size(150, 46); buttonSendHNS.Size = new Size(150, 46);
buttonSendHNS.TabIndex = 14; buttonSendHNS.TabIndex = 3;
buttonSendHNS.Text = "Send"; buttonSendHNS.Text = "Send";
buttonSendHNS.UseVisualStyleBackColor = true; buttonSendHNS.UseVisualStyleBackColor = true;
buttonSendHNS.Click += buttonSendHNS_Click; buttonSendHNS.Click += buttonSendHNS_Click;
@ -462,7 +477,7 @@
textBoxSendingAmount.Location = new Point(346, 159); textBoxSendingAmount.Location = new Point(346, 159);
textBoxSendingAmount.Name = "textBoxSendingAmount"; textBoxSendingAmount.Name = "textBoxSendingAmount";
textBoxSendingAmount.Size = new Size(344, 29); textBoxSendingAmount.Size = new Size(344, 29);
textBoxSendingAmount.TabIndex = 11; textBoxSendingAmount.TabIndex = 2;
textBoxSendingAmount.Leave += textBoxSendingAmount_Leave; textBoxSendingAmount.Leave += textBoxSendingAmount_Leave;
// //
// textBoxSendingTo // textBoxSendingTo
@ -471,7 +486,7 @@
textBoxSendingTo.Location = new Point(346, 98); textBoxSendingTo.Location = new Point(346, 98);
textBoxSendingTo.Name = "textBoxSendingTo"; textBoxSendingTo.Name = "textBoxSendingTo";
textBoxSendingTo.Size = new Size(344, 29); textBoxSendingTo.Size = new Size(344, 29);
textBoxSendingTo.TabIndex = 11; textBoxSendingTo.TabIndex = 1;
textBoxSendingTo.Leave += textBoxSendingTo_Leave; textBoxSendingTo.Leave += textBoxSendingTo_Leave;
// //
// labelSendingMax // labelSendingMax
@ -514,11 +529,63 @@
labelSendPrompt.TabIndex = 0; labelSendPrompt.TabIndex = 0;
labelSendPrompt.Text = "Send HNS"; 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 // MainForm
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1152, 575); ClientSize = new Size(1152, 575);
Controls.Add(panelRecieve);
Controls.Add(panelSend); Controls.Add(panelSend);
Controls.Add(panelPortfolio); Controls.Add(panelPortfolio);
Controls.Add(panelNav); Controls.Add(panelNav);
@ -542,6 +609,9 @@
groupBoxbalance.PerformLayout(); groupBoxbalance.PerformLayout();
panelSend.ResumeLayout(false); panelSend.ResumeLayout(false);
panelSend.PerformLayout(); panelSend.PerformLayout();
panelRecieve.ResumeLayout(false);
panelRecieve.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxReceiveQR).EndInit();
ResumeLayout(false); ResumeLayout(false);
PerformLayout(); PerformLayout();
} }
@ -589,5 +659,10 @@
private Button buttonSendHNS; private Button buttonSendHNS;
private Button buttonSendMax; private Button buttonSendMax;
private CheckBox checkBoxSendSubFee; 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.Diagnostics;
using System.IO;
using System.Net;
using System.Net.Http; using System.Net.Http;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Security.Policy; using System.Security.Policy;
using System.Windows.Forms;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using Point = System.Drawing.Point;
using Size = System.Drawing.Size;
using IronBarCode;
namespace FireWallet namespace FireWallet
{ {
@ -451,6 +458,7 @@ namespace FireWallet
panelaccount.Visible = true; panelaccount.Visible = true;
panelNav.Visible = false; panelNav.Visible = false;
panelSend.Visible = false; panelSend.Visible = false;
panelRecieve.Visible = false;
toolStripStatusLabelaccount.Text = "Account: Not Logged In"; toolStripStatusLabelaccount.Text = "Account: Not Logged In";
screen = 0; screen = 0;
@ -478,7 +486,7 @@ namespace FireWallet
JObject resp = JObject.Parse(response); 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; decimal locked = Convert.ToDecimal(resp["lockedUnconfirmed"].ToString()) / 1000000;
available = available - locked; available = available - locked;
available = decimal.Round(available, 2); available = decimal.Round(available, 2);
@ -561,6 +569,19 @@ namespace FireWallet
return "Error"; 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() private async void GetTXHistory()
{ {
@ -703,14 +724,16 @@ namespace FireWallet
} }
} }
#endregion #endregion
#region Nav #region Nav
private async void PortfolioPanel_Click(object sender, EventArgs e) private async void PortfolioPanel_Click(object sender, EventArgs e)
{ {
buttonNavSend.BackColor = ColorTranslator.FromHtml(theme["background"]);
buttonNavSend.ForeColor = ColorTranslator.FromHtml(theme["foreground"]);
panelSend.Hide(); panelSend.Hide();
panelPortfolio.Show(); 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(); await UpdateBalance();
GetTXHistory(); GetTXHistory();
labelBalance.Text = "Available: " + balance.ToString() + " HNS"; labelBalance.Text = "Available: " + balance.ToString() + " HNS";
@ -727,8 +750,11 @@ namespace FireWallet
{ {
panelPortfolio.Hide(); panelPortfolio.Hide();
panelSend.Show(); panelSend.Show();
panelRecieve.Hide();
buttonNavPortfolio.BackColor = ColorTranslator.FromHtml(theme["background"]); buttonNavPortfolio.BackColor = ColorTranslator.FromHtml(theme["background"]);
buttonNavPortfolio.ForeColor = ColorTranslator.FromHtml(theme["foreground"]); 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")) if (theme.ContainsKey("selected-bg") && theme.ContainsKey("selected-fg"))
{ {
buttonNavSend.BackColor = ColorTranslator.FromHtml(theme["selected-bg"]); buttonNavSend.BackColor = ColorTranslator.FromHtml(theme["selected-bg"]);
@ -757,10 +783,79 @@ namespace FireWallet
labelSendingFee.Text = "Est. Fee: " + fee + " HNS"; labelSendingFee.Text = "Est. Fee: " + fee + " HNS";
labelSendingError.Hide(); 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 #endregion
#region Send #region Send
private async void textBoxSendingTo_Leave(object sender, EventArgs e) private async void textBoxSendingTo_Leave(object sender, EventArgs e)
{
if (textBoxSendingTo.Text == "") return;
if (textBoxSendingTo.Text.Substring(0, 1) == "@")
{
labelSendingError.Show();
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 try
{ {
@ -782,6 +877,7 @@ namespace FireWallet
labelSendingError.Text = ex.Message; labelSendingError.Text = ex.Message;
} }
} }
}
private void textBoxSendingAmount_Leave(object sender, EventArgs e) private void textBoxSendingAmount_Leave(object sender, EventArgs e)
{ {
@ -867,5 +963,11 @@ namespace FireWallet
} }
#endregion #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 partial class NotifyForm
{ {