public bool Remove(string key)
 {
     return(SecureStorage.Remove(key));
 }
        private async void BtnLogin_Clicked(object sender, EventArgs e)
        {
            Button button = (Button)sender;

            button.IsEnabled = false;
            try
            {
                var isVaild = ValidateUser();
                if (isVaild)
                {
                    var user = new User
                    {
                        networkStatus1 = UserNameEntry.Text,
                        networkStatus2 = PasswordEntry.Text
                    };

                    var res = await authViewModel.Login(user);

                    if (res != null)
                    {
                        if (res.data.Code == 0)
                        {
                            App.IsUserLoggedIn = true;

                            //storing token in secure storage
                            try
                            {
                                await SecureStorage.SetAsync("auth_token", res.token);
                            }
                            catch (Exception ex)
                            {
                                // Possible that device doesn't support secure storage on device.
                            }
                            OperationData.userId         = res.data.Data.userId;
                            OperationData.userLocation   = !string.IsNullOrEmpty(res.data.Data.userLocation) ? res.data.Data.userLocation : "";
                            OperationData.filterLocation = OperationData.userLocation;

                            if (!res.data.Data.isProfileCompleted)
                            {
                                Application.Current.MainPage = new NavigationPage(new CompleteProfilePage(false, null));
                            }
                            else
                            {
                                App.IsProfileCompleted       = true;
                                Application.Current.MainPage = new NavigationPage(new MainPage());
                            }

                            //Application.Current.MainPage = new MainPage();
                        }
                        else
                        {
                            await DisplayAlert("Message", "We could not log you in. Please try again", null, "OK");
                        }
                    }
                    else
                    {
                        await DisplayAlert("Message", "We could not log you in. Please try again", null, "OK");
                    }
                }


                bool ValidateUser()
                {
                    bool areCredentialsCorrect = false;

                    if (string.IsNullOrEmpty(UserNameEntry.Text))
                    {
                        UserNameEntryInput.HasError = true;
                    }
                    else if (!string.IsNullOrEmpty(UserNameEntry.Text) && string.IsNullOrEmpty(PasswordEntry.Text))
                    {
                        PasswordEntryInput.HasError = true;
                    }
                    else
                    {
                        UserNameEntry.Text    = UserNameEntry.Text.Trim();
                        PasswordEntry.Text    = PasswordEntry.Text.Trim();
                        areCredentialsCorrect = true;
                    }
                    return(areCredentialsCorrect);
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                button.IsEnabled = true;
            }
        }
Пример #3
0
 public async Task <string> GetTokenAsync()
 {
     return(await SecureStorage.GetAsync("auth_token"));
 }
 public virtual void ForceLogout()
 {
     SecureStorage.RemoveAll();
     Application.Current.MainPage = new NavigationPage(new LoginPage());
 }
 public virtual void CloseApp()
 {
     SecureStorage.RemoveAll();
     Environment.Exit(0);
 }
Пример #6
0
 /// <summary>
 /// Remove the locally stored user
 /// </summary>
 public void DeleteUser()
 {
     SecureStorage.Remove("User");
 }
Пример #7
0
 /// <summary>
 /// Remove the locally stored TrackingEvent
 /// </summary>
 public void DeleteTrackingEvent()
 {
     SecureStorage.Remove("TrackingEvent");
 }
Пример #8
0
 public Task SetLicenseKeyAsync(string key)
 {
     return(SecureStorage.SetAsync(LicenseGlobals.LicenseKey, key));
 }
Пример #9
0
 public void DeleteData(string key)
 {
     Application.Current.Properties[key] = null;
     SecureStorage.Remove(key);
 }
Пример #10
0
 public static string DredgeId()
 {
     return(Task.Run(() => SecureStorage.GetAsync(DREDGEID)).Result);
 }
 private static async Task <string> Get(string key)
 {
     // Don't call secure storage on the ui thread
     return(await Task.Run(async() => await SecureStorage.GetAsync(key)));
 }
Пример #12
0
        protected async Task <ResultServiceModel <T> > Post <T>(string url, object model) where T : class
        {
StartMethod:
            ResultServiceModel <T> resultService = new ResultServiceModel <T>();

            try
            {
                HttpClient client = new HttpClient();

                client.Timeout = TimeSpan.FromSeconds(20);

                string token = "";

                try
                {
                    token = await SecureStorage.GetAsync("Token");
                }
                catch (Exception e)
                {
                    throw e;
                }

                client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);

                HttpContent content = GetHttpContent(model);

                var result = client.PostAsync(url, content).Result;

                if (result.IsSuccessStatusCode)
                {
                    try
                    {
                        var json_result = result.Content.ReadAsStringAsync().Result;

                        T obj = GetModelFormResult <T>(json_result);

                        resultService.IsError = System.Net.HttpStatusCode.OK;

                        resultService.Model = obj;

                        return(resultService);
                    }
                    catch (Exception e)
                    {
                        return(new ResultServiceModel <T>());
                    }
                }
                else if (result.StatusCode == System.Net.HttpStatusCode.Unauthorized)
                {
                    try
                    {
                        var tokenData = await _tokenService.GetAccessToken();

                        if (tokenData != null)
                        {
                            if (tokenData.Model == null || tokenData.Model.Token == null)
                            {
                                resultService.IsError = result.StatusCode;
                            }
                            await SecureStorage.SetAsync("Token", tokenData.Model.Token);

                            goto StartMethod;
                        }
                        else
                        {
                            resultService.IsError = result.StatusCode;
                        }
                    }
                    catch (Exception e)
                    {
                        resultService.IsError = result.StatusCode;
                    }
                }
                else
                {
                    client.Dispose();
                    resultService.IsError = result.StatusCode;
                }
            }
            catch (Exception e)
            {
                resultService.IsError = System.Net.HttpStatusCode.InternalServerError;
            }
            return(resultService);
        }
Пример #13
0
 internal static async Task SetProfile(Profile response)
 {
     var userString = JsonConvert.SerializeObject(response);
     await SecureStorage.SetAsync("Profile", userString);
 }
 public Task SetAsync(string key, string value)
 {
     return(SecureStorage.SetAsync(key, value));
 }
 public static void RemoveFromDevice()
 {
     SecureStorage.Remove("Email");
     SecureStorage.Remove("GivenName");
 }
 private async void Entry_TextChanged(object sender, TextChangedEventArgs e)
 {
     await SecureStorage.SetAsync("Alias", e.NewTextValue);
 }
Пример #17
0
 /// <summary>
 /// Save a user locally and encrypted
 /// </summary>
 /// <param name="user">The user that will be saved</param>
 public async void SaveUser(User user)
 {
     Console.WriteLine(JsonConvert.SerializeObject(user));
     await SecureStorage.SetAsync("User", JsonConvert.SerializeObject(user));
 }
Пример #18
0
        public virtual async Task <Token> LoginWithCredentials(string userName, string password, string client_id, string client_secret, string[] scopes = null, IDictionary <string, string> acr_values = null, CancellationToken cancellationToken = default)
        {
            if (userName == null)
            {
                throw new ArgumentNullException(nameof(userName));
            }

            if (password == null)
            {
                throw new ArgumentNullException(nameof(password));
            }

            if (client_id == null)
            {
                throw new ArgumentNullException(nameof(client_id));
            }

            if (client_secret == null)
            {
                throw new ArgumentNullException(nameof(client_secret));
            }

            if (scopes == null)
            {
                scopes = "openid profile user_info".Split(' ');
            }

            HttpClient httpClient = ContainerProvider.Value.Resolve <HttpClient>();

            var parameters = new Dictionary <string, string> {
            };

            if (acr_values != null)
            {
                parameters.Add("acr_values", string.Join(" ", acr_values.Select(p => $"{p.Key}:{p.Value}")));
            }

            TokenResponse tokenResponse = await httpClient.RequestPasswordTokenAsync(new PasswordTokenRequest
            {
                Address      = ClientAppProfile.TokenEndpoint,
                ClientSecret = client_secret,
                ClientId     = client_id,
                Scope        = string.Join(" ", scopes),
                UserName     = userName,
                Password     = password,
                Parameters   = parameters
            }, cancellationToken).ConfigureAwait(false);

            if (tokenResponse.IsError)
            {
                if (tokenResponse.Error == "invalid_grant" && !string.IsNullOrEmpty(tokenResponse.ErrorDescription))
                {
                    throw new LoginFailureException(tokenResponse.ErrorDescription, (tokenResponse.Exception ?? new Exception($"{tokenResponse.Error} {tokenResponse.Raw}")));
                }
                else
                {
                    throw tokenResponse.Exception ?? new Exception($"{tokenResponse.Error} {tokenResponse.Raw}");
                }
            }

            Token token = tokenResponse;

            string jsonToken = JsonConvert.SerializeObject(token);

            if (UseSecureStorage())
            {
                await SecureStorage.SetAsync("Token", jsonToken).ConfigureAwait(false);
            }
            else
            {
                Preferences.Set("Token", jsonToken);
            }

            return(token);
        }
Пример #19
0
 /// <summary>
 /// Save a TrackingEvent locally and encrypted
 /// </summary>
 /// <param name="trackingEvent">The TrackingEvent that will be saved</param>
 public async void SaveTrackingEvent(TrackingEvent trackingEvent)
 {
     await SecureStorage.SetAsync("TrackingEvent", JsonConvert.SerializeObject(trackingEvent));
 }
Пример #20
0
        public async void ClearAccounts_Clicked(System.Object sender, System.EventArgs e)
        {
            string action = await DisplayActionSheet("Are you sure you want to remove all accounts from this device?", "Cancel", null, "Yes", "No");

            Debug.WriteLine("Action: " + action);
            if (action == "Yes")
            {
                try
                {
                    if (Device.RuntimePlatform == Device.UWP)
                    {
                        await ResetUWP();
                    }
                    else
                    {
                        await Reset();
                    }

                    // keep storage network
                    // await SecureStorage.SetAsync(helper.StorageNetwork, "TestNet");

                    GenerateAccount1.IsEnabled = true;
                    GenerateAccount2.IsEnabled = true;
                    GenerateAccount3.IsEnabled = true;

                    MultisigTransaction.IsVisible = false;
                    GetMultiSigTx.IsVisible       = false;
                    CreateMultiSig.IsVisible      = false;
                    GetMultiSig.IsVisible         = false;
                    Transaction.IsVisible         = false;
                    GetTransaction.IsVisible      = false;
                    GetAccount1Info.IsVisible     = false;
                    GetAccount2Info.IsVisible     = false;
                    GetAccount3Info.IsVisible     = false;


                    CreateMultiSig.IsEnabled      = false;
                    Transaction.IsEnabled         = false;
                    MultisigTransaction.IsEnabled = false;

                    GenerateAccount1.Text    = "Generate " + helper.StorageAccountName1;
                    GenerateAccount2.Text    = "Generate " + helper.StorageAccountName2;
                    GenerateAccount3.Text    = "Generate " + helper.StorageAccountName3;
                    CreateMultiSig.Text      = "Create Multisig Address";
                    Transaction.Text         = "Transaction from " + helper.StorageAccountName1 + " to " + helper.StorageAccountName2;
                    MultisigTransaction.Text = "Send Multisig Transaction to " + helper.StorageAccountName3;

                    //phone

                    GenerateAccount1p.IsEnabled = true;
                    GenerateAccount2p.IsEnabled = true;
                    GenerateAccount3p.IsEnabled = true;

                    MultisigTransactionp.IsVisible = false;
                    GetMultiSigTxp.IsVisible       = false;
                    CreateMultiSigp.IsVisible      = false;
                    GetMultiSigp.IsVisible         = false;
                    Transactionp.IsVisible         = false;
                    GetTransactionp.IsVisible      = false;
                    GetAccount1Infop.IsVisible     = false;
                    GetAccount2Infop.IsVisible     = false;
                    GetAccount3Infop.IsVisible     = false;


                    CreateMultiSigp.IsEnabled      = false;
                    Transactionp.IsEnabled         = false;
                    MultisigTransactionp.IsEnabled = false;

                    GenerateAccount1p.Text    = "Generate " + helper.StorageAccountName1;
                    GenerateAccount2p.Text    = "Generate " + helper.StorageAccountName2;
                    GenerateAccount3p.Text    = "Generate " + helper.StorageAccountName3;
                    CreateMultiSigp.Text      = "Create Multisig Address";
                    Transactionp.Text         = "Transaction from " + helper.StorageAccountName1 + " to " + helper.StorageAccountName2;
                    MultisigTransactionp.Text = "Send Multisig Transaction to " + helper.StorageAccountName3;



                    // note: multisig sends from acct 1 and 2 if they both sign,
                    // the account receiving funds (acct 3) does not have to be in the multisig,
                    // it could be any account
                    var htmlSource = new HtmlWebViewSource();
                    htmlSource.Html = @"<html><body></body></html>";

                    myWebView.Source  = htmlSource;
                    myWebViewp.Source = htmlSource;
                    network           = await SecureStorage.GetAsync(helper.StorageNetwork);

                    var nodetype = await SecureStorage.GetAsync(helper.StorageNodeType);

                    NetworkLabel.Text = "Network: " + network + " " + nodetype;


                    buttonstate();
                    await DisplayAlert("Clear Accounts ", "Accounts Removed", "OK");
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Error: " + ex.Message);
                    // Possible that device doesn't support secure storage on device.
                }
            }
        }
Пример #21
0
 private static async Task <string> GetUserToken()
 {
     return(await SecureStorage.GetAsync("accessToken"));
 }
Пример #22
0
        public async void buttonstate()
        {
            var account1 = await SecureStorage.GetAsync(helper.StorageAccountName1);

            var account2 = await SecureStorage.GetAsync(helper.StorageAccountName2);

            var account3 = await SecureStorage.GetAsync(helper.StorageAccountName3);

            network = await SecureStorage.GetAsync(helper.StorageNetwork);

            var msig = await SecureStorage.GetAsync(helper.StorageMultisig);

            var transaction = await SecureStorage.GetAsync(helper.StorageTransaction);

            var multisigtransaction = await SecureStorage.GetAsync(helper.StorageMultisigTransaction);

            var nodetype = await SecureStorage.GetAsync(helper.StorageNodeType);

            NetworkLabel.Text = "Network: " + network + " " + nodetype;

            CreateMultiSig.IsVisible      = true;
            Transaction.IsVisible         = true;
            MultisigTransaction.IsVisible = true;

            CreateMultiSigp.IsVisible      = true;
            Transactionp.IsVisible         = true;
            MultisigTransactionp.IsVisible = true;

            // test for null (first time) and "" or " " for UWP (after first time)
            if (string.IsNullOrEmpty(account1) || account1 == " ")
            {
                // this account is not generated yet
                GenerateAccount1.IsEnabled  = true;
                GetAccount1Info.IsVisible   = false;
                GenerateAccount1.Text       = "Generate " + helper.StorageAccountName1;
                GenerateAccount1p.IsEnabled = true;
                GetAccount1Infop.IsVisible  = false;
                GenerateAccount1p.Text      = "Generate " + helper.StorageAccountName1;
            }
            else
            {
                GenerateAccount1.Text       = helper.StorageAccountName1 + " created";
                GenerateAccount1.IsEnabled  = false;
                GetAccount1Info.IsVisible   = true;
                GenerateAccount1p.Text      = helper.StorageAccountName1 + " created";
                GenerateAccount1p.IsEnabled = false;
                GetAccount1Infop.IsVisible  = true;
                // DisableNetworkToggles(network);
            }
            if (string.IsNullOrEmpty(account2) || account2 == " ")
            {
                // this account is not generated yet
                GenerateAccount2.IsEnabled  = true;
                GetAccount2Info.IsVisible   = false;
                GenerateAccount2.Text       = "Generate " + helper.StorageAccountName2;
                GenerateAccount2p.IsEnabled = true;
                GetAccount2Infop.IsVisible  = false;
                GenerateAccount2p.Text      = "Generate " + helper.StorageAccountName2;
            }
            else
            {
                GenerateAccount2.Text       = helper.StorageAccountName2 + " created";
                GenerateAccount2.IsEnabled  = false;
                GetAccount2Info.IsVisible   = true;
                GenerateAccount2p.Text      = helper.StorageAccountName2 + " created";
                GenerateAccount2p.IsEnabled = false;
                GetAccount2Infop.IsVisible  = true;

                // DisableNetworkToggles(network);
            }
            if (string.IsNullOrEmpty(account3) || account3 == " ")
            {
                // this account is not generated yet
                GenerateAccount3.IsEnabled  = true;
                GetAccount3Info.IsVisible   = false;
                GenerateAccount3.Text       = "Generate " + helper.StorageAccountName3;
                GenerateAccount3p.IsEnabled = true;
                GetAccount3Infop.IsVisible  = false;
                GenerateAccount3p.Text      = "Generate " + helper.StorageAccountName3;
            }
            else
            {
                GenerateAccount3.Text       = helper.StorageAccountName3 + " created";
                GenerateAccount3.IsEnabled  = false;
                GetAccount3Info.IsVisible   = true;
                GenerateAccount3p.Text      = helper.StorageAccountName3 + " created";
                GenerateAccount3p.IsEnabled = false;
                GetAccount3Infop.IsVisible  = true;
                // DisableNetworkToggles(network);
            }

            //if (!(string.IsNullOrEmpty(account1) || account1 == " " ||
            //    string.IsNullOrEmpty(account2) || account2 == " " ||
            //    string.IsNullOrEmpty(account3) || account3 == " "))
            if (string.IsNullOrEmpty(account1) || account1 == " " ||
                string.IsNullOrEmpty(account2) || account2 == " " ||
                string.IsNullOrEmpty(account3) || account3 == " ")
            {
            }
            else
            {
                // all accounts created - leave state

                //    DisableNetworkToggles(network);


                if (string.IsNullOrEmpty(msig) || msig == " ")
                {
                    CreateMultiSig.IsEnabled  = true;
                    CreateMultiSig.Text       = "Create Multisig Address";
                    GetMultiSig.IsVisible     = false;
                    CreateMultiSigp.IsEnabled = true;
                    CreateMultiSigp.Text      = "Create Multisig Address";
                    GetMultiSigp.IsVisible    = false;
                    // disbale multisig transaction
                }
                else
                {
                    //CreateMultiSig.IsEnabled = true;
                    CreateMultiSig.IsEnabled  = false;
                    CreateMultiSig.Text       = "Multisig created ";
                    GetMultiSig.IsVisible     = true;
                    CreateMultiSigp.IsEnabled = false;
                    CreateMultiSigp.Text      = "Multisig created ";
                    GetMultiSigp.IsVisible    = true;
                    // todo store off version threshold and number of account
                    var htmlSource = new HtmlWebViewSource();
                    htmlSource.Html = @"<html><body><h3>" + "Multisig created - version = 1, threshold = 2, number of accounts = 3 </h3>" +
                                      "<h3>" + helper.StorageMultisig + " Address = " + msig.ToString() + "</h3>" +

                                      "</body></html>";

                    myWebView.Source  = htmlSource;
                    myWebViewp.Source = htmlSource;

                    // enable send multisig transaction
                }

                if (string.IsNullOrEmpty(transaction) || transaction == " ")
                {
                    Transaction.IsEnabled = true;

                    Transaction.Text         = "Xfer " + helper.StorageAccountName1 + " to " + helper.StorageAccountName2;
                    GetTransaction.IsVisible = false;

                    Transactionp.IsEnabled = true;

                    Transactionp.Text         = "Xfer " + helper.StorageAccountName1 + " to " + helper.StorageAccountName2;
                    GetTransactionp.IsVisible = false;
                }
                else
                {
                    Transaction.IsEnabled     = true;
                    Transaction.Text          = "Send " + helper.StorageAccountName1 + " to " + helper.StorageAccountName2 + "?";
                    GetTransaction.IsVisible  = true;
                    Transactionp.IsEnabled    = true;
                    Transactionp.Text         = "Send " + helper.StorageAccountName1 + " to " + helper.StorageAccountName2 + "?";
                    GetTransactionp.IsVisible = true;
                }
                if (string.IsNullOrEmpty(msig) || msig == " ")
                {
                }
                else
                {
                    if (string.IsNullOrEmpty(multisigtransaction) || multisigtransaction == " ")
                    {
                        // only enable if multisigaddress created
                        MultisigTransaction.IsEnabled  = true;
                        MultisigTransaction.Text       = "Send Multisig Tx to " + helper.StorageAccountName3;
                        GetMultiSigTx.IsVisible        = false;
                        MultisigTransactionp.IsEnabled = true;
                        MultisigTransactionp.Text      = "Send Multisig Tx to " + helper.StorageAccountName3;
                        GetMultiSigTxp.IsVisible       = false;
                    }
                    else
                    {
                        MultisigTransaction.IsEnabled = true;
                        MultisigTransaction.Text      = "Send Multisig Tx to " + helper.StorageAccountName3 + "?";
                        GetMultiSigTx.IsVisible       = true;

                        MultisigTransactionp.IsEnabled = true;
                        MultisigTransactionp.Text      = "Send Multisig Tx to " + helper.StorageAccountName3 + "?";
                        GetMultiSigTxp.IsVisible       = true;
                    }
                }
            }


            if (String.IsNullOrEmpty(account1) || account1 == " ")
            {
            }
            else
            {
                FundsNeeded1.IsVisible = await ToggleFundButton(network, helper.StorageAccountName1);

                FundsNeeded1p.IsVisible = await ToggleFundButton(network, helper.StorageAccountName1);
            }
            if (String.IsNullOrEmpty(account2) || account2 == " ")
            {
            }
            else
            {
                FundsNeeded2.IsVisible = await ToggleFundButton(network, helper.StorageAccountName2);

                FundsNeeded2p.IsVisible = await ToggleFundButton(network, helper.StorageAccountName2);
            }
            if (String.IsNullOrEmpty(account3) || account3 == " ")
            {
            }
            else
            {
                FundsNeeded3.IsVisible = await ToggleFundButton(network, helper.StorageAccountName3);

                FundsNeeded3p.IsVisible = await ToggleFundButton(network, helper.StorageAccountName3);
            }
            if (String.IsNullOrEmpty(msig) || msig == " ")
            {
            }
            else
            {
                FundsNeededMS.IsVisible = await ToggleFundButton(network, helper.StorageMultisig);

                FundsNeededMSp.IsVisible = await ToggleFundButton(network, helper.StorageMultisig);
            }
        }
 public virtual void ForceLogoutForErrorPopup()
 {
     SecureStorage.RemoveAll();
     Application.Current.MainPage.Navigation.PopPopupAsync();
     Application.Current.MainPage = new NavigationPage(new LoginPage());
 }
Пример #24
0
        public async void Transaction_Clicked(System.Object sender, System.EventArgs e)
        {
            // restore accounts

            var accounts = await helper.RestoreAccounts();

            Account           account1 = accounts[0];
            Account           account2 = accounts[1];
            Account           account3 = accounts[2];
            HtmlWebViewSource htmlSource;
            // transfer from Account 1 to 2
            TransactionParametersResponse transParams = null;

            try
            {
                transParams = algodApiInstance.TransactionParams();
            }
            catch (ApiException err)
            {
                throw new Exception("Could not get params", err);
            }
            var amount   = Utils.AlgosToMicroalgos(1);
            var tx       = Utils.GetPaymentTransaction(account1.Address, account2.Address, amount, "pay message", transParams);
            var signedTx = account1.SignTransaction(tx);

            Console.WriteLine("Signed transaction with txid: " + signedTx.transactionID);
            PostTransactionsResponse id = null;

            //  string wait = "";
            // send the transaction to the network
            try
            {
                id = Utils.SubmitTransaction(algodApiInstance, signedTx);
                Console.WriteLine("Successfully sent tx with id: " + id.TxId);
                var wait = Utils.WaitTransactionToComplete(algodApiInstance, id.TxId);

                Console.WriteLine("Successful! " + wait.Txn);
                await DisplayAccount(helper.StorageAccountName2);
            }
            catch (ApiException err)
            {
                // This should give us an informative error message.
                //   await SecureStorage.SetAsync("Transaction", err.Message);
                Console.WriteLine("Exception when calling algod#rawTransaction: " + err.Message);

                if (err.Message.Contains("overspend"))
                {
                    var network = await SecureStorage.GetAsync(helper.StorageNetwork);

                    htmlSource      = new HtmlWebViewSource();
                    htmlSource.Html = @"<html><body><h3>" + network + " Account has insuficent funds. " + "</h3>" +
                                      "<h3>" + network + " add funds and try again. " + "</h3>" +
                                      "<p>Account = " + account1.Address.ToString() + "</p>" +
                                      "</body></html>";

                    myWebView.Source  = htmlSource;
                    myWebViewp.Source = htmlSource;
                }
                htmlSource      = new HtmlWebViewSource();
                htmlSource.Html = @"<html><body><h3> Transaction ID = " + err.Message + "</h3>" +
                                  "</body></html>";

                myWebView.Source  = htmlSource;
                myWebViewp.Source = htmlSource;
                //  Entry4.Text = "Transaction ID = " + err.Message;
            }

            if (!(String.IsNullOrEmpty(id.TxId)))
            {
                await SecureStorage.SetAsync(helper.StorageTransaction, id.TxId.ToString());

                GetTransaction.IsVisible = true;
            }


            buttonstate();


            var mytx = await SecureStorage.GetAsync(helper.StorageTransaction);

            if (!(mytx == null || mytx == ""))

            {
                Algorand.V2.Model.Account accountinfo = await algodApiInstance.AccountInformationAsync(account2.Address.ToString());

                Debug.WriteLine("Account 2 info: " + accountinfo);
                htmlSource = new HtmlWebViewSource();

                htmlSource.Html = @"<html><body><h3> Transaction ID = " + mytx.ToString() + " </h3>" +
                                  "<h3>" + "Account 2 info = " + accountinfo.ToJson() + "</h3>" +
                                  "</body></html>";

                myWebView.Source  = htmlSource;
                myWebViewp.Source = htmlSource;
            }
            await DisplayAccount(helper.StorageAccountName2);
        }
Пример #25
0
        private async Task SetUserAndProgeny()
        {
            _viewModel.UserInfo  = OfflineDefaultData.DefaultUserInfo;
            _viewModel.UserEmail = await UserService.GetUserEmail();

            _viewModel.AccessToken = await UserService.GetAuthAccessToken();

            _viewModel.UserInfo = await UserService.GetUserInfo(_viewModel.UserEmail);

            string userviewchild = await SecureStorage.GetAsync(Constants.UserViewChildKey);

            bool viewchildParsed = int.TryParse(userviewchild, out int viewChildId);

            if (viewchildParsed)
            {
                _viewModel.ViewChild = viewChildId;
                try
                {
                    _viewModel.Progeny = await App.Database.GetProgenyAsync(_viewModel.ViewChild);
                }
                catch (Exception)
                {
                    _viewModel.Progeny = await ProgenyService.GetProgeny(_viewModel.ViewChild);
                }

                _viewModel.UserInfo = await App.Database.GetUserInfoAsync(_viewModel.UserEmail);
            }
            else
            {
                _viewModel.ViewChild = _viewModel.UserInfo.ViewChild;
            }

            if (String.IsNullOrEmpty(_viewModel.UserInfo.Timezone))
            {
                _viewModel.UserInfo.Timezone = Constants.DefaultTimeZone;
            }
            try
            {
                TimeZoneInfo.FindSystemTimeZoneById(_viewModel.UserInfo.Timezone);
            }
            catch (Exception)
            {
                _viewModel.UserInfo.Timezone = TZConvert.WindowsToIana(_viewModel.UserInfo.Timezone);
            }

            Progeny progeny = await ProgenyService.GetProgeny(_viewModel.ViewChild);

            try
            {
                TimeZoneInfo.FindSystemTimeZoneById(progeny.TimeZone);
            }
            catch (Exception)
            {
                progeny.TimeZone = TZConvert.WindowsToIana(progeny.TimeZone);
            }
            _viewModel.Progeny = progeny;

            List <Progeny> progenyList = await ProgenyService.GetProgenyList(_viewModel.UserEmail);

            _viewModel.ProgenyCollection.Clear();
            _viewModel.CanUserAddItems = false;
            if (progenyList != null && progenyList.Any())
            {
                foreach (Progeny prog in progenyList)
                {
                    _viewModel.ProgenyCollection.Add(prog);
                    if (prog.Admins.ToUpper().Contains(_viewModel.UserInfo.UserEmail.ToUpper()))
                    {
                        _viewModel.CanUserAddItems = true;
                    }
                }
            }

            _viewModel.UserAccessLevel = await ProgenyService.GetAccessLevel(_viewModel.ViewChild);
        }
Пример #26
0
        public async void MultisigTransaction_Clicked(System.Object sender, System.EventArgs e)
        {
            //MultisigTransaction

            // List for Pks for multisig account
            List <Ed25519PublicKeyParameters> publicKeys = new List <Ed25519PublicKeyParameters>();

            // restore accounts
            var accounts = await helper.RestoreAccounts();

            Account account1 = accounts[0];
            Account account2 = accounts[1];
            Account account3 = accounts[2];


            publicKeys.Add(account1.GetEd25519PublicKey());
            publicKeys.Add(account2.GetEd25519PublicKey());
            publicKeys.Add(account3.GetEd25519PublicKey());

            // Instantiate the the Multisig Accout

            MultisigAddress msig = new MultisigAddress(1, 2, publicKeys);

            Console.WriteLine("Multisignature Address: " + msig.ToString());
            //   dispense funds to msig account
            string DEST_ADDR = account3.Address.ToString();

            // add some notes to the transaction

            // todo notes
            byte[] notes = Encoding.UTF8.GetBytes("These are some notes encoded in some way!");//.getBytes();

            var         amount = Utils.AlgosToMicroalgos(1);
            Transaction tx     = null;

            //noteb64 = notes
            try
            {
                tx = Utils.GetPaymentTransaction(new Address(msig.ToString()), new Address(DEST_ADDR), amount, "this is a multisig trans",
                                                 algodApiInstance.TransactionParams());
            }
            catch (Exception err)
            {
                Console.WriteLine("Could not get params", err.Message);
            }
            // Sign the Transaction for two accounts
            SignedTransaction signedTx   = account1.SignMultisigTransaction(msig, tx);
            SignedTransaction completeTx = account2.AppendMultisigTransaction(msig, signedTx);

            // send the transaction to the network
            PostTransactionsResponse id = null;

            try
            {
                id = Utils.SubmitTransaction(algodApiInstance, completeTx);
                Console.WriteLine("Successfully sent tx with id: " + id.TxId);
                var x = Utils.WaitTransactionToComplete(algodApiInstance, id.TxId);
                Console.WriteLine(x);
            }
            catch (ApiException err)
            {
                Console.WriteLine("Exception when calling algod#rawTransaction: " + err.Message);
            }
            await SecureStorage.SetAsync(helper.StorageMultisigTransaction, id.TxId.ToString());

            MultisigTransaction.Text = "Transaction successfully sent";
            GetMultiSigTx.IsVisible  = true;

            MultisigTransactionp.Text = "Transaction successfully sent";
            GetMultiSigTxp.IsVisible  = true;

            //ulong? balance = await helper.GetAccountBalance(helper.StorageMultisig);
            //var htmlSource = new HtmlWebViewSource();
            //htmlSource.Html = @"<html><body><h3> Multisig balance = " + balance.ToString() + " </h3>" +
            //      "</body></html>";

            //myWebView.Source = htmlSource;



            buttonstate();

            await DisplayAccount(helper.StorageAccountName3);

            //var mytx = await SecureStorage.GetAsync(helper.StorageMultisigTransaction);

            //if (!(mytx == null || mytx == ""))

            //{
            //    htmlSource = new HtmlWebViewSource();
            //    htmlSource.Html = @"<html><body><h3> Transaction ID = " + mytx.ToString() + " </h3>" +
            //          "</body></html>";

            //    myWebView.Source = htmlSource;


            //}
        }
Пример #27
0
 public void SignOut()
 {
     Auth.SignOut();
     SecureStorage.RemoveAll();
     Preferences.Clear();
 }
        public async void SaveToDevice()
        {
            await SecureStorage.SetAsync("Email", Email);

            await SecureStorage.SetAsync("GivenName", GivenName);
        }
Пример #29
0
        public async Task <ApiStatus> SignInAsync()
        {
            try
            {
                UserInformation userInfo = await Auth.SignInAsync();

                // Sign-in succeeded.
                string accountId = userInfo.AccountId;
                string token     = userInfo.AccessToken;
                if (!string.IsNullOrWhiteSpace(accountId) && !string.IsNullOrWhiteSpace(token))
                {
                    await SecureStorage.SetAsync("auth_token", token);

                    var tokenHandler = new JwtSecurityTokenHandler();

                    try
                    {
                        var jwToken = tokenHandler.ReadJwtToken(userInfo.IdToken);

                        var firstName  = jwToken.Claims.FirstOrDefault(t => t.Type == "given_name")?.Value;
                        var familyName = jwToken.Claims.FirstOrDefault(t => t.Type == "family_name")?.Value;
                        var jobTitle   = jwToken.Claims.FirstOrDefault(t => t.Type == "jobTitle")?.Value;
                        var email      = jwToken.Claims.FirstOrDefault(t => t.Type == "emails")?.Value;

                        string fullName = firstName + " " + familyName;

                        if (!string.IsNullOrWhiteSpace(fullName))
                        {
                            Preferences.Set("MyName", fullName);
                        }

                        if (!string.IsNullOrWhiteSpace(jobTitle))
                        {
                            Preferences.Set("JobTitle", jobTitle);
                        }

                        if (!string.IsNullOrWhiteSpace(email))
                        {
                            Preferences.Set("MyEmail", email);
                        }

                        _httpClient = new HttpClient();
                        _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

                        string baseUrl = Constants.ApiBaseUrl;

                        _userClient = new UserClient(baseUrl, _httpClient);

                        var user = await _userClient.GetAsync();

                        Preferences.Set("MyUserId", user.Id);
                        Preferences.Set("MyProfilePic", user.Picture);

                        if (!string.IsNullOrWhiteSpace(user.Points.ToString()))
                        {
                            Preferences.Set("MyPoints", user.Points);
                        }

                        Preferences.Set("LoggedIn", true);
                        return(ApiStatus.Success);
                    }
                    catch (ArgumentException)
                    {
                        //TODO: Handle error decoding JWT
                        return(ApiStatus.Error);
                    }
                }
                else
                {
                    return(ApiStatus.LoginFailure);
                }
            }

            catch (ApiException e)
            {
                if (e.StatusCode == 404)
                {
                    return(ApiStatus.Unavailable);
                }
                else if (e.StatusCode == 401)
                {
                    return(ApiStatus.LoginFailure);
                }

                return(ApiStatus.Error);
            }
        }
 public Task <string> GetAsync(string key)
 {
     return(SecureStorage.GetAsync(key));
 }