Identify profiles
MODIFY
WalletWasabi.Fluent/ViewModels/CoinJoinProfiles/CoinJoinProfileViewModelBase.cs
WalletWasabi.Fluent/ViewModels/CoinJoinProfiles/CoinJoinProfileViewModelBase.cs
+using WalletWasabi.Blockchain.Keys;
+
namespace WalletWasabi.Fluent.ViewModels.CoinJoinProfiles;
public abstract class CoinJoinProfileViewModelBase : ViewModelBase
@@ -8,7 +10,25 @@ public abstract class CoinJoinProfileViewModelBase : ViewModelBase
public virtual int AnonScoreTarget { get; } = 5;
- public abstract int FeeRateMedianTimeFrameHours { get; }
+ public virtual int FeeRateMedianTimeFrameHours { get; }
+
+ public static bool operator ==(CoinJoinProfileViewModelBase x, CoinJoinProfileViewModelBase y)
+ {
+ if (x is null)
+ {
+ if (y is null)
+ {
+ return true;
+ }
+
+ // Only the left side is null.
+ return false;
+ }
+ // Equals handles case of null on right side.
+ return x.Equals(y);
+ }
+
+ public static bool operator !=(CoinJoinProfileViewModelBase x, CoinJoinProfileViewModelBase y) => !(x == y);
public override bool Equals(object? obj)
{

MODIFY
WalletWasabi.Fluent/ViewModels/CoinJoinProfiles/CoinJoinProfilesViewModel.cs
WalletWasabi.Fluent/ViewModels/CoinJoinProfiles/CoinJoinProfilesViewModel.cs
@@ -17,6 +17,13 @@ public partial class CoinJoinProfilesViewModel : DialogViewModelBase<bool>
[AutoNotify] private CoinJoinProfileViewModelBase? _selectedProfile;
[AutoNotify] private bool _autoCoinJoin;
+ private static CoinJoinProfileViewModelBase[] DefaultProfiles { get; } = new CoinJoinProfileViewModelBase[]
+ {
+ new EconomicCoinJoinProfileViewModel(),
+ new SpeedyCoinJoinProfileViewModel(),
+ new PrivateCoinJoinProfileViewModel()
+ };
+
public CoinJoinProfilesViewModel(KeyManager keyManager, bool isNewWallet)
{
NextCommand = ReactiveCommand.Create(() => OnNext(keyManager, isNewWallet));
@@ -24,35 +31,25 @@ public partial class CoinJoinProfilesViewModel : DialogViewModelBase<bool>
AutoCoinJoin = keyManager.AutoCoinJoin;
- Profiles = new()
- {
- new EconomicCoinJoinProfileViewModel(),
- new SpeedyCoinJoinProfileViewModel(),
- new PrivateCoinJoinProfileViewModel()
- };
+ Profiles = DefaultProfiles.ToList();
+
+ ManualSetupCommand = ReactiveCommand.CreateFromTask(async () => await OnManualSetupAsync());
if (isNewWallet)
{
_selectedProfile = Profiles[1];
+ return;
}
- else
- {
- _selectedProfile = Profiles.FirstOrDefault(x => x.Title == keyManager.CoinjoinProfile);
- if (_selectedProfile is PrivateCoinJoinProfileViewModel p)
- {
- Profiles.Remove(p);
- _selectedProfile = new PrivateCoinJoinProfileViewModel(keyManager.AnonScoreTarget);
- Profiles.Add(_selectedProfile);
+ _selectedProfile = IdentifySelectedProfile(keyManager);
}
- if (_selectedProfile is null && keyManager.CoinjoinProfile is { })
+ public static CoinJoinProfileViewModelBase IdentifySelectedProfile(KeyManager keyManager)
{
- SelectedManualProfile = new ManualCoinJoinProfileViewModel(keyManager.AnonScoreTarget, keyManager.FeeRateMedianTimeFrameHours);
- }
- }
+ var currentProfile = new ManualCoinJoinProfileViewModel(keyManager);
+ var result = DefaultProfiles.FirstOrDefault(x => x == currentProfile) ?? currentProfile;
- ManualSetupCommand = ReactiveCommand.CreateFromTask(async () => await OnManualSetupAsync());
+ return result;
}
public ICommand ManualSetupCommand { get; }
@@ -84,7 +81,6 @@ public partial class CoinJoinProfilesViewModel : DialogViewModelBase<bool>
keyManager.SetAnonScoreTarget(selected.AnonScoreTarget, toFile: false);
keyManager.SetFeeRateMedianTimeFrame(selected.FeeRateMedianTimeFrameHours, toFile: false);
keyManager.IsCoinjoinProfileSelected = true;
- keyManager.CoinjoinProfile = selected.Title;
if (isNewWallet)
{

MODIFY
WalletWasabi.Fluent/ViewModels/CoinJoinProfiles/ManualCoinJoinProfileViewModel.cs
WalletWasabi.Fluent/ViewModels/CoinJoinProfiles/ManualCoinJoinProfileViewModel.cs
+using WalletWasabi.Blockchain.Keys;
+
namespace WalletWasabi.Fluent.ViewModels.CoinJoinProfiles;
public class ManualCoinJoinProfileViewModel : CoinJoinProfileViewModelBase
@@ -8,6 +10,10 @@ public class ManualCoinJoinProfileViewModel : CoinJoinProfileViewModelBase
FeeRateMedianTimeFrameHours = feeRateMedianTimeFrameHours;
}
+ public ManualCoinJoinProfileViewModel(KeyManager keyManager) : this(keyManager.AnonScoreTarget, keyManager.FeeRateMedianTimeFrameHours)
+ {
+ }
+
public override string Title => "Custom";
public override string Description => "";

MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/WalletSettingsViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/WalletSettingsViewModel.cs
@@ -53,7 +53,11 @@ public partial class WalletSettingsViewModel : RoutableViewModel
SetAutoCoinJoin = ReactiveCommand.CreateFromTask(async () =>
{
- if (!_wallet.KeyManager.IsCoinjoinProfileSelected)
+ if (_wallet.KeyManager.IsCoinjoinProfileSelected)
+ {
+ AutoCoinJoin = !AutoCoinJoin;
+ }
+ else
{
await NavigateDialogAsync(new CoinJoinProfilesViewModel(_wallet.KeyManager, false), NavigationTarget.DialogScreen);
}
@@ -62,7 +66,6 @@ public partial class WalletSettingsViewModel : RoutableViewModel
{
_wallet.KeyManager.AutoCoinJoin = AutoCoinJoin;
_wallet.KeyManager.ToFile();
- this.RaisePropertyChanged(nameof(AutoCoinJoin));
}
else
{
@@ -116,17 +119,18 @@ public partial class WalletSettingsViewModel : RoutableViewModel
IsCoinjoinProfileSelected = _wallet.KeyManager.IsCoinjoinProfileSelected;
SelectedCoinjoinProfileName =
- (_wallet.KeyManager.IsCoinjoinProfileSelected, _wallet.KeyManager.CoinjoinProfile) switch
+ (_wallet.KeyManager.IsCoinjoinProfileSelected, CoinJoinProfilesViewModel.IdentifySelectedProfile(_wallet.KeyManager)) switch
{
- (true, string x) => x,
- (true, null) => "[unknown]",
- (false, _) => "none"
+ (true, CoinJoinProfileViewModelBase x) => x.Title,
+ (false, _) => "None",
+ _ => "Unknown"
};
}
private async Task SelectCoinjoinProfileAsync()
{
await NavigateDialogAsync(new CoinJoinProfilesViewModel(_wallet.KeyManager, false), NavigationTarget.DialogScreen);
+ AutoCoinJoin = _wallet.KeyManager.AutoCoinJoin;
}
private void ValidatePlebStopThreshold(IValidationErrors errors) =>

MODIFY
WalletWasabi/Blockchain/Keys/KeyManager.cs
WalletWasabi/Blockchain/Keys/KeyManager.cs
@@ -176,9 +176,6 @@ public class KeyManager
[JsonProperty(Order = 15, PropertyName = "IsCoinjoinProfileSelected")]
public bool IsCoinjoinProfileSelected { get; set; } = false;
- [JsonProperty(Order = 16, PropertyName = "CoinjoinProfile")]
- public string CoinjoinProfile { get; set; }
-
[JsonProperty(Order = 999)]
private List<HdPubKey> HdPubKeys { get; }

Identify profiles