Simplify `HigestCoinJoinState`
MODIFY
WalletWasabi.Fluent/ViewModels/ApplicationViewModel.cs
WalletWasabi.Fluent/ViewModels/ApplicationViewModel.cs
@@ -83,7 +83,7 @@ public class ApplicationViewModel : ViewModelBase, ICanShutdownProvider
if (cjManager is { })
{
- return cjManager.GetHighestCoinJoinClientState() switch
+ return cjManager.HighestCoinJoinClientState switch
{
CoinJoinClientState.InCriticalPhase => false,
CoinJoinClientState.Idle or CoinJoinClientState.InProgress => true,

MODIFY
WalletWasabi/Services/SleepInhibitor.cs
WalletWasabi/Services/SleepInhibitor.cs
@@ -64,7 +64,7 @@ public class SleepInhibitor : PeriodicRunner
protected override async Task ActionAsync(CancellationToken cancel)
{
- var highestCoinJoinClientState = CoinJoinManager.GetHighestCoinJoinClientState();
+ var highestCoinJoinClientState = CoinJoinManager.HighestCoinJoinClientState;
switch (highestCoinJoinClientState)
{
case CoinJoinClientState.Idle:

MODIFY
WalletWasabi/WabiSabi/Client/CoinJoinManager.cs
WalletWasabi/WabiSabi/Client/CoinJoinManager.cs
@@ -35,7 +35,6 @@ public class CoinJoinManager : BackgroundService
public IWasabiHttpClientFactory HttpClientFactory { get; }
public RoundStateUpdater RoundStatusUpdater { get; }
public ServiceConfiguration ServiceConfiguration { get; }
- private ImmutableDictionary<string, CoinJoinTracker> TrackedCoinJoins { get; } = ImmutableDictionary<string, CoinJoinTracker>.Empty;
private CoinRefrigerator CoinRefrigerator { get; } = new();
public bool IsUserInSendWorkflow { get; set; }
public event EventHandler<StatusChangedEventArgs>? StatusChanged;
@@ -62,20 +61,7 @@ public class CoinJoinManager : BackgroundService
await _channel.Writer.WriteAsync(new StopCoinJoinCommand(wallet), cancellationToken).ConfigureAwait(false);
}
-
- public CoinJoinClientState GetHighestCoinJoinClientState()
- {
- var inProgress = TrackedCoinJoins.Values.Where(wtd => !wtd.IsCompleted).ToImmutableArray();
-
- if (inProgress.IsEmpty)
- {
- return CoinJoinClientState.Idle;
- }
-
- return inProgress.Any(wtd => wtd.InCriticalCoinJoinState)
- ? CoinJoinClientState.InCriticalPhase
- : CoinJoinClientState.InProgress;
- }
+ public CoinJoinClientState HighestCoinJoinClientState { get; private set; }
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
@@ -169,6 +155,17 @@ public class CoinJoinManager : BackgroundService
NotifyCoinJoinCompletion(finishedCoinJoin);
await HandleCoinJoinFinalizationAsync(finishedCoinJoin, trackedCoinJoins, stoppingToken).ConfigureAwait(false);
}
+
+ // Updates the highest coinjoin client state.
+ var inProgress = trackedCoinJoins.Values.Where(wtd => !wtd.IsCompleted).ToImmutableArray();
+
+ HighestCoinJoinClientState = inProgress.IsEmpty
+ ? CoinJoinClientState.Idle
+ : inProgress.Any(wtd => wtd.InCriticalCoinJoinState)
+ ? CoinJoinClientState.InCriticalPhase
+ : CoinJoinClientState.InProgress;
+
+ await Task.Delay(TimeSpan.FromSeconds(1), stoppingToken).ConfigureAwait(false);
}
});
}, stoppingToken);

Simplify `HigestCoinJoinState`