main: Added sending HNS to address

This commit is contained in:
Nathan Woodburn 2023-07-07 14:04:47 +10:00
parent f652995b21
commit 2532d4d4c9
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
4 changed files with 199 additions and 6 deletions

View File

@ -14,6 +14,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="DnsClient" Version="1.7.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="QRCoder" Version="1.4.3" /> <PackageReference Include="QRCoder" Version="1.4.3" />
</ItemGroup> </ItemGroup>

View File

@ -6,11 +6,17 @@ using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.Security.Cryptography;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using FireWallet; using FireWallet;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using DnsClient;
using DnsClient.Protocol;
using System.Security.Policy;
namespace FireWalletLite namespace FireWalletLite
{ {
@ -20,6 +26,7 @@ namespace FireWalletLite
public string dir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\FireWalletLite\\"; public string dir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\FireWalletLite\\";
public int daysToExpire = 90; // How many days to check for domain exiries. If domain will expire in less than this, prompt user to renew. public int daysToExpire = 90; // How many days to check for domain exiries. If domain will expire in less than this, prompt user to renew.
public string TXExplorer = "https://niami.io/tx/"; // Transaction explorer URL public string TXExplorer = "https://niami.io/tx/"; // Transaction explorer URL
public string DomainExplorer = "https://niami.io/domain/"; // Domain explorer URL
public Dictionary<string, string> Theme { get; set; } public Dictionary<string, string> Theme { get; set; }
HttpClient httpClient = new HttpClient(); HttpClient httpClient = new HttpClient();
Decimal Balance { get; set; } Decimal Balance { get; set; }
@ -193,7 +200,7 @@ namespace FireWalletLite
available = decimal.Round(available, 2); available = decimal.Round(available, 2);
locked = decimal.Round(locked, 2); locked = decimal.Round(locked, 2);
Balance = available; Balance = available;
labelBalance.Text = "Balance: " + available; labelBalance.Text = "Balance: " + available + " HNS";
// Get domain count // Get domain count
UpdateDomains(); UpdateDomains();
@ -270,6 +277,14 @@ namespace FireWalletLite
return "Error"; return "Error";
} }
} }
public 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;
}
public string[] Domains { get; set; } public string[] Domains { get; set; }
public string[] DomainsRenewable { get; set; } public string[] DomainsRenewable { get; set; }
private async void UpdateDomains() private async void UpdateDomains()
@ -297,7 +312,6 @@ namespace FireWalletLite
panelDomainList.Controls.Add(noDomainsLabel); panelDomainList.Controls.Add(noDomainsLabel);
noDomainsLabel.Left = panelDomainList.Width / 2 - noDomainsLabel.Width / 2; noDomainsLabel.Left = panelDomainList.Width / 2 - noDomainsLabel.Width / 2;
noDomainsLabel.Top = 10; noDomainsLabel.Top = 10;
return;
} }
foreach (JObject name in names) foreach (JObject name in names)
@ -348,9 +362,8 @@ namespace FireWalletLite
expiry.Left = domainTMP.Width - expiry.Width - 100; expiry.Left = domainTMP.Width - expiry.Width - 100;
domainTMP.Controls.Add(expiry); domainTMP.Controls.Add(expiry);
} }
/*
// On Click open domain // On Click open domain
/*
domainTMP.Click += new EventHandler((sender, e) => domainTMP.Click += new EventHandler((sender, e) =>
{ {
DomainForm domainForm = new DomainForm(this, name["name"].ToString(), UserSettings["explorer-tx"], UserSettings["explorer-domain"]); DomainForm domainForm = new DomainForm(this, name["name"].ToString(), UserSettings["explorer-tx"], UserSettings["explorer-domain"]);
@ -520,7 +533,6 @@ namespace FireWalletLite
} }
return; return;
} }
JObject result = JObject.Parse(jObject["result"].ToString()); JObject result = JObject.Parse(jObject["result"].ToString());
string hash = result["hash"].ToString(); string hash = result["hash"].ToString();
AddLog("Batch sent with hash: " + hash); AddLog("Batch sent with hash: " + hash);

View File

@ -29,13 +29,94 @@
private void InitializeComponent() private void InitializeComponent()
{ {
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SendForm)); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SendForm));
labelAddress = new Label();
textBoxAddress = new TextBox();
labelAmount = new Label();
textBoxAmount = new TextBox();
labelHNSToken = new Label();
buttonSend = new Button();
labelMax = new Label();
SuspendLayout(); SuspendLayout();
// //
// labelAddress
//
labelAddress.AutoSize = true;
labelAddress.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
labelAddress.Location = new Point(268, 10);
labelAddress.Name = "labelAddress";
labelAddress.Size = new Size(69, 21);
labelAddress.TabIndex = 0;
labelAddress.Text = "Address:";
//
// textBoxAddress
//
textBoxAddress.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
textBoxAddress.Location = new Point(131, 34);
textBoxAddress.Name = "textBoxAddress";
textBoxAddress.Size = new Size(391, 29);
textBoxAddress.TabIndex = 1;
//
// labelAmount
//
labelAmount.AutoSize = true;
labelAmount.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
labelAmount.Location = new Point(268, 98);
labelAmount.Name = "labelAmount";
labelAmount.Size = new Size(69, 21);
labelAmount.TabIndex = 2;
labelAmount.Text = "Amount:";
//
// textBoxAmount
//
textBoxAmount.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
textBoxAmount.Location = new Point(183, 122);
textBoxAmount.Name = "textBoxAmount";
textBoxAmount.Size = new Size(208, 29);
textBoxAmount.TabIndex = 3;
//
// labelHNSToken
//
labelHNSToken.AutoSize = true;
labelHNSToken.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
labelHNSToken.Location = new Point(397, 125);
labelHNSToken.Name = "labelHNSToken";
labelHNSToken.Size = new Size(42, 21);
labelHNSToken.TabIndex = 4;
labelHNSToken.Text = "HNS";
//
// buttonSend
//
buttonSend.FlatStyle = FlatStyle.Flat;
buttonSend.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
buttonSend.Location = new Point(257, 247);
buttonSend.Name = "buttonSend";
buttonSend.Size = new Size(97, 40);
buttonSend.TabIndex = 5;
buttonSend.Text = "Send";
buttonSend.UseVisualStyleBackColor = true;
buttonSend.Click += buttonSend_Click;
//
// labelMax
//
labelMax.AutoSize = true;
labelMax.Location = new Point(277, 164);
labelMax.Name = "labelMax";
labelMax.Size = new Size(33, 15);
labelMax.TabIndex = 6;
labelMax.Text = "MAX";
//
// SendForm // SendForm
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450); ClientSize = new Size(653, 299);
Controls.Add(labelMax);
Controls.Add(buttonSend);
Controls.Add(labelHNSToken);
Controls.Add(textBoxAmount);
Controls.Add(labelAmount);
Controls.Add(textBoxAddress);
Controls.Add(labelAddress);
FormBorderStyle = FormBorderStyle.Fixed3D; FormBorderStyle = FormBorderStyle.Fixed3D;
Icon = (Icon)resources.GetObject("$this.Icon"); Icon = (Icon)resources.GetObject("$this.Icon");
Margin = new Padding(4, 3, 4, 3); Margin = new Padding(4, 3, 4, 3);
@ -45,8 +126,17 @@
ShowInTaskbar = false; ShowInTaskbar = false;
Text = "Send HNS"; Text = "Send HNS";
ResumeLayout(false); ResumeLayout(false);
PerformLayout();
} }
#endregion #endregion
private Label labelAddress;
private TextBox textBoxAddress;
private Label labelAmount;
private TextBox textBoxAmount;
private Label labelHNSToken;
private Button buttonSend;
private Label labelMax;
} }
} }

View File

@ -7,6 +7,8 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using FireWallet;
using Newtonsoft.Json.Linq;
namespace FireWalletLite namespace FireWalletLite
{ {
@ -20,6 +22,94 @@ namespace FireWalletLite
InitializeComponent(); InitializeComponent();
this.main = main; this.main = main;
this.unlockedbalance = Unlockedbalance; this.unlockedbalance = Unlockedbalance;
// Theme form
this.BackColor = ColorTranslator.FromHtml(main.Theme["background"]);
this.ForeColor = ColorTranslator.FromHtml(main.Theme["foreground"]);
foreach (Control control in Controls)
{
main.ThemeControl(control);
}
labelMax.Text = "Max: " + (unlockedbalance - fee).ToString() + " HNS";
if (unlockedbalance < fee)
{
labelMax.Text = "Max: 0 HNS";
//buttonSend.Enabled = false;
}
// Allign controls
labelAddress.Left = (this.ClientSize.Width - labelAddress.Width) / 2;
labelAmount.Left = (this.ClientSize.Width - labelAmount.Width) / 2;
textBoxAddress.Left = (this.ClientSize.Width - textBoxAddress.Width) / 2;
labelMax.Left = (this.ClientSize.Width - labelMax.Width) / 2;
textBoxAmount.Left = (this.ClientSize.Width - textBoxAmount.Width - labelHNSToken.Width - 10) / 2;
labelHNSToken.Left = textBoxAmount.Left + textBoxAmount.Width + 10;
buttonSend.Left = (this.ClientSize.Width - buttonSend.Width) / 2;
}
private async void buttonSend_Click(object sender, EventArgs e)
{
buttonSend.Enabled = false;
string address = textBoxAddress.Text;
if (textBoxAddress.Text.Substring(0,1) == "@")
{
// HIP-02 not supported yet
NotifyForm notify = new NotifyForm("HIP-02 not supported yet");
notify.ShowDialog();
notify.Dispose();
buttonSend.Enabled = true;
return;
}
bool valid = await main.ValidAddress(address);
if (!valid)
{
NotifyForm notify = new NotifyForm("Invalid address");
notify.ShowDialog();
notify.Dispose();
buttonSend.Enabled = true;
return;
}
decimal amount = 0;
if (!decimal.TryParse(textBoxAmount.Text, out amount))
{
NotifyForm notify = new NotifyForm("Invalid amount");
notify.ShowDialog();
notify.Dispose();
return;
}
if (amount > unlockedbalance - fee)
{
NotifyForm notify = new NotifyForm("Insufficient balance");
notify.ShowDialog();
notify.Dispose();
return;
}
string content = "{\"method\": \"sendtoaddress\",\"params\": [ \"" + address + "\", " +
amount.ToString() + "]}";
string output = await main.APIPost("", true, content);
JObject APIresp = JObject.Parse(output);
if (APIresp["error"].ToString() != "")
{
main.AddLog("Failed:");
main.AddLog(APIresp.ToString());
JObject error = JObject.Parse(APIresp["error"].ToString());
string ErrorMessage = error["message"].ToString();
NotifyForm notify = new NotifyForm("Error Transaction Failed\n" + ErrorMessage);
notify.ShowDialog();
notify.Dispose();
return;
}
string hash = APIresp["result"].ToString();
string link = main.TXExplorer + hash;
NotifyForm notifySuccess = new NotifyForm("Transaction Sent\nThis transaction could take up to 20 minutes to mine",
"Explorer", link);
notifySuccess.ShowDialog();
notifySuccess.Dispose();
this.Close();
} }
} }
} }