private async void Window_Loaded(object sender, RoutedEventArgs e) { if (XmlManager.IsExist()) { List <string> adviceList = new List <string>() { "You should remove spend address so that the program may run faster", "You should only use each address once", "Your private key is in the UserInfo.xml file" }; Random r = new Random(); int rInt = r.Next(0, 3); //for ints txtResult.Text = adviceList[rInt]; await Task.Delay(2000); WalletWindow wallet = new WalletWindow(); wallet.Show(); this.Close(); } else { XmlManager.NewXmlFile(); txtResult.Text = "Welcome new user!\n Currently generate your first address!\nPlease don't close window"; Transaction transaction = new Transaction(); TransactionProtocol protocol = new TransactionProtocol(); TransactionResponse result = await protocol.MakeTransaction(transaction); if (result.Status == "invalid") { txtResult.Text = "Cannot send key to host"; } else { txtResult.Text = "You create your first transaction"; } await Task.Delay(2000); WalletWindow wallet = new WalletWindow(); wallet.Show(); this.Close(); } }
private async void MakeTransaction(object sender, RoutedEventArgs e) { if (Outputs.Count == 0) { MessageBox.Show("You don't have Output"); return; } await GetTotalBalance(); float spend = 0; float total = XmlManager.GetCurrentTotal(); var stringCoin = $": {total.ToString()} KCoin"; txtTotal.Text = stringCoin; foreach (Output output in Outputs) { spend += output.Amount; } if (total < spend) { MessageBox.Show("You don't have enough money"); return; } Transaction transaction = new Transaction(Outputs); TransactionProtocol protocol = new TransactionProtocol(); TransactionResponse response = await protocol.MakeTransaction(transaction); if (response.Status == "invalid") { MessageBox.Show(response.Message, "Error"); } Outputs.Clear(); lvOutput.ItemsSource = null; lvOutput.ItemsSource = Outputs; }