1using System.Collections.ObjectModel;
2using System.ComponentModel;
5using CommunityToolkit.Mvvm.ComponentModel;
6using CommunityToolkit.Mvvm.Input;
10using Microsoft.Extensions.DependencyInjection;
11using Microsoft.Maui.Controls.Shapes;
52 #region Observable Properties
63 [NotifyPropertyChangedFor(nameof(
Currency))]
70 private bool isRefreshingBalance;
82 private bool showBottomNavigation =
true;
86 #region Computed Properties
91 public string Currency => this.FetchedBalance?.Currency ??
"NC";
113 : this.ReservedDecimal +
" " + this.
Currency;
122 #region Tasks & Refresh Policy
136 await base.OnInitializeAsync();
139 ServiceRef.XmppService.EDalerBalanceUpdated += this.Wallet_BalanceUpdated;
148 await base.OnAppearingAsync();
150 this.GetBalanceTask.Load(this.LoadBalanceAsync);
162 ServiceRef.XmppService.EDalerBalanceUpdated -= this.Wallet_BalanceUpdated;
164 await base.OnDisposeAsync();
169 #region Property Change Logic
174 base.OnPropertyChanged(e);
176 if (e.PropertyName == nameof(this.IsConnected))
178 this.BuyEdalerCommand.NotifyCanExecuteChanged();
179 this.SendEdalerCommand.NotifyCanExecuteChanged();
190 [RelayCommand(AllowConcurrentExecutions =
false, CanExecute = nameof(IsConnected))]
191 private async Task BuyEdaler()
199 if (ServiceProviders.Length == 0)
207 List<IBuyEDalerServiceProvider> ServiceProviders2 = [];
208 ServiceProviders2.AddRange(ServiceProviders);
209 ServiceProviders2.Add(
new EmptyBuyEDalerServiceProvider());
212 ServiceProvidersNavigationArgs SelectionArgs =
new(
213 ServiceProviders.ToArray(),
219 if (SelectionArgs.ServiceProvider is
null)
227 if (!await this.authenticationService.AuthenticateUserAsync(
AuthenticationPurpose.ApplyForOrganizationalId))
237 else if (
string.IsNullOrEmpty(
ServiceProvider.BuyEDalerTemplateContractId))
239 TaskCompletionSource<decimal?> Result =
new();
244 decimal? Amount = await Result.Task;
245 if (!Amount.HasValue)
248 if (Amount.Value > 0)
255 if (Amount.HasValue && Amount.Value > 0)
257 ServiceRef.TagProfile.HasWallet =
true;
265 Dictionary<CaseInsensitiveString, object> Parameters =
new()
267 {
"Visibility",
"CreatorAndParts" },
270 {
"TrustProvider", e2.TrustProviderId }
282 IDictionary<CaseInsensitiveString, object>[] Options = await
OptionsTransaction.Wait();
286 MainThread.BeginInvokeOnMainThread(async () => await ContractOptionsPage.ShowContractOptions(Options));
299 [RelayCommand(AllowConcurrentExecutions =
false, CanExecute = nameof(IsConnected))]
300 private async Task SendEdaler()
306 StringBuilder Sb =
new();
307 Sb.Append(
"edaler:");
314 TaskCompletionSource<string?> UriToSend =
new();
315 TaskCompletionSource<string?> MessageToSend =
new();
319 string? Uri = await UriToSend.Task;
320 string? Message = await MessageToSend.Task;
321 if (
string.IsNullOrEmpty(Uri))
339 public async Task ViewMainPage()
343 if (Application.Current?.MainPage?.Navigation !=
null)
344 await Application.Current.MainPage.Navigation.PopToRootAsync();
353 public async Task ViewApps()
366 public async Task ViewRequestPayment()
383 private async Task OpenTransactionHistory()
398 #region Private Methods
404 private async Task LoadBalanceAsync(TaskContext<bool> Ctx)
413 MainThread.BeginInvokeOnMainThread(() =>
415 this.FetchedBalance = CurrentBalance;
416 this.BalanceUpdated = DateTime.Now;
417 ServiceRef.TagProfile.LastEDalerBalanceDecimal = this.BalanceDecimal;
418 ServiceRef.TagProfile.LastEDalerBalanceUpdate = DateTime.Now;
427 private async Task Wallet_BalanceUpdated(
object? sender,
BalanceEventArgs e)
429 await MainThread.InvokeOnMainThreadAsync(() =>
431 this.FetchedBalance = e.
Balance;
432 this.BalanceUpdated = DateTime.Now;
433 ServiceRef.TagProfile.LastEDalerBalanceDecimal = this.BalanceDecimal;
434 ServiceRef.TagProfile.LastEDalerBalanceUpdate = DateTime.Now;
Contains information about a balance.
CaseInsensitiveString Currency
Currency of amount.
Wallet balance event arguments.
Represents a transaction in the eDaler network.
Abstract base class for eDaler URIs
static bool TryParse(string Uri, out EDalerUri Result)
Tries to parse an eDaler URI
static readonly TimeSpan XmppConnect
XMPP Connect timeout
A set of never changing property constants and helpful values.
A strongly-typed resource class, for looking up localized strings, etc.
static string UnknownPleaseRefresh
Looks up a localized string similar to Unknown, please refresh.
static string SelectServiceProviderBuyEDaler
Looks up a localized string similar to Select the Service Provider you want to use to buy eDaler....
static string BuyEDaler
Looks up a localized string similar to Buy eDaler..
Base class that references services in the app.
static IServiceProvider Provider
The service provider for the app. This is set before the app is started, and will be used to resolve ...
static ILogService LogService
Log service.
static IUiService UiService
Service serializing and managing UI-related tasks.
static INavigationService NavigationService
The navigation service for navigating between pages.
static IPopupService PopupService
Popup service for presenting application popups.
static ITagProfile TagProfile
TAG Profile service.
static IContractOrchestratorService ContractOrchestratorService
Contract orchestrator service.
static IReportingStringLocalizer Localizer
Localization service
static IXmppService XmppService
The XMPP service for XMPP communication.
Provides a data-binding friendly mechanism to manage and report the status of asynchronous operations...
Main page for viewing apps.
Holds navigation parameters specific to buying eDaler.
A page that allows the user to buy eDaler.
Holds navigation parameters specific to an eDaler balance event.
Holds navigation parameters specific to eDaler URIs.
ViewModel for the Wallet page, handling balance display, buy flow, and related navigation.
string BalanceString
Balance formatted with currency.
ObservableTask< bool > GetBalanceTask
Wraps the balance fetch operation for async UI binding.
string Currency
Currency of current balance.
override async Task OnDisposeAsync()
Method called when the view is disposed, and will not be used more. Use this method to unregister eve...
string ReservedString
Reserved formatted.
override void OnPropertyChanged(PropertyChangedEventArgs e)
override async Task OnInitializeAsync()
Method called when view is initialized for the first time. Use this method to implement registration ...
override async Task OnAppearingAsync()
Method called when view is appearing on the screen.
decimal BalanceDecimal
Exposes the current balance as a decimal.
bool HasReserved
If there is a reserved amount. Only show once balance fetch is complete.
decimal ReservedDecimal
Reserved amount.
A page that displays information about eDaler received.
A page that allows the user to realize payments.
A page that allows the user to view its tokens.
Page presenting the user's transaction history.
A view model that holds the XMPP state.
Event arguments for callback methods to token creation attributes queries.
Contains information about a service provider.
string Type
Type of service provider.
string Id
ID of service provider.
Interface for information about a service provider that users can use to buy eDaler.
Task GoToAsync(string Route)
Navigates to the specified route and pushes the page onto the navigation stack.
BaseContentPage? CurrentPage
Gets the current visible view.
Task DisplayException(Exception Exception, string? Title=null)
Displays an alert/message box to the user.
Interface for pages that can receive contract options from an asynchronous process.
BackMethod
Navigation Back Method
class OptionsTransaction(string TransactionId)
Maintains the status of an ongoing retrieval of payment options.
class PaymentTransaction(string TransactionId, string Currency)
Maintains the status of an ongoing payment transaction.
AuthenticationPurpose
Purpose for requesting the user to authenticate itself.