public Task RestoreAccountByKey(string privateKey, string newPassword)
 {
     return(Task.Run(() =>
     {
         this.Account = new Account(privateKey);
         var json = new KeyStoreService().EncryptAndGenerateDefaultKeyStoreAsJson(newPassword, privateKey.HexToByteArray(), this.Account.Address);
         Settings.AddAccount(this.Account.Address, json);
     }));
 }
Exemple #2
0
        private async void Save_Click(object sender, RoutedEventArgs e)
        {
            if (numberBox.Text.Length < numberBox.MaxLength || !numberRx.IsMatch(numberBox.Text))
            {
                numberBox.Focus(FocusState.Programmatic); return;
            }
            if (passwordBox.Password.Length == 0 || carrierBox.SelectedIndex == 1 && passwordBox.Password.Length != BitePasswordLength)
            {
                passwordBox.Focus(FocusState.Programmatic); return;
            }

            if (Network.Disconnected)
            {
                await new MessageDialog(DisplayResources.Strings.GetString("NetworkOffline")).ShowAsync();
                return;
            }

            SetEnabled(false);
            var statusBar = StatusBar.GetForCurrentView();

            statusBar.ProgressIndicator.Text = DisplayResources.Strings.GetString("LoggingIn");
            await statusBar.ProgressIndicator.ShowAsync();

            string  number = numberBox.Text;
            Account account = null;
            string  errorMessage = null, errorMessageId = null;

            try {
                switch (carrierBox.SelectedIndex)
                {
                case 0:
                    errorMessageId = "ZZLoginFailure";
                    account        = await ZZAccount.Login(client, numberBox.Text, passwordBox.Password);

                    break;

                case 1:
                    errorMessageId = "BiteLoginFailure";
                    account        = await BiteAccount.Login(client, numberBox.Text, passwordBox.Password.ToUpper());

                    break;

                case 2:
                    errorMessageId = "OLoginFailure";
                    account        = await OAccount.Login(client, numberBox.Text, passwordBox.Password);

                    break;
                }
                if (account == null)
                {
                    errorMessage = DisplayResources.Strings.GetString(errorMessageId);
                }
            } catch (Exception ex) {
                errorMessage = ex.Message + Environment.NewLine + DisplayResources.Strings.GetString(errorMessageId);
            }

            await statusBar.ProgressIndicator.HideAsync();

            if (errorMessage != null)
            {
                await new MessageDialog(errorMessage).ShowAsync();
                SetEnabled(true);
                return;
            }

            account.RefreshInterval = TimeSpan.FromMinutes(30);
            account.Caption         = string.Concat(number.Substring(0, 2), " ", number.Substring(2, 3), " ", number.Substring(5, 3));
            app.Accounts.Add(account);
            Settings.SetAccounts(app.Accounts);
            app.HaveAccountsChanged = false;
            Settings.AddAccount(account);

            statusBar.ProgressIndicator.Text = DisplayResources.Strings.GetString("Refreshing");
            await statusBar.ProgressIndicator.ShowAsync();

            errorMessage = null;
            try {
                await account.SetBalance(client);
            } catch (Exception) {
                // Ja nespēja noskaidrot atlikumu, ļauj lietotājam to vēlāk pamēģināt.
            }
            await statusBar.ProgressIndicator.HideAsync();

            app.Account = account;
            Frame.Navigate(typeof(EditAccountPage));
        }