mirror of
https://github.com/Nathanwoodburn/FireWallet.git
synced 2024-11-24 08:08:14 +11:00
main: Only get the number of TXs needed
This should speed up the loading on larger wallets
This commit is contained in:
parent
f44aac35f0
commit
1675ac48f3
@ -92,6 +92,10 @@ namespace FireWallet
|
|||||||
AddLog("Loaded");
|
AddLog("Loaded");
|
||||||
Opacity = 1;
|
Opacity = 1;
|
||||||
batchMode = false;
|
batchMode = false;
|
||||||
|
// Pull form to front
|
||||||
|
this.BringToFront();
|
||||||
|
this.Focus();
|
||||||
|
|
||||||
textBoxaccountpassword.Focus();
|
textBoxaccountpassword.Focus();
|
||||||
}
|
}
|
||||||
private void MainForm_Closing(object sender, FormClosingEventArgs e)
|
private void MainForm_Closing(object sender, FormClosingEventArgs e)
|
||||||
@ -770,6 +774,7 @@ namespace FireWallet
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
AddLog("Post Error: " + ex.Message);
|
AddLog("Post Error: " + ex.Message);
|
||||||
|
AddLog(await resp.Content.ReadAsStringAsync());
|
||||||
AddLog("Content: " + content);
|
AddLog("Content: " + content);
|
||||||
return "Error";
|
return "Error";
|
||||||
}
|
}
|
||||||
@ -839,6 +844,7 @@ namespace FireWallet
|
|||||||
decimal progress = Convert.ToDecimal(chain["progress"].ToString());
|
decimal progress = Convert.ToDecimal(chain["progress"].ToString());
|
||||||
labelSyncPercent.Text = "Sync: " + decimal.Round(progress * 100, 2) + "%";
|
labelSyncPercent.Text = "Sync: " + decimal.Round(progress * 100, 2) + "%";
|
||||||
|
|
||||||
|
|
||||||
// Exit if set to 0 TXs
|
// Exit if set to 0 TXs
|
||||||
if (userSettings.ContainsKey("portfolio-tx"))
|
if (userSettings.ContainsKey("portfolio-tx"))
|
||||||
{
|
{
|
||||||
@ -858,28 +864,57 @@ namespace FireWallet
|
|||||||
labelPendingCount.Text = "Unconfirmed TX: " + pendingTxs.Count.ToString();
|
labelPendingCount.Text = "Unconfirmed TX: " + pendingTxs.Count.ToString();
|
||||||
|
|
||||||
|
|
||||||
// Get TX's
|
// Check how many TX there are
|
||||||
APIresponse = await APIGet("wallet/" + account + "/tx/history", true);
|
APIresponse = await APIGet("wallet/"+ account,true);
|
||||||
|
JObject wallet = JObject.Parse(APIresponse);
|
||||||
|
if (!wallet.ContainsKey("balance"))
|
||||||
|
{
|
||||||
|
AddLog("GetInfo Error");
|
||||||
|
AddLog(APIresponse);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
JObject balance = JObject.Parse(wallet["balance"].ToString());
|
||||||
|
int TotalTX = Convert.ToInt32(balance["tx"].ToString());
|
||||||
|
int toGet = 10;
|
||||||
|
if (userSettings.ContainsKey("portfolio-tx")) toGet = Convert.ToInt32(userSettings["portfolio-tx"]);
|
||||||
|
|
||||||
|
if (toGet > TotalTX) toGet = TotalTX;
|
||||||
|
int toSkip = TotalTX - toGet;
|
||||||
|
|
||||||
|
// GET TXs
|
||||||
|
APIresponse = await APIPost("", true, "{\"method\": \"listtransactions\",\"params\": [\"default\"," +toGet+","+ toSkip+ "]}");
|
||||||
|
|
||||||
if (APIresponse == "Error")
|
if (APIresponse == "Error")
|
||||||
{
|
{
|
||||||
AddLog("GetInfo Error");
|
AddLog("GetInfo Error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
JArray txs = JArray.Parse(APIresponse);
|
JObject TXGET = JObject.Parse(APIresponse);
|
||||||
int txCount = txs.Count;
|
|
||||||
if (txCount > groupBoxTransactions.Height / 55) txCount = (int)Math.Floor(groupBoxTransactions.Height / 55.0);
|
// Check for error
|
||||||
if (userSettings.ContainsKey("portfolio-tx")) txCount = Convert.ToInt32(userSettings["portfolio-tx"]);
|
if (TXGET["error"].ToString() != "")
|
||||||
if (txCount > txs.Count) txCount = txs.Count;
|
{
|
||||||
Control[] tmpControls = new Control[txCount];
|
AddLog("GetInfo Error");
|
||||||
for (int i = 0; i < txCount; i++)
|
AddLog(APIresponse);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
JArray txs = JArray.Parse(TXGET["result"].ToString());
|
||||||
|
Control[] tmpControls = new Control[toGet];
|
||||||
|
for (int i = 0; i < toGet; i++)
|
||||||
{
|
{
|
||||||
|
|
||||||
// Get last tx
|
// Get last tx
|
||||||
JObject tx = JObject.Parse(txs[txs.Count - 1 - i].ToString());
|
JObject tx = JObject.Parse(await APIGet("wallet/" + account + "/tx/" + txs[toGet - i - 1]["txid"].ToString(), true));
|
||||||
|
|
||||||
string hash = tx["hash"].ToString();
|
string hash = tx["hash"].ToString();
|
||||||
string date = tx["mdate"].ToString();
|
string date = tx["mdate"].ToString();
|
||||||
|
|
||||||
|
date = DateTime.Parse(date).ToShortDateString();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Panel tmpPanel = new Panel();
|
Panel tmpPanel = new Panel();
|
||||||
tmpPanel.Width = groupBoxTransactions.Width - SystemInformation.VerticalScrollBarWidth - 20;
|
tmpPanel.Width = groupBoxTransactions.Width - SystemInformation.VerticalScrollBarWidth - 20;
|
||||||
tmpPanel.Height = 50;
|
tmpPanel.Height = 50;
|
||||||
@ -917,29 +952,45 @@ namespace FireWallet
|
|||||||
|
|
||||||
tmpPanel.Controls.Add(labelHash);
|
tmpPanel.Controls.Add(labelHash);
|
||||||
|
|
||||||
// Count inputs and outputs
|
|
||||||
JArray inputs = JArray.Parse(tx["inputs"].ToString());
|
JArray inputs = JArray.Parse(tx["inputs"].ToString());
|
||||||
JArray outputs = JArray.Parse(tx["outputs"].ToString());
|
JArray outputs = JArray.Parse(tx["outputs"].ToString());
|
||||||
int inputCount = inputs.Count;
|
int inputCount = inputs.Count;
|
||||||
int outputCount = outputs.Count;
|
int outputCount = outputs.Count;
|
||||||
|
|
||||||
|
int costHNS = int.Parse(txs[toGet - i - 1]["amount"].ToString());
|
||||||
|
string cost = "";
|
||||||
|
if (costHNS < 0)
|
||||||
|
{
|
||||||
|
cost = "Spent: " + (costHNS * -1).ToString() + " HNS";
|
||||||
|
}
|
||||||
|
else if (costHNS > 0)
|
||||||
|
{
|
||||||
|
cost = "Received: " + costHNS.ToString() + " HNS";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Label labelInputOutput = new Label()
|
Label labelInputOutput = new Label()
|
||||||
{
|
{
|
||||||
Text = "Inputs: " + inputCount + " Outputs: " + outputCount,
|
Text = "Inputs: " + inputCount + " Outputs: " + outputCount + "\n" + cost,
|
||||||
AutoSize = true,
|
AutoSize = true,
|
||||||
Location = new Point(300, 20)
|
Location = new Point(300, 5)
|
||||||
};
|
};
|
||||||
tmpPanel.Controls.Add(labelInputOutput);
|
tmpPanel.Controls.Add(labelInputOutput);
|
||||||
|
|
||||||
|
|
||||||
tmpPanel.Click += (sender, e) =>
|
tmpPanel.Click += (sender, e) =>
|
||||||
{
|
{
|
||||||
TXForm txForm = new TXForm(this, tx);
|
TXForm txForm = new TXForm(this, hash);
|
||||||
txForm.Show();
|
txForm.Show();
|
||||||
};
|
};
|
||||||
foreach (Control c in tmpPanel.Controls)
|
foreach (Control c in tmpPanel.Controls)
|
||||||
{
|
{
|
||||||
c.Click += (sender, e) =>
|
c.Click += (sender, e) =>
|
||||||
{
|
{
|
||||||
TXForm txForm = new TXForm(this, tx);
|
TXForm txForm = new TXForm(this, hash);
|
||||||
txForm.Show();
|
txForm.Show();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user