move logic to the proper viewmodel
MODIFY
WalletWasabi.Fluent/ViewModels/AddWallet/LegalDocumentsViewModel.cs
WalletWasabi.Fluent/ViewModels/AddWallet/LegalDocumentsViewModel.cs
+using System.Reactive.Concurrency;
+using System.Reactive.Disposables;
+using ReactiveUI;
using WalletWasabi.Fluent.ViewModels.Navigation;
+using WalletWasabi.Logging;
namespace WalletWasabi.Fluent.ViewModels.AddWallet;
@@ -15,14 +19,38 @@ public partial class LegalDocumentsViewModel : RoutableViewModel
{
[AutoNotify] private string? _content;
- public LegalDocumentsViewModel(string content)
+ public LegalDocumentsViewModel()
{
- Content = content;
-
SetupCancel(enableCancel: false, enableCancelOnEscape: false, enableCancelOnPressed: false);
EnableBack = true;
NextCommand = BackCommand;
}
+
+ protected override void OnNavigatedTo(bool isInHistory, CompositeDisposable disposables)
+ {
+ base.OnNavigatedTo(isInHistory, disposables);
+
+ RxApp.MainThreadScheduler.Schedule(async () =>
+ {
+ try
+ {
+ IsBusy = true;
+ var document = await Services.LegalChecker.WaitAndGetLatestDocumentAsync();
+ Content = document.Content;
+ }
+ catch (Exception ex)
+ {
+ if (ex is not OperationCanceledException)
+ {
+ Logger.LogError("Failed to get Legal documents.", ex);
+ }
+ }
+ finally
+ {
+ IsBusy = false;
+ }
+ });
+ }
}

MODIFY
WalletWasabi.Fluent/ViewModels/AddWallet/TermsAndConditionsViewModel.cs
WalletWasabi.Fluent/ViewModels/AddWallet/TermsAndConditionsViewModel.cs
@@ -10,9 +10,9 @@ public partial class TermsAndConditionsViewModel : DialogViewModelBase<bool>
{
[AutoNotify] private bool _isAgreed;
- public TermsAndConditionsViewModel(string legalDocument)
+ public TermsAndConditionsViewModel()
{
- ViewTermsCommand = ReactiveCommand.Create(() => OnViewTerms(legalDocument));
+ ViewTermsCommand = ReactiveCommand.Create(() => Navigate().To(new LegalDocumentsViewModel()));
NextCommand = ReactiveCommand.Create(
OnNext,
@@ -24,11 +24,6 @@ public partial class TermsAndConditionsViewModel : DialogViewModelBase<bool>
public ICommand ViewTermsCommand { get; }
- private void OnViewTerms(string legalDocument)
- {
- Navigate().To(new LegalDocumentsViewModel(legalDocument));
- }
-
private void OnNext()
{
Close(DialogResultKind.Normal, true);

MODIFY
WalletWasabi.Fluent/ViewModels/Login/LoginViewModel.cs
WalletWasabi.Fluent/ViewModels/Login/LoginViewModel.cs
@@ -95,12 +95,12 @@ public partial class LoginViewModel : RoutableViewModel
private async Task<bool> ShowLegalAsync()
{
- if (!Services.LegalChecker.TryGetNewLegalDocs(out var document))
+ if (!Services.LegalChecker.TryGetNewLegalDocs(out _))
{
return true;
}
- var legalDocs = new TermsAndConditionsViewModel(document.Content);
+ var legalDocs = new TermsAndConditionsViewModel();
var dialogResult = await NavigateDialogAsync(legalDocs, NavigationTarget.DialogScreen);

MODIFY
WalletWasabi.Fluent/ViewModels/MainViewModel.cs
WalletWasabi.Fluent/ViewModels/MainViewModel.cs
using System.Linq;
using System.Reactive.Concurrency;
using System.Reactive.Linq;
-using Avalonia;
using Avalonia.Controls;
using NBitcoin;
using ReactiveUI;
@@ -17,7 +16,6 @@ using WalletWasabi.Fluent.ViewModels.Settings;
using WalletWasabi.Fluent.ViewModels.StatusIcon;
using WalletWasabi.Fluent.ViewModels.TransactionBroadcasting;
using WalletWasabi.Fluent.ViewModels.Wallets;
-using WalletWasabi.Logging;
namespace WalletWasabi.Fluent.ViewModels;
@@ -223,27 +221,7 @@ public partial class MainViewModel : ViewModelBase
return null;
});
- RxApp.MainThreadScheduler.Schedule(async () =>
- {
- try
- {
- await Services.LegalChecker.WaitAndGetLatestDocumentAsync();
-
- LegalDocumentsViewModel.RegisterAsyncLazy(async () =>
- {
- var document = await Services.LegalChecker.WaitAndGetLatestDocumentAsync();
- return new LegalDocumentsViewModel(document.Content);
- });
- }
- catch (Exception ex)
- {
- if (ex is not OperationCanceledException)
- {
- Logger.LogError("Failed to get Legal documents.", ex);
- }
- }
- });
-
+ LegalDocumentsViewModel.RegisterLazy(() => new LegalDocumentsViewModel());
UserSupportViewModel.RegisterLazy(() => new UserSupportViewModel());
BugReportLinkViewModel.RegisterLazy(() => new BugReportLinkViewModel());
DocsLinkViewModel.RegisterLazy(() => new DocsLinkViewModel());

move logic to the proper viewmodel