Exemple #1
0
        private async void SendLSKButton_OnClick(object sender, RoutedEventArgs e)
        {
            var act = (from a in Globals.AppViewModel.AccountsViewModel.Accounts
                       where a.FriendlyName == AppViewModel.SelectedAccountFriendlyName
                       select a).First();
            var     avail = act.Balance;
            decimal iamount;

            if (!decimal.TryParse(SendAmountTextBox.Text.Trim(), out iamount))
            {
                ShowNotice("Send LSK", "Please enter a valid send amount and try again.");
                return;
            }
            if (iamount + Properties.Settings.Default.SendFee > avail || iamount < 0.1m)
            {
                ShowNotice("Send LSK",
                           "Sorry the amount specified exceeds your available balance.\r\nPlease enter a valid send amount and try again.");
                return;
            }
            //verify the toaddress is valid by checking the length and format
            if (ToAddressTextBox.Text.Trim().Length < 20 || ToAddressTextBox.Text.Trim().Length > 21 ||
                !ToAddressTextBox.Text.Trim().EndsWith("l"))
            {
                ShowNotice("Send LSK",
                           "Sorry the address specified does not apear to be valid.\r\nPlease check the address for errors and try again.");
                return;
            }
            transactions_send_response res;

            using (
                var avm = new AuthViewModel
            {
                ActionDescription =
                    "Send " + iamount + " LSK from " + act.FriendlyName + " to " + ToAddressTextBox.Text.Trim()
            })
            {
                var rmpw = new AuthRequestDialog(avm);
                rmpw.ShowDialog();
                if (!avm.Accepted)
                {
                    return;
                }
                if (rmpw.DialogResult == null || rmpw.DialogResult == false || string.IsNullOrEmpty(avm.Password))
                {
                    return;
                }
                var actsec = AppHelpers.DecryptString(act.SecretHash, avm.Password);
                res = await Globals.API.Transactions_Send(actsec, (long)LiskAPI.LSKDecimalToLong(iamount),
                                                          ToAddressTextBox.Text.Trim(), act.PublicKey, "");
            }
            if (res == null || !res.success || string.IsNullOrEmpty(res.transactionId))
            {
                if (res != null && !string.IsNullOrEmpty(res.error))
                {
                    Console.WriteLine("Send transaction failed or did not return a transaction id, " + res.error);
                    var nd = new NoticeDialog("Send LSK Failed",
                                              "Sending of " + iamount + " LSK from " + act.FriendlyName + " to " +
                                              ToAddressTextBox.Text.Trim() + " failed.\r\nError: " + res.error);
                    nd.ShowDialog();
                }
                else
                {
                    Console.WriteLine("Send transaction failed or did not return a transaction id, no additional data");
                    var nd = new NoticeDialog("Send LSK Failed",
                                              "Sending of " + iamount + " LSK from " + act.FriendlyName + " to " +
                                              ToAddressTextBox.Text.Trim() + " failed.\r\nError: no error data available.");
                    nd.ShowDialog();
                }
            }
            else
            {
                Console.WriteLine("Send transaction id " + res.transactionId + " sent " + iamount + " LSK from " +
                                  act.FriendlyName + " to " + ToAddressTextBox.Text.Trim());
                var nd = new NoticeDialog("Send LSK",
                                          "Sent " + iamount + " LSK from " + act.FriendlyName + " to " + ToAddressTextBox.Text.Trim());
                nd.ShowDialog();
            }
            try
            {
                Send_OnLoaded(null, null);
            }
            catch
            {
            }
        }