FireWallet/FireWallet/TransferForm.cs

131 lines
4.0 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
2023-06-15 13:55:51 +10:00
using DnsClient.Protocol;
using DnsClient;
using Newtonsoft.Json.Linq;
namespace FireWallet
{
public partial class TransferForm : Form
{
MainForm MainForm;
string Domain;
public TransferForm(MainForm main, string domain)
{
InitializeComponent();
MainForm = main;
Domain = domain;
this.Text = "Transfer " + Domain + " | FireWallet";
label1.Text = "Transfer " + Domain;
if (MainForm.Theme.ContainsKey("error"))
{
labelError.ForeColor = ColorTranslator.FromHtml(MainForm.Theme["error"]);
}
if (MainForm.WatchOnly)
{
buttonTransfer.Enabled = false; // watch only wallet only batch
}
// Theme
this.BackColor = ColorTranslator.FromHtml(MainForm.Theme["background"]);
this.ForeColor = ColorTranslator.FromHtml(MainForm.Theme["foreground"]);
foreach (Control c in Controls)
{
MainForm.ThemeControl(c);
}
}
private void buttonCancel_Click(object sender, EventArgs e)
{
this.Close();
}
2023-06-15 13:55:51 +10:00
string address = "";
private async void buttonTransfer_Click(object sender, EventArgs e)
{
await updateAddress();
2023-06-15 13:55:51 +10:00
if (!await MainForm.ValidAddress(address))
{
labelError.Show();
return;
}
string content = "{\"method\": \"sendtransfer\",\"params\": [ \"" + Domain + "\", \"" +
2023-06-15 13:55:51 +10:00
address + "\"]}";
string output = await MainForm.APIPost("", true, content);
JObject APIresp = JObject.Parse(output);
if (APIresp["error"].ToString() != "")
{
MainForm.AddLog("Failed:");
MainForm.AddLog(APIresp.ToString());
NotifyForm notify = new NotifyForm("Error Transaction Failed");
notify.ShowDialog();
return;
}
JObject result = JObject.Parse(APIresp["result"].ToString());
string hash = result["hash"].ToString();
string link = MainForm.UserSettings["explorer-tx"] + hash;
NotifyForm notifySuccess = new NotifyForm("Transaction Sent\nThis transaction could take up to 20 minutes to mine",
"Explorer", link);
notifySuccess.ShowDialog();
notifySuccess.Dispose();
this.Close();
}
private async void buttonBatch_Click(object sender, EventArgs e)
{
await updateAddress();
2023-06-15 13:55:51 +10:00
if (!await MainForm.ValidAddress(address))
{
labelError.Show();
return;
}
2023-06-15 13:55:51 +10:00
MainForm.AddBatch(Domain, "TRANSFER", address);
this.Close();
}
2023-06-15 13:55:51 +10:00
private async Task updateAddress()
2023-06-15 13:55:51 +10:00
{
labelError.Hide();
if (textBoxAddress.Text.Length < 1)
{
address = "";
return;
}
if (textBoxAddress.Text.Substring(0, 1) == "@")
{
string domain = textBoxAddress.Text.Substring(1);
string address = await MainForm.HIP02Lookup(domain);
if (address == "ERROR")
2023-06-15 13:55:51 +10:00
{
labelError.Show();
labelError.Text = "HIP-02 lookup failed";
} else
{
labelSendingHIPAddress.Text = address;
this.address = address;
labelSendingHIPAddress.Show();
labelHIPArrow.Show();
2023-06-15 13:55:51 +10:00
}
} else
{
address = textBoxAddress.Text;
}
}
}
}