move the autostart delay from wabisabi code to ui code.
MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/CoinJoinStateViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/CoinJoinStateViewModel.cs
@@ -34,6 +34,7 @@ public partial class CoinJoinStateViewModel : ViewModelBase
private enum Trigger
{
Invalid = 0,
+ AutoStartTimeout,
AutoCoinJoinOn,
AutoCoinJoinOff,
AutoCoinJoinEntered,
@@ -76,13 +77,15 @@ public partial class CoinJoinStateViewModel : ViewModelBase
private readonly MusicStatusMessageViewModel _finishedMessage = new() { Message = "No balance to coinjoin" };
- private DateTimeOffset _autoStartTime;
+ private TimeSpan _autoStartTime;
private DateTimeOffset _countDownStarted;
public CoinJoinStateViewModel(WalletViewModel walletVm, IObservable<Unit> balanceChanged)
{
_elapsedTime = "";
_remainingTime = "";
+ _countDownStarted = DateTimeOffset.Now;
+ _autoStartTime = TimeSpan.FromSeconds(Random.Shared.Next(1 * 60, 1 * 60));
_wallet = walletVm.Wallet;
@@ -208,6 +211,8 @@ public partial class CoinJoinStateViewModel : ViewModelBase
coinJoinManager.Stop(_wallet);
coinJoinManager.AutoStart(_wallet);
+
+ _stateMachine.Fire(Trigger.AutoCoinJoinEntered);
});
_stateMachine.Configure(State.AutoStarting)
@@ -215,9 +220,12 @@ public partial class CoinJoinStateViewModel : ViewModelBase
.Permit(Trigger.Pause, State.Paused)
.Permit(Trigger.RoundStart, State.AutoPlaying)
.Permit(Trigger.RoundStartFailed, State.AutoFinished)
+ .Permit(Trigger.AutoStartTimeout, State.AutoPlaying)
.Permit(Trigger.Play, State.AutoPlaying)
.OnEntry(() =>
{
+ UpdateCountDown();
+
IsAutoWaiting = true;
CurrentStatus = _countDownMessage;
})
@@ -283,11 +291,16 @@ public partial class CoinJoinStateViewModel : ViewModelBase
ElapsedTime = $"{GetElapsedTime().ToString(format)}";
RemainingTime = $"-{GetRemainingTime().ToString(format)}";
ProgressValue = GetPercentage();
+
+ if (GetRemainingTime() <= TimeSpan.Zero)
+ {
+ _stateMachine.Fire(Trigger.AutoStartTimeout);
+ }
}
private TimeSpan GetElapsedTime() => DateTimeOffset.Now - _countDownStarted;
- private TimeSpan GetRemainingTime() => _autoStartTime - DateTimeOffset.Now;
+ private TimeSpan GetRemainingTime() => (_countDownStarted + _autoStartTime) - DateTimeOffset.Now;
private double GetPercentage() => GetElapsedTime().TotalSeconds / GetRemainingTime().TotalSeconds * 100;
@@ -321,16 +334,6 @@ public partial class CoinJoinStateViewModel : ViewModelBase
{
switch (e)
{
- case StartingEventArgs startingEventArgs:
- if (_stateMachine.State == State.AutoCoinJoin)
- {
- _countDownStarted = DateTimeOffset.Now;
- _autoStartTime = _countDownStarted + startingEventArgs.StartingIn;
- _stateMachine.Fire(Trigger.AutoCoinJoinEntered);
- }
-
- break;
-
case StartedEventArgs:
_stateMachine.Fire(Trigger.RoundStart);
break;

MODIFY
WalletWasabi/WabiSabi/Client/CoinJoinManager.cs
WalletWasabi/WabiSabi/Client/CoinJoinManager.cs
@@ -39,7 +39,6 @@ public class CoinJoinManager : BackgroundService
public ServiceConfiguration ServiceConfiguration { get; }
private ImmutableDictionary<string, CoinJoinTracker> TrackedCoinJoins { get; set; } = ImmutableDictionary<string, CoinJoinTracker>.Empty;
private CoinRefrigerator CoinRefrigerator { get; } = new();
- private TimeSpan AutoCoinJoinDelayAfterWalletLoaded { get; } = TimeSpan.FromSeconds(60);
public bool IsUserInSendWorkflow { get; set; }
private ConcurrentDictionary<Wallet, CoinJoinCommand> WalletManualState { get; } = new();
@@ -99,11 +98,6 @@ public class CoinJoinManager : BackgroundService
if (!MustStart(openedWallet))
{
- if (openedWallet.ElapsedTimeSinceStartup <= AutoCoinJoinDelayAfterWalletLoaded)
- {
- NotifyCoinJoinStarting(openedWallet);
- continue;
- }
if (!openedWallet.KeyManager.AutoCoinJoin)
{
NotifyCoinJoinStartError(openedWallet, CoinjoinError.AutoConjoinDisabled);
@@ -222,11 +216,6 @@ public class CoinJoinManager : BackgroundService
}
}
- private void NotifyCoinJoinStarting(Wallet openedWallet) =>
- SafeRaiseEvent(StatusChanged, new StartingEventArgs(
- openedWallet,
- AutoCoinJoinDelayAfterWalletLoaded - openedWallet.ElapsedTimeSinceStartup));
-
private void NotifyCoinJoinStarted(Wallet openedWallet, TimeSpan registrationTimeout) =>
SafeRaiseEvent(StatusChanged, new StartedEventArgs(openedWallet, registrationTimeout));

MODIFY
WalletWasabi/WabiSabi/Client/StatusChangedEventArgs.cs
WalletWasabi/WabiSabi/Client/StatusChangedEventArgs.cs
@@ -19,16 +19,6 @@ public class LoadedEventArgs : StatusChangedEventArgs
}
}
-public class StartingEventArgs : StatusChangedEventArgs
-{
- public StartingEventArgs(Wallet wallet, TimeSpan startingIn)
- : base(wallet)
- {
- StartingIn = startingIn;
- }
- public TimeSpan StartingIn { get; }
-}
-
public class StartedEventArgs : StatusChangedEventArgs
{
public StartedEventArgs(Wallet wallet, TimeSpan registrationTimeout)

MODIFY
WalletWasabi/Wallets/Wallet.cs
WalletWasabi/Wallets/Wallet.cs
@@ -71,7 +71,6 @@ public class Wallet : BackgroundService
}
}
- public TimeSpan ElapsedTimeSinceStartup => DateTimeOffset.UtcNow - StartupTime;
public DateTimeOffset StartupTime { get; private set; }
public BitcoinStore BitcoinStore { get; private set; }
public KeyManager KeyManager { get; }

move the autostart delay from wabisabi code to ui code.