Example #1
0
        private async void BulkImportButton_OnClick(object sender, RoutedEventArgs e)
        {
            var fd = new OpenFileDialog();

            fd.Multiselect = false;
            fd.Filter      = "CSV Files (*.csv)|*.csv|All Files (*.*)|*.*";
            var showDialog = fd.ShowDialog();
            var res        = showDialog != null && (bool)showDialog;

            if (!res || string.IsNullOrEmpty(fd.FileName) || !File.Exists(fd.FileName))
            {
                return;
            }

            string[] secrets;
            try
            {
                secrets = File.ReadAllText(fd.FileName).Split(',');
            }
            catch (Exception)
            {
                var nd = new NoticeDialog("Bulk Account Import",
                                          "Error: CSV file could not be parsed.\r\nPlease correct the file and try again.");
                nd.ShowDialog();
                return;
            }

            using (var avm = new AuthViewModel {
                ActionDescription = "Bulk Import Accounts "
            })
            {
                var rmpw = new AuthRequestDialog(avm);
                rmpw.ShowDialog();
                if (!avm.Accepted)
                {
                    return;
                }
                if (rmpw.DialogResult == null || rmpw.DialogResult == false || string.IsNullOrEmpty(avm.Password))
                {
                    return;
                }
                var i  = 0;
                var ii = 1;
                var pd = new ProcessingDialog("Importing Accounts",
                                              "Please wait while your accounts are imported. This may take some time depending on the number of accounts.");
                pd.Show();
                foreach (var sec in secrets)
                {
                    ii++;
                    pd.ProgressTextBlock.Text = ii + " of " + secrets.Length;
                    var act = await Globals.API.Accounts_Open(sec);

                    if (!act.success)
                    {
                        continue;
                    }

                    var hasrecord = (from a in Globals.AppViewModel.AccountsViewModel.Accounts
                                     where a.Address == act.account.address
                                     select a).Any();
                    if (hasrecord)
                    {
                        continue;
                    }

                    var ssece = AppHelpers.EncryptString(sec, avm.Password);
                    var bal   = LiskAPI.LSKLongToDecimal(act.account.balance);
                    var ni    = new Account
                    {
                        Address      = act.account.address,
                        PublicKey    = act.account.publicKey,
                        FriendlyName = act.account.address,
                        SecretHash   = ssece,
                        Balance      = bal,
                        LastUpdate   = DateTime.UtcNow
                    };
                    try
                    {
                        await AccountsViewModel.AddAccountAsync(ni);

                        i++;
                    }
                    catch (Exception crap)
                    {
                        Console.WriteLine("Error saving imported account " + act.account.address + " | " + crap.Message);
                    }
                }
                pd.Hide();
                var nd = new NoticeDialog("Bulk Account Import",
                                          "Bulk account import complete.\r\n" + i + " of " + secrets.Length + " accounts imported.");
                nd.ShowDialog();
                NavigationCommands.BrowseBack.Execute(null, null);
            }
        }
Example #2
0
        private async void ModernButton_Click_1(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(AccountSecretTextBox.Text.Trim()))
            {
                return;
            }
            var sec        = AccountSecretTextBox.Text;
            var issecvalid = await AppHelpers.IsSecretValid(sec);

            if (!issecvalid)
            {
                var nd = new NoticeDialog("Invalid Account Secret",
                                          "Invalid account secret.\r\nPlease correct and try again.");
                nd.ShowDialog();
                return;
            }
            AccountSecretTextBox.Text = "";
            var act = await Globals.API.Accounts_Open(sec);

            var fn = AccountFriendlyNameTextBox.Text.Trim();

            AccountFriendlyNameTextBox.Text = "";
            if (string.IsNullOrEmpty(fn))
            {
                var dg = await Globals.API.Delegates_Get(act.account.publicKey);

                if (dg != null && dg.success && dg.@delegate != null && !string.IsNullOrEmpty([email protected]))
                {
                    fn = [email protected];
                }
            }

            var hasrecord = (from a in Globals.AppViewModel.AccountsViewModel.Accounts
                             where a.Address == act.account.address || a.FriendlyName == fn
                             select a).Any();

            if (hasrecord)
            {
                var nd = new NoticeDialog("Account Record Exists",
                                          "A record for this account secret or friendly name already exists.\r\nPlease use a different secret or friendly name and try again");
                nd.ShowDialog();
                return;
            }

            using (var avm = new AuthViewModel {
                ActionDescription = "Add / Import new account " + fn
            })
            {
                var rmpw = new AuthRequestDialog(avm);
                rmpw.ShowDialog();
                if (!avm.Accepted)
                {
                    return;
                }
                if (rmpw.DialogResult == null || rmpw.DialogResult == false || string.IsNullOrEmpty(avm.Password))
                {
                    return;
                }

                var ssece = AppHelpers.EncryptString(sec, avm.Password);
                var ni    = new Account
                {
                    Address      = act.account.address,
                    PublicKey    = act.account.publicKey,
                    FriendlyName = fn,
                    SecretHash   = ssece,
                    Balance      = LiskAPI.LSKLongToDecimal(act.account.balance)
                };
                await AccountsViewModel.AddAccountAsync(ni);

                NavigationCommands.BrowseBack.Execute(null, null);
            }
        }
Example #3
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
            {
            }
        }