private async void ExecuteCoffeePurchase() { Console.WriteLine($"CoffeeMaker: {CoffeeMaker}, Program: {SelectedCoffeeProgram}, NumberOfCoffees: {NumberOfCoffees}"); Console.WriteLine($"Sender: {_web3.TransactionManager.Account.Address}"); if (CoffeeMaker.IsNullOrEmpty() || !CoffeeMaker.IsValidEthereumAddress() || SelectedCoffeeProgram < 0 || NumberOfCoffees <= 0) { Console.WriteLine("Invalid input for transaction. Aborting."); return; } var costs = CoffeePrograms[SelectedCoffeeProgram].Price * NumberOfCoffees; if ((await _coffeeEconomyService.GetTokensAsync(_account.Address)) < costs) { Console.WriteLine("Not enough coffee tokens to buy this much coffee."); return; } IsBusy = true; var transactionId = await _coffeeEconomyService.BuyCoffeeAsync(CoffeeMaker, SelectedCoffeeProgram, NumberOfCoffees); Console.WriteLine($"TransactionId: {transactionId}"); CoffeeMaker = null; ResetLoadedVariables(); IsBusy = false; }
private async void LoadCoffeeMakerPrograms() { if (CoffeeMaker.IsNullOrEmpty() || !CoffeeMaker.IsValidEthereumAddress()) { return; } try { var details = await _coffeeEconomyService.GetCoffeeMakerDataAsync(CoffeeMaker); if (details == null) { return; } CoffeeMakerDetails = details; var programs = await _coffeeEconomyService.GetCoffeeMakerProgramCountAsync(CoffeeMaker); Console.WriteLine($"Found {programs} coffee programs!"); if (programs > 0) { var list = new List <CoffeeMakerProgram>(); for (int i = 0; i < programs; i++) { var program = await _coffeeEconomyService.GetCoffeeMakerProgramDetailsAsync(CoffeeMaker, i); list.Add(program); Console.WriteLine($"Coffee program: {program.Name}, Price: {program.Price}"); } CoffeePrograms = list; SelectedCoffeeProgram = 0; // add the discovered coffee maker to our list of known coffee makers but only if it is a valid one var extendedCoffeeMakerDetails = new Models.CoffeeMaker { Address = CoffeeMaker, OwenerAddress = details.OwenerAddress, Name = details.Name, Department = details.Department, DescriptiveLocation = details.DescriptiveLocation, Latitude = details.Latitude, Longitude = details.Longitude, MachineInfo = details.MachineInfo, MachineType = details.MachineType, }; _coffeeMakerStorageService.AddOrUpdateCoffeeMakerDetails(extendedCoffeeMakerDetails); } } catch (Exception) { // reset our view data ResetLoadedVariables(); } }