move pw check logic to wallet
MODIFY
WalletWasabi.Fluent/ViewModels/Login/LoginViewModel.cs
WalletWasabi.Fluent/ViewModels/Login/LoginViewModel.cs
using System.Threading.Tasks;
using System.Windows.Input;
using ReactiveUI;
-using WalletWasabi.Blockchain.Keys;
using WalletWasabi.Fluent.ViewModels.AddWallet;
using WalletWasabi.Fluent.ViewModels.Login.PasswordFinder;
using WalletWasabi.Fluent.ViewModels.Navigation;
using WalletWasabi.Fluent.ViewModels.Wallets;
+using WalletWasabi.Services;
using WalletWasabi.Userfacing;
namespace WalletWasabi.Fluent.ViewModels.Login
@@ -13,9 +13,6 @@ namespace WalletWasabi.Fluent.ViewModels.Login
[NavigationMetaData(Title = "Login")]
public partial class LoginViewModel : RoutableViewModel
{
- private readonly WalletManagerViewModel _walletManagerViewModel;
- private readonly ClosedWalletViewModel _closedWalletViewModel;
-
[AutoNotify] private string _password;
[AutoNotify] private bool _isPasswordIncorrect;
[AutoNotify] private bool _isPasswordNeeded;
@@ -23,58 +20,37 @@ namespace WalletWasabi.Fluent.ViewModels.Login
public LoginViewModel(WalletManagerViewModel walletManagerViewModel, ClosedWalletViewModel closedWalletViewModel)
{
- _walletManagerViewModel = walletManagerViewModel;
- _closedWalletViewModel = closedWalletViewModel;
-
- var wallet = _closedWalletViewModel.Wallet;
- var legalChecker = walletManagerViewModel.LegalChecker;
-
- KeyManager = wallet.KeyManager;
- IsPasswordNeeded = !KeyManager.IsWatchOnly;
-
+ var wallet = closedWalletViewModel.Wallet;
+ LegalChecker = walletManagerViewModel.LegalChecker;
+ IsPasswordNeeded = !wallet.KeyManager.IsWatchOnly;
_walletName = wallet.WalletName;
_password = "";
NextCommand = ReactiveCommand.CreateFromTask(async () =>
{
- IsPasswordIncorrect = await Task.Run(async () =>
- {
- if (!IsPasswordNeeded)
+ string? compatibilityPasswordUsed = null;
+
+ IsPasswordIncorrect = !await Task.Run(() => closedWalletViewModel.Wallet.TryLogin(Password, out compatibilityPasswordUsed));
+
+ if (IsPasswordIncorrect)
{
- return false;
+ return;
}
- if (PasswordHelper.TryPassword(KeyManager, Password, out var compatibilityPasswordUsed))
- {
if (compatibilityPasswordUsed is { })
{
await ShowErrorAsync(PasswordHelper.CompatibilityPasswordWarnMessage, "Compatibility password was used");
}
- return false;
- }
+ var legalResult = await ShowLegalAsync();
- return true;
- });
-
- if (!IsPasswordIncorrect)
- {
- if (legalChecker.TryGetNewLegalDocs(out var document))
- {
- var legalDocs = new TermsAndConditionsViewModel(document.Content);
-
- var dialogResult = await NavigateDialog(legalDocs, NavigationTarget.DialogScreen);
-
- if (dialogResult.Result)
+ if (legalResult)
{
- await legalChecker.AgreeAsync();
- await LoginWalletAsync();
- }
+ await LoginWalletAsync(walletManagerViewModel, closedWalletViewModel);
}
else
{
- await LoginWalletAsync();
- }
+ closedWalletViewModel.Wallet.Logout();
}
});
@@ -90,18 +66,17 @@ namespace WalletWasabi.Fluent.ViewModels.Login
EnableAutoBusyOn(NextCommand);
}
+ public LegalChecker LegalChecker { get; }
+
public ICommand OkCommand { get; }
public ICommand ForgotPasswordCommand { get; }
- public KeyManager KeyManager { get; }
-
- private async Task LoginWalletAsync()
+ private async Task LoginWalletAsync(WalletManagerViewModel walletManagerViewModel, ClosedWalletViewModel closedWalletViewModel)
{
- _closedWalletViewModel.Wallet.Login(Password);
- _closedWalletViewModel.RaisePropertyChanged(nameof(WalletViewModelBase.IsLoggedIn));
+ closedWalletViewModel.RaisePropertyChanged(nameof(WalletViewModelBase.IsLoggedIn));
- var destination = await _walletManagerViewModel.LoadWalletAsync(_closedWalletViewModel);
+ var destination = await walletManagerViewModel.LoadWalletAsync(closedWalletViewModel);
if (destination is { })
{
@@ -112,5 +87,24 @@ namespace WalletWasabi.Fluent.ViewModels.Login
await ShowErrorAsync("Error", "Wasabi was unable to login and load your wallet.");
}
}
+
+ private async Task<bool> ShowLegalAsync()
+ {
+ if (!LegalChecker.TryGetNewLegalDocs(out var document))
+ {
+ return true;
+ }
+
+ var legalDocs = new TermsAndConditionsViewModel(document.Content);
+
+ var dialogResult = await NavigateDialog(legalDocs, NavigationTarget.DialogScreen);
+
+ if (dialogResult.Result)
+ {
+ await LegalChecker.AgreeAsync();
+ }
+
+ return dialogResult.Result;
+ }
}
}

MODIFY
WalletWasabi/Wallets/Wallet.cs
WalletWasabi/Wallets/Wallet.cs
@@ -21,6 +21,7 @@ using WalletWasabi.Logging;
using WalletWasabi.Models;
using WalletWasabi.Services;
using WalletWasabi.Stores;
+using WalletWasabi.Userfacing;
using WalletWasabi.WebClients.PayJoin;
namespace WalletWasabi.Wallets
@@ -97,11 +98,22 @@ namespace WalletWasabi.Wallets
private Kitchen Kitchen { get; } = new();
- public void Login(string password)
+ public bool TryLogin(string password, out string? compatibilityPasswordUsed)
+ {
+ compatibilityPasswordUsed = null;
+
+ if (KeyManager.IsWatchOnly)
{
- Kitchen.Cook(password);
IsLoggedIn = true;
}
+ else if (PasswordHelper.TryPassword(KeyManager, password, out compatibilityPasswordUsed))
+ {
+ IsLoggedIn = true;
+ Kitchen.Cook(password);
+ }
+
+ return IsLoggedIn;
+ }
public void Logout() => IsLoggedIn = false;

move pw check logic to wallet