main: Added redeem and send all

This commit is contained in:
Nathan Woodburn 2023-06-21 21:31:46 +10:00
parent a4a35ad62e
commit d41c72faff
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
2 changed files with 135 additions and 12 deletions

View File

@ -65,6 +65,7 @@ namespace FireWallet
buttonNavSend = new Button();
buttonNavPortfolio = new Button();
panelPortfolio = new Panel();
buttonRedeemAll = new Button();
buttonRevealAll = new Button();
groupBoxTransactions = new GroupBox();
groupBoxinfo = new GroupBox();
@ -126,6 +127,7 @@ namespace FireWallet
textBoxExAddr = new TextBox();
labelSettings4 = new Label();
textBoxExTX = new TextBox();
buttonSendAll = new Button();
statusStripmain.SuspendLayout();
panelaccount.SuspendLayout();
groupBoxaccount.SuspendLayout();
@ -445,6 +447,8 @@ namespace FireWallet
//
// panelPortfolio
//
panelPortfolio.Controls.Add(buttonSendAll);
panelPortfolio.Controls.Add(buttonRedeemAll);
panelPortfolio.Controls.Add(buttonRevealAll);
panelPortfolio.Controls.Add(groupBoxTransactions);
panelPortfolio.Controls.Add(groupBoxinfo);
@ -455,13 +459,25 @@ namespace FireWallet
panelPortfolio.TabIndex = 7;
panelPortfolio.Visible = false;
//
// buttonRedeemAll
//
buttonRedeemAll.FlatStyle = FlatStyle.Flat;
buttonRedeemAll.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
buttonRedeemAll.Location = new Point(649, 12);
buttonRedeemAll.Name = "buttonRedeemAll";
buttonRedeemAll.Size = new Size(106, 44);
buttonRedeemAll.TabIndex = 9;
buttonRedeemAll.Text = "Redeem All";
buttonRedeemAll.UseVisualStyleBackColor = true;
buttonRedeemAll.Click += buttonRedeemAll_Click;
//
// buttonRevealAll
//
buttonRevealAll.FlatStyle = FlatStyle.Flat;
buttonRevealAll.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
buttonRevealAll.Location = new Point(537, 12);
buttonRevealAll.Name = "buttonRevealAll";
buttonRevealAll.Size = new Size(89, 44);
buttonRevealAll.Size = new Size(106, 44);
buttonRevealAll.TabIndex = 9;
buttonRevealAll.Text = "Reveal All";
buttonRevealAll.UseVisualStyleBackColor = true;
@ -1105,6 +1121,18 @@ namespace FireWallet
textBoxExTX.Size = new Size(307, 29);
textBoxExTX.TabIndex = 1;
//
// buttonSendAll
//
buttonSendAll.FlatStyle = FlatStyle.Flat;
buttonSendAll.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
buttonSendAll.Location = new Point(761, 12);
buttonSendAll.Name = "buttonSendAll";
buttonSendAll.Size = new Size(106, 44);
buttonSendAll.TabIndex = 9;
buttonSendAll.Text = "Send All TXs";
buttonSendAll.UseVisualStyleBackColor = true;
buttonSendAll.Click += buttonSendAll_Click;
//
// MainForm
//
AutoScaleDimensions = new SizeF(7F, 15F);
@ -1251,5 +1279,7 @@ namespace FireWallet
private Label labelDomainSort;
private ToolStripSeparator toolStripSeparator1;
private ToolStripMenuItem otherProjectsToolStripMenuItem;
private Button buttonRedeemAll;
private Button buttonSendAll;
}
}

View File

@ -153,7 +153,6 @@ namespace FireWallet
// Pull form to front
this.WindowState = FormWindowState.Minimized;
this.Show();
this.Opacity = 1;
@ -928,21 +927,25 @@ namespace FireWallet
req.Content = new StringContent(content);
// Send request
HttpResponseMessage resp = await httpClient.SendAsync(req);
try
{
resp.EnsureSuccessStatusCode();
HttpResponseMessage resp = await httpClient.SendAsync(req);
if (!resp.IsSuccessStatusCode)
{
AddLog("Post Error: " + resp.StatusCode);
AddLog(await resp.Content.ReadAsStringAsync());
return "Error";
}
return await resp.Content.ReadAsStringAsync();
}
catch (Exception ex)
{
AddLog("Post Error: " + ex.Message);
AddLog(await resp.Content.ReadAsStringAsync());
AddLog("Content: " + content);
return "Error";
}
return await resp.Content.ReadAsStringAsync();
}
/// <summary>
/// Get from HSD API
@ -972,7 +975,12 @@ namespace FireWallet
request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes("x:" + key)));
// Send request and log response
HttpResponseMessage response = await httpClient.SendAsync(request);
response.EnsureSuccessStatusCode();
if (!response.IsSuccessStatusCode)
{
AddLog("Get Error: " + response.StatusCode);
AddLog(await response.Content.ReadAsStringAsync());
return "Error";
}
return await response.Content.ReadAsStringAsync();
}
@ -993,9 +1001,16 @@ namespace FireWallet
AddLog("GetAddress Error");
return "Error";
}
try
{
JObject resp = JObject.Parse(APIresponse);
return resp["address"].ToString();
}
catch
{
return "Error";
}
}
private async void GetTXHistory()
{
@ -2361,5 +2376,83 @@ namespace FireWallet
Process.Start(psi);
}
#endregion
private async void buttonRedeemAll_Click(object sender, EventArgs e)
{
buttonRedeemAll.Enabled = false;
string content = "{\"method\": \"sendbatch\", \"params\":[[[\"REDEEM\"]]]}";
AddLog(content);
string response = await APIPost("", true, content);
if (response == "Error")
{
AddLog("Error sending batch");
NotifyForm notifyForm = new NotifyForm("Error sending batch");
notifyForm.ShowDialog();
notifyForm.Dispose();
buttonRedeemAll.Enabled = true;
return;
}
JObject resp = JObject.Parse(response);
if (resp["error"].ToString() != "")
{
AddLog("Error sending batch");
AddLog(resp["error"].ToString());
JObject error = JObject.Parse(resp["error"].ToString());
NotifyForm notifyForm = new NotifyForm("Error sending batch\n" + error["message"].ToString());
notifyForm.ShowDialog();
notifyForm.Dispose();
buttonRedeemAll.Enabled = true;
return;
}
if (resp.ContainsKey("result"))
{
JObject result = JObject.Parse(resp["result"].ToString());
string hash = result["hash"].ToString();
NotifyForm notifyForm = new NotifyForm("Batch sent\n" + hash, "Explorer", UserSettings["explorer-tx"] + hash);
notifyForm.ShowDialog();
notifyForm.Dispose();
}
buttonRedeemAll.Enabled = true;
}
private async void buttonSendAll_Click(object sender, EventArgs e)
{
buttonSendAll.Enabled = false;
string content = "{\"method\": \"sendbatch\", \"params\":[[[\"REVEAL\"],[\"REDEEM\"],[\"RENEW\"]]]}";
AddLog(content);
string response = await APIPost("", true, content);
if (response == "Error")
{
AddLog("Error sending batch");
NotifyForm notifyForm = new NotifyForm("Error sending batch");
notifyForm.ShowDialog();
notifyForm.Dispose();
buttonSendAll.Enabled = true;
return;
}
JObject resp = JObject.Parse(response);
if (resp["error"].ToString() != "")
{
AddLog("Error sending batch");
AddLog(resp["error"].ToString());
JObject error = JObject.Parse(resp["error"].ToString());
NotifyForm notifyForm = new NotifyForm("Error sending batch\n" + error["message"].ToString());
notifyForm.ShowDialog();
notifyForm.Dispose();
buttonSendAll.Enabled = true;
return;
}
if (resp.ContainsKey("result"))
{
JObject result = JObject.Parse(resp["result"].ToString());
string hash = result["hash"].ToString();
NotifyForm notifyForm = new NotifyForm("Batch sent\n" + hash, "Explorer", UserSettings["explorer-tx"] + hash);
notifyForm.ShowDialog();
notifyForm.Dispose();
}
buttonSendAll.Enabled = true;
}
}
}