safer way to fix immediate transition.
MODIFY
WalletWasabi.Fluent/State/StateMachine.cs
WalletWasabi.Fluent/State/StateMachine.cs
@@ -96,11 +96,21 @@ public class StateMachine<TState, TTrigger> where TTrigger : Enum where TState :
}
public void Start()
+ {
+ Enter();
+ }
+
+ private void Enter()
{
_currentState.Enter();
+
+ if (_currentState.WillTransitionTo is { } state)
+ {
+ Goto(state);
+ }
}
- public void Goto(TState state, bool exit = true, bool enter = true)
+ private void Goto(TState state, bool exit = true, bool enter = true)
{
if (_states.ContainsKey(state))
{
@@ -117,7 +127,7 @@ public class StateMachine<TState, TTrigger> where TTrigger : Enum where TState :
if (enter)
{
- _currentState.Enter();
+ Enter();
}
}
}
@@ -134,6 +144,8 @@ public class StateMachine<TState, TTrigger> where TTrigger : Enum where TState :
public StateContext? Parent { get; private set; }
+ internal TState? WillTransitionTo { get; private set; }
+
public StateContext(StateMachine<TState, TTrigger> owner, TState state)
{
_owner = owner;
@@ -145,6 +157,13 @@ public class StateMachine<TState, TTrigger> where TTrigger : Enum where TState :
_permittedTransitions = new();
}
+ public StateContext TransitionOnEntryTo(TState? state)
+ {
+ WillTransitionTo = state;
+
+ return this;
+ }
+
public StateContext SubstateOf(TState parent)
{
Parent = _owner._states[parent];

MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/CoinJoinStateViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/CoinJoinStateViewModel.cs
@@ -196,6 +196,7 @@ public partial class CoinJoinStateViewModel : ViewModelBase
// Manual Cj State
_stateMachine.Configure(State.ManualCoinJoin)
.Permit(Trigger.AutoCoinJoinOn, State.AutoCoinJoin)
+ .TransitionOnEntryTo(State.Stopped)
.OnEntry(() =>
{
IsAuto = false;
@@ -203,8 +204,6 @@ public partial class CoinJoinStateViewModel : ViewModelBase
PlayVisible = true;
StopVisible = false;
PauseVisible = false;
-
- _stateMachine.Goto(State.Stopped);
})
.OnEntry(UpdateAndShowWalletMixedProgress)
.OnTrigger(Trigger.BalanceChanged, UpdateAndShowWalletMixedProgress);
@@ -301,6 +300,7 @@ public partial class CoinJoinStateViewModel : ViewModelBase
// AutoCj State
_stateMachine.Configure(State.AutoCoinJoin)
+ .TransitionOnEntryTo(State.AutoStarting)
.Permit(Trigger.AutoCoinJoinOff, State.ManualCoinJoin)
.OnEntry(async () =>
{
@@ -312,8 +312,6 @@ public partial class CoinJoinStateViewModel : ViewModelBase
CurrentStatus = _initialisingMessage;
await coinJoinManager.StopAsync(_wallet, CancellationToken.None);
-
- _stateMachine.Goto(State.AutoStarting);
});
_stateMachine.Configure(State.AutoStarting)

safer way to fix immediate transition.