Ejemplo n.º 1
0
 public async void CheckActivation()
 {
     await WithProgress(activityIndicator, async() => {
         var created = await StellarHelper.CheckAccountCreated(App.Locator.Profile.KeyPair);
         if (created)
         {
             var trusted = await StellarHelper.CheckTokenTrusted();
             if (trusted)
             {
                 App.Locator.Profile.Activated = true;
                 Application.Current.MainPage  = new MainPage();
             }
             else
             {
                 var added = await StellarHelper.AddTrustToken(App.Locator.Profile.KeyPair);
                 if (added)
                 {
                     App.Locator.Profile.Activated = true;
                     Application.Current.MainPage  = new MainPage();
                 }
                 else
                 {
                     ShowMessage("Error adding trust token");
                 }
             }
         }
         else
         {
             ShowMessage("Stellar account isn't created yet");
         }
     });
 }
Ejemplo n.º 2
0
        public static async Task <StellarOperationResult> AcceptPackageAsRecipient(string escrowPubkey, string paymentTransaction, string location)
        {
            //var courierBalance = await App.Locator.ServiceClient.Balance(App.Locator.Profile.Pubkey);

            var signed = await StellarHelper.SignTransaction(App.Locator.Profile.KeyPair, paymentTransaction);            //sign the payment transaction

            var submitResult = await App.Locator.BridgeServiceClient.SubmitTransaction(signed);

            if (submitResult != null)
            {
                var result = await App.Locator.RouteServiceClient.AcceptPackage(escrowPubkey, location);                //accept the package

                if (result != null)
                {
                    return(StellarOperationResult.Success);
                }
                else
                {
                    return(StellarOperationResult.FailAcceptPackage);
                }
            }
            else
            {
                return(StellarOperationResult.FailAcceptPackage);
            }
        }
Ejemplo n.º 3
0
        private async void DepositClicked(object sender, System.EventArgs e)
        {
            Unfocus();

            ProgressBar.Progress         = 0;
            ProgressLabel.Text           = "";
            ProgressView.BackgroundColor = new Color(0, 0, 0, 0.7);
            ProgressView.IsVisible       = true;

            try
            {
                var result = await StellarHelper.LaunchPackage(ViewModel.PaketId, ViewModel.RecipientPubkey, ViewModel.Deadline, ViewModel.CourierPubkey, ViewModel.Payment, ViewModel.Collateral, FinalizePackageEvents);

                if (result == StellarOperationResult.LowBULsLauncher)
                {
                    EventHandler handler = (se, ee) => {
                        if (ee != null)
                        {
                            ShowPurchaseBuls();
                        }
                    };

                    ShowErrorMessage(AppResources.PurchaseBULs, false, handler, AppResources.Purchase);
                }
                else if (result != StellarOperationResult.Success)
                {
                    ShowError(result);
                }
                else
                {
                    BindingContext = await PackageHelper.GetPackageDetails(ViewModel.PaketId);

                    CheckVisiblePayments();
                }
            }
            catch (Exception exc)
            {
                EventHandler handler = (se, ee) => {
                    if (ee != null)
                    {
                        ShowPurchaseBuls();
                    }
                };

                if (exc.Message == AppResources.InsufficientBULs)
                {
                    ShowErrorMessage(AppResources.PurchaseBULs, false, handler, AppResources.Purchase);
                }
                else
                {
                    ShowErrorMessage(exc.Message);
                }
            }

            ProgressView.IsVisible = false;
        }
Ejemplo n.º 4
0
        private async void RefundClicked(object sender, System.EventArgs e)
        {
            App.ShowLoading(true);

            var result = await StellarHelper.RefundEscrow(ViewModel.RefundTransaction, ViewModel.MergeTransaction);

            if (result)
            {
                RefundButton.IsVisible = false;
                RefundLabel.IsVisible  = false;

                ShowMessage(AppResources.RefundingOK);
            }

            App.ShowLoading(false);
        }
Ejemplo n.º 5
0
        public async void CheckActivation()
        {
            var created = await StellarHelper.CheckAccountCreated(App.Locator.Profile.KeyPair);

            if (created)
            {
                var trusted = await StellarHelper.CheckTokenTrusted();

                if (trusted)
                {
                    App.Locator.Profile.Activated = true;

                    var navigationPage = new NavigationPage(new MainPage());

                    Application.Current.MainPage = navigationPage;

                    App.ShowLoading(false);
                }
                else
                {
                    var added = await StellarHelper.AddTrustToken(App.Locator.Profile.KeyPair);

                    if (added)
                    {
                        App.Locator.Profile.Activated = true;

                        var navigationPage = new NavigationPage(new MainPage());

                        Application.Current.MainPage = navigationPage;

                        App.ShowLoading(false);
                    }
                    else
                    {
                        App.ShowLoading(false);

                        ShowErrorMessage(AppResources.ErrorAddTrustToken);
                    }
                }
            }
            else
            {
                App.ShowLoading(false);

                ShowErrorMessage(AppResources.StellarAccountNotCreated);
            }
        }
Ejemplo n.º 6
0
        public async void CheckActivation()
        {
            Unfocus();

            var created = await StellarHelper.CheckAccountCreated(App.Locator.Profile.KeyPair);

            if (created)
            {
                var trusted = await StellarHelper.CheckTokenTrusted();

                if (trusted)
                {
                    App.Locator.Profile.Activated = true;

                    //var userInfo = await App.Locator.IdentityServiceClient.UserInfos();
                    //if (userInfo != null)
                    //{
                    //    App.Locator.Profile.SetCredentials(App.Locator.Profile.UserName,
                    //                                       userInfo.UserDetails.FullName, userInfo.UserDetails.PhoneNumber, userInfo.UserDetails.Address,
                    //                                       App.Locator.Profile.KeyPair.SecretSeed, App.Locator.Profile.Mnemonic);

                    //}

                    var page = new WaitingAccountCreationPage(true, true);

                    await Navigation.PushAsync(page, true);

                    App.ShowLoading(false);
                }
                else
                {
                    var page = new SMSVereficationPage();

                    await Navigation.PushAsync(page, true);

                    App.ShowLoading(false);
                }
            }
            else
            {
                var page = new SMSVereficationPage();

                await Navigation.PushAsync(page, true);

                App.ShowLoading(false);
            }
        }
Ejemplo n.º 7
0
        public static async Task <StellarOperationResult> AcceptPackageAsCourier(string escrowPubkey, long collateral, string paymentTransaction, string location)
        {
            var courierBalance = await App.Locator.BridgeServiceClient.Balance(App.Locator.Profile.Pubkey);

            if (courierBalance == null || courierBalance.Account.BalanceBUL < collateral)
            {
                return(StellarOperationResult.LowBULsCourier);
            }

            var trans = await App.Locator.BridgeServiceClient.PrepareSendBuls(App.Locator.Profile.Pubkey, escrowPubkey, (collateral / 10000000.0f));

            if (trans != null)
            {
                var signed = await StellarHelper.SignTransaction(App.Locator.Profile.KeyPair, trans.Transaction);

                var paymentResult = await App.Locator.BridgeServiceClient.SubmitTransaction(signed);

                if (paymentResult != null)
                {
                    var acceptResult = await App.Locator.RouteServiceClient.AcceptPackage(escrowPubkey, location);

                    if (acceptResult != null)
                    {
                        //var newCourierBalance = await App.Locator.ServiceClient.Balance(App.Locator.Profile.Pubkey);//TODO remove balance check
                        //if (newCourierBalance.BalanceBUL == courierBalance.BalanceBUL - collateral) {
                        App.Locator.Profile.AddTransaction(escrowPubkey, paymentTransaction);
                        return(StellarOperationResult.Success);
                        //}

                        //return StellarOperationResult.IncositentBalance;
                    }
                    else
                    {
                        return(StellarOperationResult.FailAcceptPackage);
                    }
                }
                else
                {
                    return(StellarOperationResult.FailSendCollateral);
                }
            }
            else
            {
                return(StellarOperationResult.FailSendCollateral);
            }
        }
Ejemplo n.º 8
0
        private async void SendClicked(object sender, EventArgs e)
        {
            if (EntryRecepient.IsBusy)
            {
                return;
            }
            else if (recipient.Length == 0)
            {
                EntryRecepient.FocusField();
            }
            else if (IsValid())
            {
                Unfocus();

                App.ShowLoading(true);

                try
                {
                    double amount = double.Parse(EntryAmount.Text);

                    var trans = await App.Locator.BridgeServiceClient.PrepareSendBuls(App.Locator.Profile.Pubkey, recipient, amount);

                    if (trans != null)
                    {
                        var signed = await StellarHelper.SignTransaction(App.Locator.Profile.KeyPair, trans.Transaction);

                        var result = await App.Locator.BridgeServiceClient.SubmitTransaction(signed);

                        if (result != null)
                        {
                            await ViewModel.Load();

                            SundBULSMainStackView.IsVisible = false;
                            SendBULSSuccessView.IsVisible   = true;
                        }
                    }
                }
                catch (Exception ex)
                {
                    EventHandler handler = (se, ee) =>
                    {
                        if (ee != null)
                        {
                            ShowEntry(PurchaseBULEntryViews);

                            if (PickerBULCurrency.SelectedItem == null)
                            {
                                PickerBULCurrency.Focus();
                            }
                        }
                        else
                        {
                            EntryAmount.Focus();
                        }
                    };

                    if (ex.Message == AppResources.InsufficientBULs)
                    {
                        ShowErrorMessage(AppResources.PurchaseBULs, false, handler, AppResources.Purchase);
                    }
                    else
                    {
                        ShowErrorMessage(ex.Message, false, handler);
                    }
                }

                App.ShowLoading(false);

                EnableDisableButton();
            }
        }
Ejemplo n.º 9
0
        private async void OnVerify(object sender, EventArgs e)
        {
            if (!ValidationHelper.ValidateTextField(entryCode.Text))
            {
                entryCode.Focus();
            }
            else
            {
                Unfocus();

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

                var page = new WaitingAccountCreationPage();
                await Navigation.PushAsync(page, false);

                await Task.Delay(1000);

                try
                {
                    var result = await App.Locator.IdentityServiceClient.VerifyCode(entryCode.Text);

                    if (result != null)
                    {
                        var trusted = await StellarHelper.CheckTokenTrusted();

                        if (trusted)
                        {
                            page.OpenMainPage();
                        }
                        else
                        {
                            var added = await StellarHelper.AddTrustToken(App.Locator.Profile.KeyPair);

                            if (added)
                            {
                                page.OpenMainPage();
                            }
                            else
                            {
                                page.GoBack();

                                ShowErrorMessage(AppResources.ErrorAddTrustToken);
                            }
                        }
                    }
                    else
                    {
                        page.GoBack();
                    }
                }
                catch (Exception ex)
                {
                    page.GoBack();

                    ShowErrorMessage(ex.Message);
                }
            }
        }
Ejemplo n.º 10
0
        private async void AcceptClicked(object sender, System.EventArgs e)
        {
            App.ShowLoading(true);

            var myPubkey = App.Locator.Profile.Pubkey;

            string location = null;

            var hasPermission = await Utils.CheckPermissions(Plugin.Permissions.Abstractions.Permission.Location);

            if (hasPermission)
            {
                var locator = CrossGeolocator.Current;

                var position = await locator.GetPositionAsync();

                if (position != null)
                {
                    location = position.Latitude.ToString(System.Globalization.CultureInfo.InvariantCulture) + "," + position.Longitude.ToString(System.Globalization.CultureInfo.InvariantCulture);
                }
            }

            if (myPubkey == ViewModel.RecipientPubkey)
            {
                //I'm a recipient

                var result = await StellarHelper.AcceptPackageAsRecipient(BarcodeData.EscrowAddress, ViewModel.PaymentTransaction, location);

                if (result == StellarOperationResult.Success)
                {
                    await System.Threading.Tasks.Task.Delay(2000);

                    await App.Locator.Packages.Load();

                    ShowMessage(AppResources.PackageAccepted);

                    await Navigation.PopToRootAsync();
                }
                else
                {
                    ShowError(result);
                }

                App.ShowLoading(false);
            }
            else
            {
                //I'm a courier
                var result = await StellarHelper.AcceptPackageAsCourier(BarcodeData.EscrowAddress, ViewModel.Collateral, ViewModel.PaymentTransaction, location);

                if (result == StellarOperationResult.Success)
                {
                    await System.Threading.Tasks.Task.Delay(2000);

                    await App.Locator.Packages.Load();

                    ShowMessage(AppResources.PackageAccepted);

                    await Navigation.PopToRootAsync();
                }
                else
                {
                    EventHandler handler = (se, ee) => {
                        if (ee != null)
                        {
                            ShowPurchaseBuls();
                        }
                    };

                    if (result == StellarOperationResult.LowBULsCourier)
                    {
                        ShowErrorMessage(AppResources.PurchaseBULs, false, handler, AppResources.Purchase);
                    }
                    else
                    {
                        ShowError(result);
                    }
                }

                App.ShowLoading(false);
            }
        }
Ejemplo n.º 11
0
        private async void AssignClicked(object sender, System.EventArgs e)
        {
            Unfocus();

            App.Locator.Packages.StopTimer();

            ProgressBar.Progress         = 0;
            ProgressLabel.Text           = AppResources.LaunchPackageStep0;
            ProgressView.BackgroundColor = new Color(0, 0, 0, 0.7);
            ProgressView.IsVisible       = true;

            var myPubkey = App.Locator.Profile.Pubkey;

            string location = null;

            var hasPermission = await Utils.CheckPermissions(Plugin.Permissions.Abstractions.Permission.Location);

            if (hasPermission)
            {
                var locator = CrossGeolocator.Current;

                var position = await locator.GetPositionAsync();

                if (position != null)
                {
                    location = position.Latitude.ToString(System.Globalization.CultureInfo.InvariantCulture) + "," + position.Longitude.ToString(System.Globalization.CultureInfo.InvariantCulture);
                }
            }

            //I'm a courier
            var result = await StellarHelper.AssignPackage(ViewModel.PaketId, ViewModel.Collateral, location, FinalizePackageEvents);

            if (result == StellarOperationResult.Success)
            {
                await System.Threading.Tasks.Task.Delay(2000);

                await App.Locator.Packages.Load();

                MessagingCenter.Send(this, Constants.PACKAGE_ASSIGN, ViewModel.PaketId);

                ShowMessage(AppResources.PackageAssigned);

                await Navigation.PopToRootAsync();
            }
            else
            {
                EventHandler handler = (se, ee) => {
                    if (ee != null)
                    {
                        ShowPurchaseBuls();
                    }
                };

                if (result == StellarOperationResult.LowBULsCourier)
                {
                    ShowErrorMessage(AppResources.PurchaseBULs, false, handler, AppResources.Purchase);
                }
                else
                {
                    ShowError(result);
                }
            }

            ProgressView.IsVisible = false;

            App.Locator.Packages.StartTimer();
        }
Ejemplo n.º 12
0
        private async void CreateClicked(object sender, System.EventArgs e)
        {
            if (EntryRecepient.IsBusy)
            {
                return;
            }

            if (IsValid())
            {
                if (recipient.Length == 0)
                {
                    if (recipient.Length == 0)
                    {
                        EntryRecepient.FocusField();
                    }
                    return;
                }

                Unfocus();

                ProgressBar.Progress         = 0;
                ProgressLabel.Text           = AppResources.LaunchPackageStep0;
                ProgressView.BackgroundColor = new Color(0, 0, 0, 0.7);
                ProgressView.IsVisible       = true;

                var vm = ViewModel;

                var escrowKP = KeyPair.Random();

                try{
                    App.Locator.Wallet.StopTimer();
                    App.Locator.Packages.StopTimer();

                    double payment    = double.Parse(EntryPayment.Text);
                    double collateral = double.Parse(EntryCollateral.Text);

                    string location = null;

                    var hasPermission = await Utils.CheckPermissions(Plugin.Permissions.Abstractions.Permission.Location);

                    if (hasPermission)
                    {
                        var locator = CrossGeolocator.Current;
                        //  locator.DesiredAccuracy = DesiredAccuracy.Value;

                        var position = await locator.GetPositionAsync();

                        if (position != null)
                        {
                            location = position.Latitude.ToString("F7", System.Globalization.CultureInfo.InvariantCulture) + "," + position.Longitude.ToString("F7", System.Globalization.CultureInfo.InvariantCulture);
                        }
                    }

                    var result = await StellarHelper.CreatePackage(escrowKP, recipient, ViewModel.LauncherFullPhoneNumber, ViewModel.RecipientFullPhoneNumber, EntryDescription.Text, ViewModel.FromLocationAddress, ViewModel.ToLocationAddress, vm.Deadline, payment, collateral, location, ViewModel.FromLocationGPS, ViewModel.ToLocationGPS, PhotoSource, LaunchPackageEvents);

                    if (result == StellarOperationResult.Success)
                    {
                        App.Locator.DeviceService.IsNeedAlertDialogToCloseLaunchPackage = false;

                        await System.Threading.Tasks.Task.Delay(2000);

                        await App.Locator.Packages.Load();

                        await Navigation.PopAsync();
                    }
                    else if (result == StellarOperationResult.LowBULsLauncher)
                    {
                        EventHandler handler = (se, ee) => {
                            if (ee != null)
                            {
                                ShowPurchaseBuls();
                            }
                        };

                        ShowErrorMessage(AppResources.PurchaseBULs, false, handler, AppResources.Purchase);
                    }
                    else
                    {
                        ShowError(result);
                    }
                }
                catch (Exception exc)
                {
                    EventHandler handler = (se, ee) => {
                        if (ee != null)
                        {
                            ShowPurchaseBuls();
                        }
                    };

                    if (exc.Message == AppResources.InsufficientBULs)
                    {
                        ShowErrorMessage(AppResources.PurchaseBULs, false, handler, AppResources.Purchase);
                    }
                    else
                    {
                        ShowErrorMessage(exc.Message);
                    }
                }

                ProgressView.IsVisible = false;

                App.Locator.Wallet.StartTimer();
                App.Locator.Packages.StartTimer();
            }
        }