Pass authorization logic to base class
MODIFY
WalletWasabi.Fluent/ViewModels/Dialogs/Authorization/AuthorizationDialogBase.cs
WalletWasabi.Fluent/ViewModels/Dialogs/Authorization/AuthorizationDialogBase.cs
@@ -4,13 +4,15 @@ using WalletWasabi.Fluent.ViewModels.Dialogs.Base;
namespace WalletWasabi.Fluent.ViewModels.Dialogs.Authorization;
-public abstract class AuthorizationDialogBase : DialogViewModelBase<bool>
+public abstract partial class AuthorizationDialogBase : DialogViewModelBase<bool>
{
+ [AutoNotify] private string _errorMessage = "";
+
protected AuthorizationDialogBase()
{
NextCommand = ReactiveCommand.CreateFromTask(async () =>
{
- var result = await Authorize();
+ var result = await AuthorizeCore();
if (result)
{
Close(DialogResultKind.Normal, result);
@@ -20,5 +22,19 @@ public abstract class AuthorizationDialogBase : DialogViewModelBase<bool>
EnableAutoBusyOn(NextCommand);
}
+ protected abstract string AuthorizationFailedMessage { get; }
+
protected abstract Task<bool> Authorize();
+
+ private async Task<bool> AuthorizeCore()
+ {
+ var success = await Authorize();
+
+ if (!success)
+ {
+ ErrorMessage = AuthorizationFailedMessage;
+ }
+
+ return success;
+ }
}
\ No newline at end of file

MODIFY
WalletWasabi.Fluent/ViewModels/Dialogs/Authorization/HardwareWalletAuthDialogViewModel.cs
WalletWasabi.Fluent/ViewModels/Dialogs/Authorization/HardwareWalletAuthDialogViewModel.cs
@@ -55,4 +55,6 @@ public partial class HardwareWalletAuthDialogViewModel : AuthorizationDialogBase
return false;
}
}
+
+ protected override string AuthorizationFailedMessage => $"Authorization failed.{Environment.NewLine}Please, check that your device is connected and try again.";
}

MODIFY
WalletWasabi.Fluent/ViewModels/Dialogs/Authorization/PasswordAuthDialogViewModel.cs
WalletWasabi.Fluent/ViewModels/Dialogs/Authorization/PasswordAuthDialogViewModel.cs
-using System.Reactive.Concurrency;
-using System.Reactive.Linq;
using System.Threading.Tasks;
-using WalletWasabi.Fluent.Validation;
using WalletWasabi.Userfacing;
using WalletWasabi.Wallets;
@@ -12,7 +9,6 @@ public partial class PasswordAuthDialogViewModel : AuthorizationDialogBase
{
private readonly Wallet _wallet;
[AutoNotify] private string _password;
- [AutoNotify] private string _errorMessage;
public PasswordAuthDialogViewModel(Wallet wallet)
{
@@ -34,15 +30,10 @@ public partial class PasswordAuthDialogViewModel : AuthorizationDialogBase
Password = "";
}
- protected override async Task<bool> Authorize()
- {
- var result = await Task.Run(() => PasswordHelper.TryPassword(_wallet.KeyManager, Password, out _));
+ protected override string AuthorizationFailedMessage => $"The password is incorrect.{Environment.NewLine}Please, Try Again.";
- if (!result)
+ protected override async Task<bool> Authorize()
{
- ErrorMessage = "The password is incorrect! Try Again.";
- }
-
- return result;
+ return await Task.Run(() => PasswordHelper.TryPassword(_wallet.KeyManager, Password, out _));
}
}

MODIFY
WalletWasabi.Fluent/Views/Dialogs/Authorization/HardwareWalletAuthDialogView.axaml
WalletWasabi.Fluent/Views/Dialogs/Authorization/HardwareWalletAuthDialogView.axaml
EnableNext="True" NextContent="Continue"
IsBusy="{Binding IsBusy}"
ScrollViewer.VerticalScrollBarVisibility="Disabled">
+ <StackPanel>
<Viewbox MaxHeight="150">
<Image Source="{Binding WalletType, Converter={x:Static conv:WalletIconConverter.WalletTypeToImage}}" />
</Viewbox>
+ <TextBlock TextAlignment="Center" Foreground="{StaticResource SystemErrorTextColor}"
+ Text="{Binding ErrorMessage}"
+ TextWrapping="Wrap"
+ IsVisible="{Binding ErrorMessage, Converter={x:Static ObjectConverters.IsNotNull}}" />
+ </StackPanel>
</c:ContentArea>
</UserControl>

MODIFY
WalletWasabi.Fluent/Views/Dialogs/Authorization/PasswordAuthDialogView.axaml
WalletWasabi.Fluent/Views/Dialogs/Authorization/PasswordAuthDialogView.axaml
</i:Interaction.Behaviors>
</TextBox>
<TextBlock TextAlignment="Center" Foreground="{StaticResource SystemErrorTextColor}"
+ TextWrapping="Wrap"
Text="{Binding ErrorMessage}"
IsVisible="{Binding ErrorMessage, Converter={x:Static ObjectConverters.IsNotNull}}" />
</StackPanel>

Pass authorization logic to base class