Пример #1
0
        protected async override void OnAppearing()
        {
            var fl = firstLoad;

            base.OnAppearing();

            App.Locator.Packages.AvailablePackagesList = new List <AvaiablePackage>();
            App.Locator.Packages.PackagesList          = new List <Package>();

            if (fl)
            {
                if (!String.IsNullOrEmpty(App.Locator.Profile.UserName))
                {
                    if (!String.IsNullOrEmpty(App.Locator.Profile.PhoneNumber))
                    {
                        if (App.Locator.Profile.MnemonicGenerated)
                        {
                            var page = new ViewMnemonicPage();
                            await Navigation.PushAsync(page, true);
                        }
                        else
                        {
                            var page = new SMSVereficationPage();
                            await Navigation.PushAsync(page, true);
                        }

                        App.ShowLoading(false);
                    }
                    else
                    {
                        var userDetails = new UserDetails {
                            PaketUser = App.Locator.Profile.UserName,
                            FullName  = App.Locator.Profile.FullName,
                            Address   = App.Locator.Profile.Address
                        };
                        var page = new RegistrationPage(true, userDetails);

                        await Navigation.PushAsync(page, true);
                    }
                }
            }
            else
            {
                App.Locator.Profile.DeleteCredentials();
            }

            try{
                App.Locator.DeviceService.setStausBarBlack();
            }
            catch (Exception ex) {
                Console.WriteLine(ex);
            }
        }
Пример #2
0
        private async void CreateAccountClicked(object sender, EventArgs e)
        {
            if (IsValid())
            {
                Unfocus();

                if (!App.Locator.FriendlyService.IsFundWorking)
                {
                    ShowErrorMessage(AppResources.RegistrationFundNotWorking);
                    return;
                }

                App.ShowLoading(true);

                if (IsFinishActivation == true)
                {
                    //Retrievee private key
                    var kd = App.Locator.Profile.TryGetKeyData();

                    var updateResult = await App.Locator.IdentityServiceClient.UserInfos(ViewModel.FullName, ViewModel.FullPhoneNumber, ViewModel.Address);

                    if (updateResult != null)
                    {
                        App.Locator.Profile.SetCredentials(ViewModel.UserName,
                                                           ViewModel.FullName,
                                                           ViewModel.FullPhoneNumber,
                                                           ViewModel.Address,
                                                           kd.KeyPair.SecretSeed,
                                                           kd.MnemonicString);

                        Application.Current.Properties[Constants.STORED_PHONE] = ViewModel.FullPhoneNumber;

                        if (App.Locator.Profile.MnemonicGenerated)
                        {
                            var page = new ViewMnemonicPage();
                            await Navigation.PushAsync(page, true);
                        }
                        else
                        {
                            var page = new SMSVereficationPage();
                            await Navigation.PushAsync(page, true);
                        }
                    }
                }
                else if (IsAddedInfo)
                {
                    try
                    {
                        //Retrievee private key
                        var kd = App.Locator.Profile.TryGetKeyData();

                        var result = await App.Locator.IdentityServiceClient.RegisterUser(ViewModel.UserName, kd.KeyPair.Address);

                        if (result != null)
                        {
                            IsFinishActivation = true;

                            App.Locator.Profile.SetCredentials(ViewModel.UserName, kd.KeyPair.SecretSeed, kd.MnemonicString);

                            var infosResult = await App.Locator.IdentityServiceClient.UserInfos(ViewModel.FullName, ViewModel.FullPhoneNumber, ViewModel.Address, kd.KeyPair.Address);

                            if (infosResult != null)
                            {
                                App.Locator.Profile.SetCredentials(ViewModel.UserName,
                                                                   ViewModel.FullName,
                                                                   ViewModel.FullPhoneNumber,
                                                                   ViewModel.Address,
                                                                   kd.KeyPair.SecretSeed,
                                                                   kd.MnemonicString);

                                Application.Current.Properties[Constants.STORED_PHONE] = ViewModel.FullPhoneNumber;

                                if (App.Locator.Profile.MnemonicGenerated)
                                {
                                    var page = new ViewMnemonicPage();
                                    await Navigation.PushAsync(page, true);
                                }
                                else
                                {
                                    var page = new SMSVereficationPage();
                                    await Navigation.PushAsync(page, true);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine(ex);

                        ShowErrorMessage(ex.Message);
                    }
                }
                else
                {
                    try
                    {
                        var kd = Profile.GenerateKeyPairFromMnemonic();
                        App.Locator.Profile.KeyPair = kd.KeyPair;

                        var result = await App.Locator.IdentityServiceClient.RegisterUser(ViewModel.UserName, kd.KeyPair.Address);

                        if (result != null)
                        {
                            IsFinishActivation = true;
                            App.Locator.Profile.SetCredentials(ViewModel.UserName, kd.KeyPair.SecretSeed, kd.MnemonicString);
                            App.Locator.Profile.MnemonicGenerated = true;

                            var infosResult = await App.Locator.IdentityServiceClient.UserInfos(ViewModel.FullName, ViewModel.FullPhoneNumber, ViewModel.Address, kd.KeyPair.Address);

                            if (infosResult != null)
                            {
                                App.Locator.Profile.SetCredentials(ViewModel.UserName,
                                                                   ViewModel.FullName,
                                                                   ViewModel.FullPhoneNumber,
                                                                   ViewModel.Address,
                                                                   kd.KeyPair.SecretSeed,
                                                                   kd.MnemonicString);

                                var page = new ViewMnemonicPage();
                                await Navigation.PushAsync(page, true);
                            }
                        }
                        else
                        {
                            App.Locator.Profile.KeyPair = null;
                        }
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine(ex);

                        App.Locator.Profile.KeyPair = null;

                        ShowErrorMessage(ex.Message);
                    }
                }

                App.ShowLoading(false);
            }
        }