main: Added save signed message

This commit is contained in:
Nathan Woodburn 2023-07-15 21:06:11 +10:00
parent 4606eaf8a3
commit 5550ce472e
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
2 changed files with 35 additions and 11 deletions

View File

@ -39,10 +39,10 @@
buttonCancel = new Button(); buttonCancel = new Button();
buttonFinalize = new Button(); buttonFinalize = new Button();
groupBoxSign = new GroupBox(); groupBoxSign = new GroupBox();
textBoxSignature = new TextBox();
buttonSign = new Button(); buttonSign = new Button();
textBoxSignMessage = new TextBox(); textBoxSignMessage = new TextBox();
labelSignMessage = new Label(); labelSignMessage = new Label();
textBoxSignature = new TextBox();
groupBoxManage.SuspendLayout(); groupBoxManage.SuspendLayout();
groupBoxSign.SuspendLayout(); groupBoxSign.SuspendLayout();
SuspendLayout(); SuspendLayout();
@ -165,6 +165,15 @@
groupBoxSign.TabStop = false; groupBoxSign.TabStop = false;
groupBoxSign.Text = "Sign"; groupBoxSign.Text = "Sign";
// //
// textBoxSignature
//
textBoxSignature.Location = new Point(484, 56);
textBoxSignature.Multiline = true;
textBoxSignature.Name = "textBoxSignature";
textBoxSignature.ReadOnly = true;
textBoxSignature.Size = new Size(260, 156);
textBoxSignature.TabIndex = 3;
//
// buttonSign // buttonSign
// //
buttonSign.Location = new Point(606, 218); buttonSign.Location = new Point(606, 218);
@ -182,6 +191,7 @@
textBoxSignMessage.Name = "textBoxSignMessage"; textBoxSignMessage.Name = "textBoxSignMessage";
textBoxSignMessage.Size = new Size(472, 156); textBoxSignMessage.Size = new Size(472, 156);
textBoxSignMessage.TabIndex = 1; textBoxSignMessage.TabIndex = 1;
textBoxSignMessage.TextChanged += textBoxSignMessage_TextChanged;
// //
// labelSignMessage // labelSignMessage
// //
@ -192,15 +202,6 @@
labelSignMessage.TabIndex = 0; labelSignMessage.TabIndex = 0;
labelSignMessage.Text = "Message:"; labelSignMessage.Text = "Message:";
// //
// textBoxSignature
//
textBoxSignature.Location = new Point(484, 56);
textBoxSignature.Multiline = true;
textBoxSignature.Name = "textBoxSignature";
textBoxSignature.ReadOnly = true;
textBoxSignature.Size = new Size(260, 156);
textBoxSignature.TabIndex = 3;
//
// DomainForm // DomainForm
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);

View File

@ -241,6 +241,23 @@ namespace FireWalletLite
private async void buttonSign_Click(object sender, EventArgs e) private async void buttonSign_Click(object sender, EventArgs e)
{ {
if (buttonSign.Text == "Save")
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "Text File|*.txt";
saveFileDialog.Title = "Save Signature";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
JObject signature = new JObject();
signature["domain"] = Domain;
signature["message"] = textBoxSignMessage.Text;
signature["signature"] = textBoxSignature.Text;
signature["time"] = DateTime.Now.ToString();
File.WriteAllText(saveFileDialog.FileName, signature.ToString());
}
return;
}
if (textBoxSignMessage.Text == "") if (textBoxSignMessage.Text == "")
{ {
NotifyForm notify = new NotifyForm("Enter a message to sign"); NotifyForm notify = new NotifyForm("Enter a message to sign");
@ -250,7 +267,6 @@ namespace FireWalletLite
} }
string content = "{\"method\": \"signmessagewithname\", \"params\": [\"" + Domain + "\", \"" + textBoxSignMessage.Text + "\"]}"; string content = "{\"method\": \"signmessagewithname\", \"params\": [\"" + Domain + "\", \"" + textBoxSignMessage.Text + "\"]}";
string response = await Main.APIPost("", true, content); string response = await Main.APIPost("", true, content);
Main.AddLog(response);
if (response == "Error") if (response == "Error")
{ {
NotifyForm notify = new NotifyForm("Error signing message"); NotifyForm notify = new NotifyForm("Error signing message");
@ -262,13 +278,20 @@ namespace FireWalletLite
if (jObject.ContainsKey("result")) if (jObject.ContainsKey("result"))
{ {
textBoxSignature.Text = jObject["result"].ToString(); textBoxSignature.Text = jObject["result"].ToString();
buttonSign.Text = "Save";
} }
else else
{ {
Main.AddLog(response);
NotifyForm notify = new NotifyForm("Error signing message"); NotifyForm notify = new NotifyForm("Error signing message");
notify.ShowDialog(); notify.ShowDialog();
notify.Dispose(); notify.Dispose();
} }
} }
private void textBoxSignMessage_TextChanged(object sender, EventArgs e)
{
buttonSign.Text = "Sign";
}
} }
} }