implement a dialogresult, so we can know if back button or cancell button was pressed.
MODIFY
WalletWasabi.Fluent/ViewModels/AboutViewModel.cs
WalletWasabi.Fluent/ViewModels/AboutViewModel.cs
@@ -34,7 +34,7 @@ namespace WalletWasabi.Fluent.ViewModels
var interaction = new Interaction<Unit, Unit>();
interaction.RegisterHandler(
async x =>
- x.SetOutput(await new AboutAdvancedInfoViewModel().ShowDialogAsync()));
+ x.SetOutput((await new AboutAdvancedInfoViewModel().ShowDialogAsync()).Result));
AboutAdvancedInfoDialogCommand = ReactiveCommand.CreateFromTask(
execute: async () => await interaction.Handle(Unit.Default).ToTask());

MODIFY
WalletWasabi.Fluent/ViewModels/AddWallet/AddWalletPageViewModel.cs
WalletWasabi.Fluent/ViewModels/AddWallet/AddWalletPageViewModel.cs
@@ -75,10 +75,10 @@ namespace WalletWasabi.Fluent.ViewModels.AddWallet
CreateWalletCommand = ReactiveCommand.CreateFromTask(
async () =>
{
- var result = await NavigateDialog(
+ var dialogResult = await NavigateDialog(
new EnterPasswordViewModel("Type the password of the wallet and click Continue."));
- if (result is { } password)
+ if (dialogResult.Result is { } password)
{
IsBusy = true;

MODIFY
WalletWasabi.Fluent/ViewModels/AddWallet/RecoverWalletViewModel.cs
WalletWasabi.Fluent/ViewModels/AddWallet/RecoverWalletViewModel.cs
@@ -57,7 +57,7 @@ namespace WalletWasabi.Fluent.ViewModels.AddWallet
AdvancedOptionsInteraction.RegisterHandler(
async interaction =>
interaction.SetOutput(
- await new AdvancedRecoveryOptionsViewModel(interaction.Input).ShowDialogAsync()));
+ (await new AdvancedRecoveryOptionsViewModel(interaction.Input).ShowDialogAsync()).Result));
AdvancedRecoveryOptionsDialogCommand = ReactiveCommand.CreateFromTask(
async () =>
@@ -80,13 +80,13 @@ namespace WalletWasabi.Fluent.ViewModels.AddWallet
{
IsBusy = true;
- try
- {
- var result = await NavigateDialog(
+ var dialogResult = await NavigateDialog(
new EnterPasswordViewModel(
"Type the password of the wallet to be able to recover and click Continue."));
- if (result is { } password)
+ if (dialogResult.Result is { } password)
+ {
+ try
{
await Task.Run(
() =>
@@ -105,15 +105,22 @@ namespace WalletWasabi.Fluent.ViewModels.AddWallet
walletManager.AddWallet(keyManager);
});
- }
+
+ Navigate().To(new AddedWalletPageViewModel(walletName!, WalletType.Normal));
+
+ return;
}
catch (Exception ex)
{
Logger.LogError(ex);
}
- finally
+ }
+
+ IsBusy = false;
+
+ if (dialogResult.Kind == DialogResultKind.Cancel)
{
- Navigate().To(new AddedWalletPageViewModel(walletName!, WalletType.Normal));
+ Navigate().Clear();
}
}

MODIFY
WalletWasabi.Fluent/ViewModels/Dialogs/AdvancedRecoveryOptionsViewModel.cs
WalletWasabi.Fluent/ViewModels/Dialogs/AdvancedRecoveryOptionsViewModel.cs
@@ -41,7 +41,7 @@ namespace WalletWasabi.Fluent.ViewModels.Dialogs
BackCommand = ReactiveCommand.Create(() => Navigate().Back(), backCommandCanExecute);
NextCommand = ReactiveCommand.Create(
- () => Close((KeyPath.Parse(AccountKeyPath), int.Parse(MinGapLimit))),
+ () => Close(result: (KeyPath.Parse(AccountKeyPath), int.Parse(MinGapLimit))),
nextCommandCanExecute);
CancelCommand = ReactiveCommand.Create(() => Close(), cancelCommandCanExecute);

ADD
WalletWasabi.Fluent/ViewModels/Dialogs/DialogResult.cs
+namespace WalletWasabi.Fluent.ViewModels.Dialogs
+{
+ public struct DialogResult<TResult>
+ {
+ public DialogResult(TResult? result, DialogResultKind kind)
+ {
+ Result = result;
+ Kind = kind;
+ }
+
+ public TResult? Result;
+
+ public DialogResultKind Kind;
+ }
+}
\ No newline at end of file

ADD
WalletWasabi.Fluent/ViewModels/Dialogs/DialogResultKind.cs
+namespace WalletWasabi.Fluent.ViewModels.Dialogs
+{
+ public enum DialogResultKind
+ {
+ Normal,
+ Cancel,
+ Back
+ }
+}
\ No newline at end of file

MODIFY
WalletWasabi.Fluent/ViewModels/Dialogs/DialogViewModelBaseOfTResult.cs
WalletWasabi.Fluent/ViewModels/Dialogs/DialogViewModelBaseOfTResult.cs
@@ -14,23 +14,23 @@ namespace WalletWasabi.Fluent.ViewModels.Dialogs
public abstract class DialogViewModelBase<TResult> : DialogViewModelBase
{
private readonly IDisposable _disposable;
- private readonly TaskCompletionSource<TResult> _currentTaskCompletionSource;
+ private readonly TaskCompletionSource<DialogResult<TResult>> _currentTaskCompletionSource;
protected DialogViewModelBase()
{
- _currentTaskCompletionSource = new TaskCompletionSource<TResult>();
+ _currentTaskCompletionSource = new TaskCompletionSource<DialogResult<TResult>>();
_disposable = this.WhenAnyValue(x => x.IsDialogOpen)
.Skip(1) // Skip the initial value change (which is false).
.DistinctUntilChanged()
.Subscribe(OnIsDialogOpenChanged);
- CancelCommand = ReactiveCommand.Create(() => Close());
+ CancelCommand = ReactiveCommand.Create(() => Close(DialogResultKind.Cancel));
}
protected override void OnNavigatedFrom()
{
- Close();
+ Close(DialogResultKind.Cancel);
base.OnNavigatedFrom();
}
@@ -48,15 +48,15 @@ namespace WalletWasabi.Fluent.ViewModels.Dialogs
/// Method to be called when the dialog intends to close
/// and ready to pass a value back to the caller.
/// </summary>
- /// <param name="value">The return value of the dialog</param>
- protected void Close(TResult value = default)
+ /// <param name="result">The return value of the dialog</param>
+ protected void Close(DialogResultKind kind = DialogResultKind.Normal, TResult result = default)
{
if (_currentTaskCompletionSource.Task.IsCompleted)
{
return;
}
- _currentTaskCompletionSource.SetResult(value);
+ _currentTaskCompletionSource.SetResult(new DialogResult<TResult>(result, kind));
_disposable.Dispose();
@@ -69,7 +69,7 @@ namespace WalletWasabi.Fluent.ViewModels.Dialogs
/// Shows the dialog.
/// </summary>
/// <returns>The value to be returned when the dialog is finished.</returns>
- public Task<TResult> ShowDialogAsync(IDialogHost? host = null)
+ public Task<DialogResult<TResult>> ShowDialogAsync(IDialogHost? host = null)
{
if (host is null)
{
@@ -90,7 +90,7 @@ namespace WalletWasabi.Fluent.ViewModels.Dialogs
/// Gets the dialog result.
/// </summary>
/// <returns>The value to be returned when the dialog is finished.</returns>
- public Task<TResult> GetDialogResultAsync()
+ public Task<DialogResult<TResult>> GetDialogResultAsync()
{
IsDialogOpen = true;

MODIFY
WalletWasabi.Fluent/ViewModels/Dialogs/EnterPasswordViewModel.cs
WalletWasabi.Fluent/ViewModels/Dialogs/EnterPasswordViewModel.cs
@@ -40,9 +40,9 @@ namespace WalletWasabi.Fluent.ViewModels.Dialogs
var cancelCommandCanExecute = this.WhenAnyValue(x => x.IsDialogOpen).ObserveOn(RxApp.MainThreadScheduler);
- BackCommand = ReactiveCommand.Create(() => Close(), backCommandCanExecute);
- NextCommand = ReactiveCommand.Create(() => Close(Password), nextCommandCanExecute);
- CancelCommand = ReactiveCommand.Create(() => Close(), cancelCommandCanExecute);
+ BackCommand = ReactiveCommand.Create(() => Close(DialogResultKind.Back), backCommandCanExecute);
+ NextCommand = ReactiveCommand.Create(() => Close(result: Password), nextCommandCanExecute);
+ CancelCommand = ReactiveCommand.Create(() => Close(DialogResultKind.Cancel), cancelCommandCanExecute);
}
public string Subtitle { get; }

MODIFY
WalletWasabi.Fluent/ViewModels/Dialogs/TestDialogViewModel.cs
WalletWasabi.Fluent/ViewModels/Dialogs/TestDialogViewModel.cs
@@ -15,10 +15,10 @@ namespace WalletWasabi.Fluent.ViewModels.Dialogs
() => Navigate().Back(),
this.WhenAnyValue(x => x.IsDialogOpen).ObserveOn(RxApp.MainThreadScheduler));
CancelCommand = ReactiveCommand.Create(
- () => Close(false),
+ () => Close(result: false),
this.WhenAnyValue(x => x.IsDialogOpen).ObserveOn(RxApp.MainThreadScheduler));
NextCommand = ReactiveCommand.Create(
- () => Close(true),
+ () => Close(result: true),
this.WhenAnyValue(x => x.IsDialogOpen).ObserveOn(RxApp.MainThreadScheduler));
}
@@ -28,7 +28,7 @@ namespace WalletWasabi.Fluent.ViewModels.Dialogs
public void Close()
{
- Close(false);
+ Close(result: false);
}
}
}
\ No newline at end of file

MODIFY
WalletWasabi.Fluent/ViewModels/MainViewModel.cs
WalletWasabi.Fluent/ViewModels/MainViewModel.cs
@@ -157,9 +157,9 @@ namespace WalletWasabi.Fluent.ViewModels
BroadcastTransactionViewModel.RegisterAsyncLazy(
async () =>
{
- var result = await DialogScreen.NavigateDialog(new LoadTransactionViewModel(_global.Network));
+ var dialogResult = await DialogScreen.NavigateDialog(new LoadTransactionViewModel(_global.Network));
- if (result is { })
+ if (dialogResult.Result is { })
{
while (_global.TransactionBroadcaster is null)
{
@@ -172,7 +172,7 @@ namespace WalletWasabi.Fluent.ViewModels
_global.BitcoinStore,
_global.Network,
_global.TransactionBroadcaster,
- result);
+ dialogResult.Result);
}
DialogScreen.Back();

MODIFY
WalletWasabi.Fluent/ViewModels/Navigation/RoutableViewModel.cs
WalletWasabi.Fluent/ViewModels/Navigation/RoutableViewModel.cs
@@ -91,10 +91,10 @@ namespace WalletWasabi.Fluent.ViewModels.Navigation
{
}
- public async Task<TResult> NavigateDialog<TResult>(DialogViewModelBase<TResult> dialog)
+ public async Task<DialogResult<TResult>> NavigateDialog<TResult>(DialogViewModelBase<TResult> dialog)
=> await NavigateDialog(dialog, CurrentTarget);
- public async Task<TResult> NavigateDialog<TResult>(DialogViewModelBase<TResult> dialog, NavigationTarget target)
+ public async Task<DialogResult<TResult>> NavigateDialog<TResult>(DialogViewModelBase<TResult> dialog, NavigationTarget target)
{
Navigate(target).To(dialog);

MODIFY
WalletWasabi.Fluent/ViewModels/Navigation/TargettedNavigationStack.cs
WalletWasabi.Fluent/ViewModels/Navigation/TargettedNavigationStack.cs
@@ -5,7 +5,7 @@ namespace WalletWasabi.Fluent.ViewModels.Navigation
{
public static class NavigationExtensions
{
- public static async Task<T> NavigateDialog<T>(
+ public static async Task<DialogResult<T>> NavigateDialog<T>(
this TargettedNavigationStack stack,
DialogViewModelBase<T> dialog)
{

MODIFY
WalletWasabi.Fluent/ViewModels/TransactionBroadcasting/LoadTransactionViewModel.cs
WalletWasabi.Fluent/ViewModels/TransactionBroadcasting/LoadTransactionViewModel.cs
@@ -24,7 +24,7 @@ namespace WalletWasabi.Fluent.ViewModels.TransactionBroadcasting
this.WhenAnyValue(x => x.FinalTransaction)
.Where(x => x is { })
.ObserveOn(RxApp.MainThreadScheduler)
- .Subscribe(finalTransaction => Close(finalTransaction));
+ .Subscribe(finalTransaction => Close(result: finalTransaction));
ImportTransactionCommand = ReactiveCommand.CreateFromTask(
async () =>

implement a dialogresult, so we can know if back button or cancell button was pressed.