main: Added domain transfer, renew, cancel and finalize

This commit is contained in:
Nathan Woodburn 2023-07-07 15:10:48 +10:00
parent fba5833c37
commit 566ba28c80
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
4 changed files with 249 additions and 38 deletions

View File

@ -33,9 +33,12 @@
labelInfo = new Label();
labelName = new Label();
buttonExplorer = new Button();
button1 = new Button();
button2 = new Button();
buttonRenew = new Button();
buttonTransfer = new Button();
groupBoxManage = new GroupBox();
textBoxTransferAddress = new TextBox();
buttonCancel = new Button();
buttonFinalize = new Button();
groupBoxInfo.SuspendLayout();
groupBoxManage.SuspendLayout();
SuspendLayout();
@ -82,32 +85,37 @@
buttonExplorer.UseVisualStyleBackColor = true;
buttonExplorer.Click += buttonExplorer_Click;
//
// button1
// buttonRenew
//
button1.FlatStyle = FlatStyle.Flat;
button1.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
button1.Location = new Point(6, 31);
button1.Name = "button1";
button1.Size = new Size(89, 30);
button1.TabIndex = 1;
button1.Text = "Explorer";
button1.UseVisualStyleBackColor = true;
buttonRenew.FlatStyle = FlatStyle.Flat;
buttonRenew.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
buttonRenew.Location = new Point(6, 31);
buttonRenew.Name = "buttonRenew";
buttonRenew.Size = new Size(89, 30);
buttonRenew.TabIndex = 1;
buttonRenew.Text = "Renew";
buttonRenew.UseVisualStyleBackColor = true;
buttonRenew.Click += buttonRenew_Click;
//
// button2
// buttonTransfer
//
button2.FlatStyle = FlatStyle.Flat;
button2.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
button2.Location = new Point(6, 67);
button2.Name = "button2";
button2.Size = new Size(89, 30);
button2.TabIndex = 1;
button2.Text = "Explorer";
button2.UseVisualStyleBackColor = true;
buttonTransfer.FlatStyle = FlatStyle.Flat;
buttonTransfer.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
buttonTransfer.Location = new Point(375, 67);
buttonTransfer.Name = "buttonTransfer";
buttonTransfer.Size = new Size(89, 30);
buttonTransfer.TabIndex = 1;
buttonTransfer.Text = "Transfer";
buttonTransfer.UseVisualStyleBackColor = true;
buttonTransfer.Click += buttonTransfer_Click;
//
// groupBoxManage
//
groupBoxManage.Controls.Add(button1);
groupBoxManage.Controls.Add(button2);
groupBoxManage.Controls.Add(textBoxTransferAddress);
groupBoxManage.Controls.Add(buttonRenew);
groupBoxManage.Controls.Add(buttonCancel);
groupBoxManage.Controls.Add(buttonFinalize);
groupBoxManage.Controls.Add(buttonTransfer);
groupBoxManage.Font = new Font("Segoe UI", 14F, FontStyle.Regular, GraphicsUnit.Point);
groupBoxManage.Location = new Point(298, 52);
groupBoxManage.Name = "groupBoxManage";
@ -116,6 +124,39 @@
groupBoxManage.TabStop = false;
groupBoxManage.Text = "Manage";
//
// textBoxTransferAddress
//
textBoxTransferAddress.Location = new Point(6, 66);
textBoxTransferAddress.Name = "textBoxTransferAddress";
textBoxTransferAddress.Size = new Size(363, 32);
textBoxTransferAddress.TabIndex = 2;
//
// buttonCancel
//
buttonCancel.FlatStyle = FlatStyle.Flat;
buttonCancel.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
buttonCancel.Location = new Point(6, 67);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(89, 30);
buttonCancel.TabIndex = 1;
buttonCancel.Text = "Cancel";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Visible = false;
buttonCancel.Click += buttonCancel_Click;
//
// buttonFinalize
//
buttonFinalize.FlatStyle = FlatStyle.Flat;
buttonFinalize.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
buttonFinalize.Location = new Point(6, 67);
buttonFinalize.Name = "buttonFinalize";
buttonFinalize.Size = new Size(89, 30);
buttonFinalize.TabIndex = 1;
buttonFinalize.Text = "Finalize";
buttonFinalize.UseVisualStyleBackColor = true;
buttonFinalize.Visible = false;
buttonFinalize.Click += buttonFinalize_Click;
//
// DomainForm
//
AutoScaleDimensions = new SizeF(7F, 15F);
@ -136,6 +177,7 @@
groupBoxInfo.ResumeLayout(false);
groupBoxInfo.PerformLayout();
groupBoxManage.ResumeLayout(false);
groupBoxManage.PerformLayout();
ResumeLayout(false);
PerformLayout();
}
@ -146,8 +188,11 @@
private Label labelName;
private Button buttonExplorer;
private Label labelInfo;
private Button button1;
private Button button2;
private Button buttonRenew;
private Button buttonTransfer;
private GroupBox groupBoxManage;
private TextBox textBoxTransferAddress;
private Button buttonFinalize;
private Button buttonCancel;
}
}

View File

@ -8,6 +8,8 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DnsClient;
using FireWallet;
using Newtonsoft.Json.Linq;
namespace FireWalletLite
@ -76,6 +78,18 @@ namespace FireWalletLite
if (info["transfer"].ToString() != "0")
{
labelInfo.Text += "Transferring\n";
int TransferEnd = Convert.ToInt32(stats["transferLockupEnd"].ToString());
textBoxTransferAddress.Hide();
buttonTransfer.Hide();
if (height >= TransferEnd)
{
buttonFinalize.Show();
}
else
{
labelInfo.Text += "Finalize in " + (TransferEnd - height).ToString() + " blocks\n";
buttonCancel.Show();
}
}
if (state == "CLOSED")
@ -120,7 +134,172 @@ namespace FireWalletLite
GetName();
}
private async void buttonRenew_Click(object sender, EventArgs e)
{
string content = "{\"method\": \"renew\", \"params\": [\"" + domain + "\"]}";
string response = await main.APIPost("", true, content);
if (response == "Error")
{
NotifyForm notify = new NotifyForm("Error renewing domain");
notify.ShowDialog();
notify.Dispose();
return;
}
JObject jObject = JObject.Parse(response);
if (jObject.ContainsKey("result"))
{
main.AddLog(jObject["result"].ToString());
JObject result = (JObject)jObject["result"];
if (result.ContainsKey("txid"))
{
string txid = result["txid"].ToString();
NotifyForm notify = new NotifyForm("Renewed domain", "Explorer", main.TXExplorer + txid);
notify.ShowDialog();
notify.Dispose();
}
else
{
NotifyForm notify = new NotifyForm("Error renewing domain");
notify.ShowDialog();
notify.Dispose();
}
}
else
{
NotifyForm notify = new NotifyForm("Error renewing domain");
notify.ShowDialog();
notify.Dispose();
main.AddLog(jObject.ToString());
}
}
private async void buttonTransfer_Click(object sender, EventArgs e)
{
string address = textBoxTransferAddress.Text;
bool valid = await main.ValidAddress(address);
if (!valid)
{
NotifyForm notify = new NotifyForm("Invalid address");
notify.ShowDialog();
notify.Dispose();
return;
}
string content = "{\"method\": \"transfer\", \"params\": [\"" + domain + "\", \"" + address + "\"]}";
string response = await main.APIPost("", true, content);
if (response == "Error")
{
NotifyForm notify = new NotifyForm("Error transferring domain");
notify.ShowDialog();
notify.Dispose();
return;
}
JObject jObject = JObject.Parse(response);
if (jObject.ContainsKey("result"))
{
main.AddLog(jObject["result"].ToString());
JObject result = (JObject)jObject["result"];
if (result.ContainsKey("txid"))
{
string txid = result["txid"].ToString();
NotifyForm notify = new NotifyForm("Renewed domain", "Explorer", main.TXExplorer + txid);
notify.ShowDialog();
notify.Dispose();
}
else
{
NotifyForm notify = new NotifyForm("Error renewing domain");
notify.ShowDialog();
notify.Dispose();
}
}
else
{
NotifyForm notify = new NotifyForm("Error renewing domain");
notify.ShowDialog();
notify.Dispose();
main.AddLog(jObject.ToString());
}
}
private void buttonFinalize_Click(object sender, EventArgs e)
{
string content = "{\"method\": \"finalize\", \"params\": [\"" + domain + "\"]}";
string response = main.APIPost("", true, content).Result;
if (response == "Error")
{
NotifyForm notify = new NotifyForm("Error finalizing tranfer");
notify.ShowDialog();
notify.Dispose();
return;
}
JObject jObject = JObject.Parse(response);
if (jObject.ContainsKey("result"))
{
main.AddLog(jObject["result"].ToString());
JObject result = (JObject)jObject["result"];
if (result.ContainsKey("txid"))
{
string txid = result["txid"].ToString();
NotifyForm notify = new NotifyForm("Finalized tranfer", "Explorer", main.TXExplorer + txid);
notify.ShowDialog();
notify.Dispose();
}
else
{
NotifyForm notify = new NotifyForm("Error finalizing tranfer");
notify.ShowDialog();
notify.Dispose();
}
}
else
{
NotifyForm notify = new NotifyForm("Error finalizing tranfer");
notify.ShowDialog();
notify.Dispose();
main.AddLog(jObject.ToString());
}
}
private void buttonCancel_Click(object sender, EventArgs e)
{
string content = "{\"method\": \"cancel\", \"params\": [\"" + domain + "\"]}";
string response = main.APIPost("", true, content).Result;
if (response == "Error")
{
NotifyForm notify = new NotifyForm("Error cancelling tranfer");
notify.ShowDialog();
notify.Dispose();
return;
}
JObject jObject = JObject.Parse(response);
if (jObject.ContainsKey("result"))
{
main.AddLog(jObject["result"].ToString());
JObject result = (JObject)jObject["result"];
if (result.ContainsKey("txid"))
{
string txid = result["txid"].ToString();
NotifyForm notify = new NotifyForm("Cancelled tranfer", "Explorer", main.TXExplorer + txid);
notify.ShowDialog();
notify.Dispose();
}
else
{
NotifyForm notify = new NotifyForm("Error cancelling tranfer");
notify.ShowDialog();
notify.Dispose();
}
}
else
{
NotifyForm notify = new NotifyForm("Error cancelling tranfer");
notify.ShowDialog();
notify.Dispose();
main.AddLog(jObject.ToString());
}
}
/*
// Get DNS records for domain. Not implemented yet
private async void GetDNS()
{
// Get DNS records

View File

@ -49,7 +49,6 @@
groupBoxAccount = new GroupBox();
labelDomains = new Label();
labelBalance = new Label();
button1 = new Button();
statusStripMain.SuspendLayout();
panelLogin.SuspendLayout();
groupBoxLogin.SuspendLayout();
@ -148,7 +147,6 @@
//
// panelPortfolio
//
panelPortfolio.Controls.Add(button1);
panelPortfolio.Controls.Add(buttonRenew);
panelPortfolio.Controls.Add(groupBoxDomains);
panelPortfolio.Controls.Add(panelNav);
@ -257,16 +255,6 @@
labelBalance.TabIndex = 0;
labelBalance.Text = "labelBal";
//
// button1
//
button1.Location = new Point(197, 212);
button1.Name = "button1";
button1.Size = new Size(75, 23);
button1.TabIndex = 4;
button1.Text = "buttonTest";
button1.UseVisualStyleBackColor = true;
button1.Click += button1_Click;
//
// MainForm
//
AutoScaleDimensions = new SizeF(7F, 15F);
@ -317,6 +305,5 @@
private Panel panelDomainList;
private Button buttonRenew;
private Button buttonSend;
private Button button1;
}
}