Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
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);
            }
        }