main: Import wallets and rescan

This commit is contained in:
Nathan Woodburn 2023-06-09 11:36:54 +10:00
parent 4a4527657c
commit 0f84462a03
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
4 changed files with 164 additions and 51 deletions

View File

@ -90,6 +90,8 @@ namespace FireWallet
labelDomainSearch = new Label(); labelDomainSearch = new Label();
textBoxDomainSearch = new TextBox(); textBoxDomainSearch = new TextBox();
panelSettings = new Panel(); panelSettings = new Panel();
groupBoxSettingsWallet = new GroupBox();
buttonSettingsRescan = new Button();
buttonSeed = new Button(); buttonSeed = new Button();
groupBoxSettingsMisc = new GroupBox(); groupBoxSettingsMisc = new GroupBox();
labelSettings8 = new Label(); labelSettings8 = new Label();
@ -122,6 +124,7 @@ namespace FireWallet
panelDomains.SuspendLayout(); panelDomains.SuspendLayout();
groupBoxDomains.SuspendLayout(); groupBoxDomains.SuspendLayout();
panelSettings.SuspendLayout(); panelSettings.SuspendLayout();
groupBoxSettingsWallet.SuspendLayout();
groupBoxSettingsMisc.SuspendLayout(); groupBoxSettingsMisc.SuspendLayout();
((System.ComponentModel.ISupportInitialize)numericUpDownTXCount).BeginInit(); ((System.ComponentModel.ISupportInitialize)numericUpDownTXCount).BeginInit();
((System.ComponentModel.ISupportInitialize)numericUpDownConfirmations).BeginInit(); ((System.ComponentModel.ISupportInitialize)numericUpDownConfirmations).BeginInit();
@ -400,7 +403,7 @@ namespace FireWallet
groupBoxinfo.Controls.Add(labelHeight); groupBoxinfo.Controls.Add(labelHeight);
groupBoxinfo.Location = new Point(281, 3); groupBoxinfo.Location = new Point(281, 3);
groupBoxinfo.Name = "groupBoxinfo"; groupBoxinfo.Name = "groupBoxinfo";
groupBoxinfo.Size = new Size(232, 104); groupBoxinfo.Size = new Size(250, 104);
groupBoxinfo.TabIndex = 8; groupBoxinfo.TabIndex = 8;
groupBoxinfo.TabStop = false; groupBoxinfo.TabStop = false;
groupBoxinfo.Text = "Info"; groupBoxinfo.Text = "Info";
@ -717,7 +720,7 @@ namespace FireWallet
// //
// panelSettings // panelSettings
// //
panelSettings.Controls.Add(buttonSeed); panelSettings.Controls.Add(groupBoxSettingsWallet);
panelSettings.Controls.Add(groupBoxSettingsMisc); panelSettings.Controls.Add(groupBoxSettingsMisc);
panelSettings.Controls.Add(labelSettingsSaved); panelSettings.Controls.Add(labelSettingsSaved);
panelSettings.Controls.Add(buttonSettingsSave); panelSettings.Controls.Add(buttonSettingsSave);
@ -729,12 +732,34 @@ namespace FireWallet
panelSettings.TabIndex = 19; panelSettings.TabIndex = 19;
panelSettings.Visible = false; panelSettings.Visible = false;
// //
// groupBoxSettingsWallet
//
groupBoxSettingsWallet.Controls.Add(buttonSettingsRescan);
groupBoxSettingsWallet.Controls.Add(buttonSeed);
groupBoxSettingsWallet.Location = new Point(507, 16);
groupBoxSettingsWallet.Name = "groupBoxSettingsWallet";
groupBoxSettingsWallet.Size = new Size(420, 194);
groupBoxSettingsWallet.TabIndex = 9;
groupBoxSettingsWallet.TabStop = false;
groupBoxSettingsWallet.Text = "Wallet Controls";
//
// buttonSettingsRescan
//
buttonSettingsRescan.FlatStyle = FlatStyle.Flat;
buttonSettingsRescan.Location = new Point(6, 20);
buttonSettingsRescan.Name = "buttonSettingsRescan";
buttonSettingsRescan.Size = new Size(98, 53);
buttonSettingsRescan.TabIndex = 8;
buttonSettingsRescan.Text = "Rescan";
buttonSettingsRescan.UseVisualStyleBackColor = true;
buttonSettingsRescan.Click += Rescan_Click;
//
// buttonSeed // buttonSeed
// //
buttonSeed.FlatStyle = FlatStyle.Flat; buttonSeed.FlatStyle = FlatStyle.Flat;
buttonSeed.Location = new Point(507, 7); buttonSeed.Location = new Point(297, 15);
buttonSeed.Name = "buttonSeed"; buttonSeed.Name = "buttonSeed";
buttonSeed.Size = new Size(157, 68); buttonSeed.Size = new Size(117, 53);
buttonSeed.TabIndex = 8; buttonSeed.TabIndex = 8;
buttonSeed.Text = "Seed Phrase"; buttonSeed.Text = "Seed Phrase";
buttonSeed.UseVisualStyleBackColor = true; buttonSeed.UseVisualStyleBackColor = true;
@ -951,6 +976,7 @@ namespace FireWallet
groupBoxDomains.ResumeLayout(false); groupBoxDomains.ResumeLayout(false);
panelSettings.ResumeLayout(false); panelSettings.ResumeLayout(false);
panelSettings.PerformLayout(); panelSettings.PerformLayout();
groupBoxSettingsWallet.ResumeLayout(false);
groupBoxSettingsMisc.ResumeLayout(false); groupBoxSettingsMisc.ResumeLayout(false);
groupBoxSettingsMisc.PerformLayout(); groupBoxSettingsMisc.PerformLayout();
((System.ComponentModel.ISupportInitialize)numericUpDownTXCount).EndInit(); ((System.ComponentModel.ISupportInitialize)numericUpDownTXCount).EndInit();
@ -1037,5 +1063,7 @@ namespace FireWallet
private NumericUpDown numericUpDownTXCount; private NumericUpDown numericUpDownTXCount;
private Label labelSettings7; private Label labelSettings7;
private Button buttonSeed; private Button buttonSeed;
private GroupBox groupBoxSettingsWallet;
private Button buttonSettingsRescan;
} }
} }

View File

@ -419,7 +419,7 @@ namespace FireWallet
string content = "{\"passphrase\": \"" + password + "\",\"timeout\": 60}"; string content = "{\"passphrase\": \"" + password + "\",\"timeout\": 60}";
if (password == "") if (password == "")
{ {
AddLog("No password entered"); // For some reason, the API doesn't like an empty password, so we'll just use a default one
content = "{\"passphrase\": \"password\" ,\"timeout\": 60}"; content = "{\"passphrase\": \"password\" ,\"timeout\": 60}";
} }
@ -1200,6 +1200,8 @@ namespace FireWallet
textBoxDomainSearch.Text = domainSearch; textBoxDomainSearch.Text = domainSearch;
} }
#region Settings
private void buttonSettingsSave_Click(object sender, EventArgs e) private void buttonSettingsSave_Click(object sender, EventArgs e)
{ {
StreamWriter sw = new StreamWriter(dir + "settings.txt"); StreamWriter sw = new StreamWriter(dir + "settings.txt");
@ -1214,14 +1216,10 @@ namespace FireWallet
LoadSettings(); LoadSettings();
labelSettingsSaved.Show(); labelSettingsSaved.Show();
} }
private async void buttonSeed_Click(object sender, EventArgs e) private async void buttonSeed_Click(object sender, EventArgs e)
{ {
string path = "wallet/" + account + "/master"; string path = "wallet/" + account + "/master";
string response = await APIGet(path, true); string response = await APIGet(path, true);
AddLog(response);
JObject resp = JObject.Parse(response); JObject resp = JObject.Parse(response);
if (resp["encrypted"].ToString() == "False") if (resp["encrypted"].ToString() == "False")
{ {
@ -1271,5 +1269,21 @@ namespace FireWallet
} }
} }
#endregion
private async void Rescan_Click(object sender, EventArgs e)
{
string content = "{\"height\": 0}";
string response = await APIPost("rescan", true, content);
if (!response.Contains("true"))
{
AddLog("Error starting rescan");
AddLog(response);
return;
}
AddLog("Starting rescan");
}
} }
} }

View File

@ -37,15 +37,18 @@
buttonImport = new Button(); buttonImport = new Button();
buttonNew = new Button(); buttonNew = new Button();
groupBoxNew = new GroupBox(); groupBoxNew = new GroupBox();
textBoxNewPass2 = new TextBox();
textBoxNewPass1 = new TextBox();
label4 = new Label(); label4 = new Label();
textBoxNewName = new TextBox(); textBoxNewName = new TextBox();
label5 = new Label();
label3 = new Label(); label3 = new Label();
label2 = new Label(); label2 = new Label();
textBoxNewPass1 = new TextBox(); groupBoxSeed = new GroupBox();
textBoxNewPass2 = new TextBox(); textBoxSeedPhrase = new TextBox();
label5 = new Label();
groupBoxMode.SuspendLayout(); groupBoxMode.SuspendLayout();
groupBoxNew.SuspendLayout(); groupBoxNew.SuspendLayout();
groupBoxSeed.SuspendLayout();
SuspendLayout(); SuspendLayout();
// //
// buttonNext // buttonNext
@ -157,6 +160,22 @@
groupBoxNew.Text = "New Wallet"; groupBoxNew.Text = "New Wallet";
groupBoxNew.Visible = false; groupBoxNew.Visible = false;
// //
// textBoxNewPass2
//
textBoxNewPass2.Location = new Point(128, 136);
textBoxNewPass2.Name = "textBoxNewPass2";
textBoxNewPass2.Size = new Size(316, 29);
textBoxNewPass2.TabIndex = 8;
textBoxNewPass2.UseSystemPasswordChar = true;
//
// textBoxNewPass1
//
textBoxNewPass1.Location = new Point(128, 90);
textBoxNewPass1.Name = "textBoxNewPass1";
textBoxNewPass1.Size = new Size(316, 29);
textBoxNewPass1.TabIndex = 7;
textBoxNewPass1.UseSystemPasswordChar = true;
//
// label4 // label4
// //
label4.AutoSize = true; label4.AutoSize = true;
@ -175,6 +194,15 @@
textBoxNewName.TabIndex = 5; textBoxNewName.TabIndex = 5;
textBoxNewName.TextChanged += textBoxNewName_TextChanged; textBoxNewName.TextChanged += textBoxNewName_TextChanged;
// //
// label5
//
label5.AutoSize = true;
label5.Location = new Point(38, 139);
label5.Name = "label5";
label5.Size = new Size(70, 21);
label5.TabIndex = 1;
label5.Text = "Confirm:";
//
// label3 // label3
// //
label3.AutoSize = true; label3.AutoSize = true;
@ -193,36 +221,33 @@
label2.TabIndex = 0; label2.TabIndex = 0;
label2.Text = "Name:"; label2.Text = "Name:";
// //
// textBoxNewPass1 // groupBoxSeed
// //
textBoxNewPass1.Location = new Point(128, 90); groupBoxSeed.Controls.Add(textBoxSeedPhrase);
textBoxNewPass1.Name = "textBoxNewPass1"; groupBoxSeed.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
textBoxNewPass1.Size = new Size(316, 29); groupBoxSeed.Location = new Point(125, 22);
textBoxNewPass1.TabIndex = 7; groupBoxSeed.Name = "groupBoxSeed";
textBoxNewPass1.UseSystemPasswordChar = true; groupBoxSeed.Size = new Size(450, 319);
groupBoxSeed.TabIndex = 5;
groupBoxSeed.TabStop = false;
groupBoxSeed.Text = "Seed Phrase";
groupBoxSeed.Visible = false;
// //
// textBoxNewPass2 // textBoxSeedPhrase
// //
textBoxNewPass2.Location = new Point(128, 136); textBoxSeedPhrase.Location = new Point(6, 25);
textBoxNewPass2.Name = "textBoxNewPass2"; textBoxSeedPhrase.Multiline = true;
textBoxNewPass2.Size = new Size(316, 29); textBoxSeedPhrase.Name = "textBoxSeedPhrase";
textBoxNewPass2.TabIndex = 8; textBoxSeedPhrase.PlaceholderText = "pistol air cabbage high conduct party powder inject jungle knee spell derive";
textBoxNewPass2.UseSystemPasswordChar = true; textBoxSeedPhrase.Size = new Size(438, 288);
// textBoxSeedPhrase.TabIndex = 0;
// label5
//
label5.AutoSize = true;
label5.Location = new Point(38, 139);
label5.Name = "label5";
label5.Size = new Size(70, 21);
label5.TabIndex = 1;
label5.Text = "Confirm:";
// //
// NewAccountForm // NewAccountForm
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(680, 430); ClientSize = new Size(680, 430);
Controls.Add(groupBoxSeed);
Controls.Add(buttonCancel); Controls.Add(buttonCancel);
Controls.Add(buttonNext); Controls.Add(buttonNext);
Controls.Add(groupBoxNew); Controls.Add(groupBoxNew);
@ -237,6 +262,8 @@
groupBoxMode.PerformLayout(); groupBoxMode.PerformLayout();
groupBoxNew.ResumeLayout(false); groupBoxNew.ResumeLayout(false);
groupBoxNew.PerformLayout(); groupBoxNew.PerformLayout();
groupBoxSeed.ResumeLayout(false);
groupBoxSeed.PerformLayout();
ResumeLayout(false); ResumeLayout(false);
} }
@ -257,5 +284,7 @@
private TextBox textBoxNewPass2; private TextBox textBoxNewPass2;
private TextBox textBoxNewPass1; private TextBox textBoxNewPass1;
private Label label5; private Label label5;
private GroupBox groupBoxSeed;
private TextBox textBoxSeedPhrase;
} }
} }

View File

@ -52,7 +52,11 @@ namespace FireWallet
private void buttonImport_Click(object sender, EventArgs e) private void buttonImport_Click(object sender, EventArgs e)
{ {
// TODO - Import wallet page = 2;
groupBoxNew.Show();
buttonNext.Show();
buttonNext.Enabled = false;
groupBoxNew.Text = "Import Wallet";
} }
private void buttonCold_Click(object sender, EventArgs e) private void buttonCold_Click(object sender, EventArgs e)
@ -76,23 +80,31 @@ namespace FireWallet
private async void buttonNext_Click(object sender, EventArgs e) private async void buttonNext_Click(object sender, EventArgs e)
{ {
if (textBoxNewPass1 == null)
{
NotifyForm notify = new NotifyForm("Please enter a password");
notify.ShowDialog();
notify.Dispose();
return;
}
if (textBoxNewPass1.Text.Length < 8)
{
NotifyForm notify = new NotifyForm("Password must be at least 8 characters");
notify.ShowDialog();
notify.Dispose();
return;
}
if (textBoxNewPass1.Text != textBoxNewPass2.Text)
{
NotifyForm notify = new NotifyForm("Passwords do not match");
notify.ShowDialog();
notify.Dispose();
return;
}
if (page == 1) if (page == 1)
{ {
if (textBoxNewPass1 == null)
{
NotifyForm notify = new NotifyForm("Please enter a password");
notify.ShowDialog();
notify.Dispose();
return;
}
if (textBoxNewPass1.Text != textBoxNewPass2.Text)
{
NotifyForm notify = new NotifyForm("Passwords do not match");
notify.ShowDialog();
notify.Dispose();
return;
}
// Create new wallet // Create new wallet
buttonNext.Enabled = false; buttonNext.Enabled = false;
string path = "wallet/" + textBoxNewName.Text; string path = "wallet/" + textBoxNewName.Text;
@ -107,8 +119,38 @@ namespace FireWallet
return; return;
} }
mainForm.AddLog("Created wallet: " + textBoxNewName.Text); mainForm.AddLog("Created wallet: " + textBoxNewName.Text);
NotifyForm notify2 = new NotifyForm("Created wallet: " + textBoxNewName.Text);
notify2.ShowDialog();
notify2.Dispose();
this.Close();
}
else if (page == 2)
{
groupBoxSeed.Show();
buttonNext.Text = "Import";
page = 3;
}
else if (page == 3)
{
// Create new wallet
buttonNext.Enabled = false;
string path = "wallet/" + textBoxNewName.Text;
string content = "{\"passphrase\":\"" + textBoxNewPass1.Text + "\",\"mnemonic\":\"" + textBoxSeedPhrase.Text +"\"}";
string response = await APIPut(path, true, content);
if (response == "Error")
{
NotifyForm notify = new NotifyForm("Error creating wallet");
notify.ShowDialog();
notify.Dispose();
buttonNext.Enabled = true;
return;
}
mainForm.AddLog("Created wallet: " + textBoxNewName.Text);
NotifyForm notify2 = new NotifyForm("Imported wallet: " + textBoxNewName.Text);
notify2.ShowDialog();
notify2.Dispose();
this.Close();
} }
} }