Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
SellEDalerViewModel.cs
1using CommunityToolkit.Mvvm.ComponentModel;
2using CommunityToolkit.Mvvm.Input;
6using System.ComponentModel;
7using Waher.Content;
8
10{
14 public partial class SellEDalerViewModel : XmppViewModel
15 {
16 private readonly TaskCompletionSource<decimal?>? result;
17 private bool sellButtonPressed = false;
18
24 : base()
25 {
26 this.Currency = Args?.Currency;
27 this.result = Args?.Result;
28
29 this.Amount = 0;
30 this.AmountText = string.Empty;
31 this.AmountOk = false;
32 }
33
35 public override async Task OnDisposeAsync()
36 {
37 this.result?.TrySetResult(this.sellButtonPressed ? this.Amount : null);
38
39 await base.OnDisposeAsync();
40 }
41
42 #region Properties
43
47 [ObservableProperty]
48 private decimal amount;
49
53 [ObservableProperty]
54 private bool amountOk;
55
59 [ObservableProperty]
60 private string? amountText;
61
62 protected override void OnPropertyChanged(PropertyChangedEventArgs e)
63 {
64 base.OnPropertyChanged(e);
65
66 switch (e.PropertyName)
67 {
68 case nameof(this.AmountText):
69 if (CommonTypes.TryParse(this.AmountText, out decimal d) && d > 0)
70 {
71 this.Amount = d;
72 this.AmountOk = true;
73 }
74 else
75 {
76 this.AmountOk = false;
77 }
78 break;
79 }
80 }
81
85 [ObservableProperty]
86 private string? currency;
87
88 #endregion
89
94 [RelayCommand]
95 public async Task OpenCalculator(object Parameter)
96 {
97 try
98 {
99 switch (Parameter?.ToString())
100 {
101 case "AmountText":
102 CalculatorNavigationArgs Args = new(this, nameof(this.AmountText));
103
105 break;
106 }
107 }
108 catch (Exception ex)
109 {
111 }
112 }
113
117 [RelayCommand(CanExecute = nameof(AmountOk))]
118 private async Task Sell()
119 {
120 this.sellButtonPressed = true;
121 await this.GoBack();
122 }
123
124 }
125}
Base class that references services in the app.
Definition: ServiceRef.cs:43
static IUiService UiService
Service serializing and managing UI-related tasks.
Definition: ServiceRef.cs:130
static INavigationService NavigationService
The navigation service for navigating between pages.
Definition: ServiceRef.cs:178
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 selling eDaler.
TaskCompletionSource< decimal?>? Result
Amount, or null if user cancels operation.
override async Task OnDisposeAsync()
Method called when the view is disposed, and will not be used more. Use this method to unregister eve...
async Task OpenCalculator(object Parameter)
Opens the calculator for calculating the value of a numerical property.
SellEDalerViewModel(SellEDalerNavigationArgs? Args)
Creates an instance of the SellEDalerViewModel class.
A view model that holds the XMPP state.
Helps with parsing of commong data types.
Definition: CommonTypes.cs:15
Task GoToAsync(string Route)
Navigates to the specified route and pushes the page onto the navigation stack.
Task DisplayException(Exception Exception, string? Title=null)
Displays an alert/message box to the user.
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.