public TransactionPage()
        {
            _blockchainService = new UNBlockchainService();
            InitializeComponent();

            EntryPrivateKey.Text = Application.Current.Properties["Key"].ToString();
            ButtonSend.Clicked  += async(sender, args) =>
            {
                Loading.IsRunning = true;
                try
                {
                    var privateKey = EntryPrivateKey.Text;
                    var address    = EntryAddress.Text;
                    var amount     = Convert.ToDecimal(EntryAmount.Text);

                    var transferVm = new TransactionVm
                    {
                        Secret    = privateKey,
                        ToAddress = address,
                        Amount    = amount
                    };


                    var result = await _blockchainService.Transfer(transferVm);

                    if (result == "No ha sido posible ejecutar la transacción.")
                    {
                        await DisplayAlert("Error", result, "OK");
                    }
                    else
                    {
                        await DisplayAlert("Éxito", result, "OK");

                        var newBalance = await _blockchainService.GetAccountBalance(Application.Current.Properties["Address"].ToString());

                        Application.Current.Properties["Balance"] = "$ " + newBalance;


                        Application.Current.MainPage = new MasterPage();
                    }
                    Loading.IsRunning = false;
                }
                catch (Exception ex)
                {
                    await DisplayAlert("Error", "Ha ocurrido un error inesperado", "OK");

                    Loading.IsRunning = false;
                }
            };
        }
Exemplo n.º 2
0
        public MainPage()
        {
            _blockchainService = new UNBlockchainService();
            InitializeComponent();

            ButtonNewAccount.Clicked += async(sender, args) =>
            {
                Loading.IsRunning = true;
                try
                {
                    var result = await _blockchainService.CreateAccount();

                    if (result == "No ha sido posible crear la cuenta.")
                    {
                        await DisplayAlert("Error", result, "OK");
                    }
                    else
                    {
                        await DisplayAlert("Éxito", $"Cuenta creada exitosamente con llave privada { result }. Conéctate a MetaMask para conocer tu dirección", "OK");

                        EntryKey.Text = result;
                    }
                }
                catch (Exception ex)
                {
                    await DisplayAlert("Error", "Ha ocurrido un error inesperado", "OK");
                }

                Loading.IsRunning = false;
            };

            ButtonLogin.Clicked += async(sender, args) =>
            {
                Loading.IsRunning = true;

                Application.Current.Properties["Name"]    = EntryName.Text;
                Application.Current.Properties["Address"] = EntryAddress.Text;
                Application.Current.Properties["Key"]     = EntryKey.Text;
                Application.Current.Properties["Balance"] = "$0,0000";

                try
                {
                    var result = await _blockchainService.GetAccountBalance(EntryAddress.Text);

                    if (result == "No ha sido posible obtener el saldo.")
                    {
                        await DisplayAlert("Error", result, "OK");
                    }
                    else
                    {
                        Application.Current.Properties["Balance"] = "$ " + result;
                    }
                }
                catch (Exception ex)
                {
                    await DisplayAlert("Error", "Ha ocurrido un error inesperado", "OK");
                }

                Application.Current.MainPage = new MasterPage();
            };
        }