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(); labelInfo = new Label();
labelName = new Label(); labelName = new Label();
buttonExplorer = new Button(); buttonExplorer = new Button();
button1 = new Button(); buttonRenew = new Button();
button2 = new Button(); buttonTransfer = new Button();
groupBoxManage = new GroupBox(); groupBoxManage = new GroupBox();
textBoxTransferAddress = new TextBox();
buttonCancel = new Button();
buttonFinalize = new Button();
groupBoxInfo.SuspendLayout(); groupBoxInfo.SuspendLayout();
groupBoxManage.SuspendLayout(); groupBoxManage.SuspendLayout();
SuspendLayout(); SuspendLayout();
@ -82,32 +85,37 @@
buttonExplorer.UseVisualStyleBackColor = true; buttonExplorer.UseVisualStyleBackColor = true;
buttonExplorer.Click += buttonExplorer_Click; buttonExplorer.Click += buttonExplorer_Click;
// //
// button1 // buttonRenew
// //
button1.FlatStyle = FlatStyle.Flat; buttonRenew.FlatStyle = FlatStyle.Flat;
button1.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point); buttonRenew.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
button1.Location = new Point(6, 31); buttonRenew.Location = new Point(6, 31);
button1.Name = "button1"; buttonRenew.Name = "buttonRenew";
button1.Size = new Size(89, 30); buttonRenew.Size = new Size(89, 30);
button1.TabIndex = 1; buttonRenew.TabIndex = 1;
button1.Text = "Explorer"; buttonRenew.Text = "Renew";
button1.UseVisualStyleBackColor = true; buttonRenew.UseVisualStyleBackColor = true;
buttonRenew.Click += buttonRenew_Click;
// //
// button2 // buttonTransfer
// //
button2.FlatStyle = FlatStyle.Flat; buttonTransfer.FlatStyle = FlatStyle.Flat;
button2.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point); buttonTransfer.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
button2.Location = new Point(6, 67); buttonTransfer.Location = new Point(375, 67);
button2.Name = "button2"; buttonTransfer.Name = "buttonTransfer";
button2.Size = new Size(89, 30); buttonTransfer.Size = new Size(89, 30);
button2.TabIndex = 1; buttonTransfer.TabIndex = 1;
button2.Text = "Explorer"; buttonTransfer.Text = "Transfer";
button2.UseVisualStyleBackColor = true; buttonTransfer.UseVisualStyleBackColor = true;
buttonTransfer.Click += buttonTransfer_Click;
// //
// groupBoxManage // groupBoxManage
// //
groupBoxManage.Controls.Add(button1); groupBoxManage.Controls.Add(textBoxTransferAddress);
groupBoxManage.Controls.Add(button2); 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.Font = new Font("Segoe UI", 14F, FontStyle.Regular, GraphicsUnit.Point);
groupBoxManage.Location = new Point(298, 52); groupBoxManage.Location = new Point(298, 52);
groupBoxManage.Name = "groupBoxManage"; groupBoxManage.Name = "groupBoxManage";
@ -116,6 +124,39 @@
groupBoxManage.TabStop = false; groupBoxManage.TabStop = false;
groupBoxManage.Text = "Manage"; 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 // DomainForm
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
@ -136,6 +177,7 @@
groupBoxInfo.ResumeLayout(false); groupBoxInfo.ResumeLayout(false);
groupBoxInfo.PerformLayout(); groupBoxInfo.PerformLayout();
groupBoxManage.ResumeLayout(false); groupBoxManage.ResumeLayout(false);
groupBoxManage.PerformLayout();
ResumeLayout(false); ResumeLayout(false);
PerformLayout(); PerformLayout();
} }
@ -146,8 +188,11 @@
private Label labelName; private Label labelName;
private Button buttonExplorer; private Button buttonExplorer;
private Label labelInfo; private Label labelInfo;
private Button button1; private Button buttonRenew;
private Button button2; private Button buttonTransfer;
private GroupBox groupBoxManage; 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.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using DnsClient;
using FireWallet;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
namespace FireWalletLite namespace FireWalletLite
@ -76,6 +78,18 @@ namespace FireWalletLite
if (info["transfer"].ToString() != "0") if (info["transfer"].ToString() != "0")
{ {
labelInfo.Text += "Transferring\n"; 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") if (state == "CLOSED")
@ -120,7 +134,172 @@ namespace FireWalletLite
GetName(); 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() private async void GetDNS()
{ {
// Get DNS records // Get DNS records

View File

@ -49,7 +49,6 @@
groupBoxAccount = new GroupBox(); groupBoxAccount = new GroupBox();
labelDomains = new Label(); labelDomains = new Label();
labelBalance = new Label(); labelBalance = new Label();
button1 = new Button();
statusStripMain.SuspendLayout(); statusStripMain.SuspendLayout();
panelLogin.SuspendLayout(); panelLogin.SuspendLayout();
groupBoxLogin.SuspendLayout(); groupBoxLogin.SuspendLayout();
@ -148,7 +147,6 @@
// //
// panelPortfolio // panelPortfolio
// //
panelPortfolio.Controls.Add(button1);
panelPortfolio.Controls.Add(buttonRenew); panelPortfolio.Controls.Add(buttonRenew);
panelPortfolio.Controls.Add(groupBoxDomains); panelPortfolio.Controls.Add(groupBoxDomains);
panelPortfolio.Controls.Add(panelNav); panelPortfolio.Controls.Add(panelNav);
@ -257,16 +255,6 @@
labelBalance.TabIndex = 0; labelBalance.TabIndex = 0;
labelBalance.Text = "labelBal"; 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 // MainForm
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
@ -317,6 +305,5 @@
private Panel panelDomainList; private Panel panelDomainList;
private Button buttonRenew; private Button buttonRenew;
private Button buttonSend; private Button buttonSend;
private Button button1;
} }
} }

View File

@ -540,7 +540,7 @@ namespace FireWalletLite
private void button1_Click(object sender, EventArgs e) private void button1_Click(object sender, EventArgs e)
{ {
DomainForm domainForm = new DomainForm(this,"woodburn"); DomainForm domainForm = new DomainForm(this, "woodburn");
domainForm.ShowDialog(); domainForm.ShowDialog();
domainForm.Dispose(); domainForm.Dispose();
} }