Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
BuyEDalerViewModel.cs
1using CommunityToolkit.Mvvm.ComponentModel;
2using CommunityToolkit.Mvvm.Input;
6using System.ComponentModel;
7using Waher.Content;
8
10{
14 public partial class BuyEDalerViewModel : XmppViewModel
15 {
16 private readonly TaskCompletionSource<decimal?>? result;
17 private bool buyButtonPressed = false;
18
24 : base()
25 {
26 this.Currency = Args?.Currency;
27 this.result = Args?.Result;
28 this.Amount = 0;
29 this.AmountText = string.Empty;
30 this.AmountOk = false;
31 }
32
34 protected override async Task OnDispose()
35 {
36 this.result?.TrySetResult(this.buyButtonPressed ? this.Amount : null);
37
38 await base.OnDispose();
39 }
40
41 partial void OnAmountTextChanged(string? value)
42 {
43 if (CommonTypes.TryParse(this.AmountText, out decimal d) && d > 0)
44 {
45 this.Amount = d;
46 this.AmountOk = true;
47 }
48 else
49 this.AmountOk = false;
50 }
51
52 #region Properties
53
57 [ObservableProperty]
58 private decimal amount;
59
63 [ObservableProperty]
64 [NotifyPropertyChangedFor(nameof(this.AmountEntryValid))]
65 [NotifyCanExecuteChangedFor(nameof(BuyCommand))]
66 private bool amountOk;
67
71 [ObservableProperty]
72 private string? amountText;
73
77 public bool AmountEntryValid => this.AmountOk || string.IsNullOrEmpty(this.AmountText);
78
82 [ObservableProperty]
83 private string? currency;
84
85 #endregion
86
91 [RelayCommand]
92 public async Task OpenCalculator(object Parameter)
93 {
94 try
95 {
96 switch (Parameter?.ToString())
97 {
98 case "AmountText":
99 CalculatorNavigationArgs Args = new(this, nameof(this.AmountText));
100
101 await ServiceRef.UiService.GoToAsync(nameof(CalculatorPage), Args, BackMethod.Pop);
102 break;
103 }
104 }
105 catch (Exception ex)
106 {
108 }
109 }
110
114 [RelayCommand(CanExecute = nameof(AmountOk))]
115 private async Task Buy()
116 {
117 this.buyButtonPressed = true;
118 await this.GoBack();
119 }
120
121 }
122}
Base class that references services in the app.
Definition: ServiceRef.cs:31
static IUiService UiService
Service serializing and managing UI-related tasks.
Definition: ServiceRef.cs:55
virtual async Task GoBack()
Method called when user wants to navigate to the previous screen.
A page that allows the user to calculate the value of a numerical input field.
Holds navigation parameters specific to buying eDaler.
TaskCompletionSource< decimal?>? Result
Amount, or null if user cancels operation.
The view model to bind to for buying eDaler.
override async Task OnDispose()
Method called when the view is disposed, and will not be used more. Use this method to unregister eve...
BuyEDalerViewModel(BuyEDalerNavigationArgs? Args)
Creates an instance of the BuyEDalerViewModel class.
async Task OpenCalculator(object Parameter)
Opens the calculator for calculating the value of a numerical property.
bool AmountEntryValid
If amount entry should show an error
A view model that holds the XMPP state.
Helps with parsing of commong data types.
Definition: CommonTypes.cs:13
static bool TryParse(string s, out double Value)
Tries to decode a string encoded double.
Definition: CommonTypes.cs:46
Task DisplayException(Exception Exception, string? Title=null)
Displays an alert/message box to the user.
Task GoToAsync(string Route, BackMethod BackMethod=BackMethod.Inherited, string? UniqueId=null)
Navigates the AppShell to the specified route, with page arguments to match.
BackMethod
Navigation Back Method
Definition: BackMethod.cs:7
delegate string ToString(IElement Element)
Delegate for callback methods that convert an element value to a string.