remove state machine hacks
MODIFY
WalletWasabi.Fluent/State/StateMachine.cs
WalletWasabi.Fluent/State/StateMachine.cs
using System.Collections.Generic;
-using System.Linq;
namespace WalletWasabi.Fluent.State;
@@ -9,7 +8,7 @@ public class StateMachine<TState, TTrigger> where TTrigger : Enum where TState :
private readonly Dictionary<TState, StateContext> _states;
private OnTransitionedDelegate? _onTransitioned;
- public delegate void OnTransitionedDelegate(TTrigger trigger, TState from, TState to);
+ public delegate void OnTransitionedDelegate(TState from, TState to);
public TState State => _currentState.StateId;
@@ -84,15 +83,15 @@ public class StateMachine<TState, TTrigger> where TTrigger : Enum where TState :
if (_states.ContainsKey(destination) && _states[destination].Parent is { } parent && !IsInState(parent.StateId))
{
- Goto(trigger, parent.StateId);
+ Goto(parent.StateId);
}
- Goto(trigger, destination);
+ Goto(destination);
}
else if (_currentState.Parent is { } && _currentState.Parent.CanTransit(trigger))
{
- Goto(trigger, _currentState.Parent.StateId, true, false);
- Goto(trigger, _currentState.GetDestination(trigger));
+ Goto(_currentState.Parent.StateId, true, false);
+ Goto(_currentState.GetDestination(trigger));
}
}
@@ -101,7 +100,7 @@ public class StateMachine<TState, TTrigger> where TTrigger : Enum where TState :
_currentState.Enter();
}
- private void Goto(TTrigger trigger, TState state, bool exit = true, bool enter = true)
+ public void Goto(TState state, bool exit = true, bool enter = true)
{
if (_states.ContainsKey(state))
{
@@ -114,7 +113,7 @@ public class StateMachine<TState, TTrigger> where TTrigger : Enum where TState :
_currentState = _states[state];
- _onTransitioned?.Invoke(trigger, old, _currentState.StateId);
+ _onTransitioned?.Invoke(old, _currentState.StateId);
if (enter)
{

MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/CoinJoinStateViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/CoinJoinStateViewModel.cs
@@ -157,8 +157,6 @@ public partial class CoinJoinStateViewModel : ViewModelBase
AutoStartTimeout,
AutoCoinJoinOn,
AutoCoinJoinOff,
- AutoCoinJoinEntered,
- ManualCoinJoinEntered,
Pause,
Play,
Stop,
@@ -198,7 +196,6 @@ public partial class CoinJoinStateViewModel : ViewModelBase
// Manual Cj State
_stateMachine.Configure(State.ManualCoinJoin)
.Permit(Trigger.AutoCoinJoinOn, State.AutoCoinJoin)
- .Permit(Trigger.ManualCoinJoinEntered, State.Stopped) // TODO remove hack
.OnEntry(() =>
{
IsAuto = false;
@@ -207,7 +204,7 @@ public partial class CoinJoinStateViewModel : ViewModelBase
StopVisible = false;
PauseVisible = false;
- _stateMachine.Fire(Trigger.ManualCoinJoinEntered);
+ _stateMachine.Goto(State.Stopped);
})
.OnEntry(UpdateAndShowWalletMixedProgress)
.OnTrigger(Trigger.BalanceChanged, UpdateAndShowWalletMixedProgress);
@@ -305,7 +302,6 @@ public partial class CoinJoinStateViewModel : ViewModelBase
// AutoCj State
_stateMachine.Configure(State.AutoCoinJoin)
.Permit(Trigger.AutoCoinJoinOff, State.ManualCoinJoin)
- .Permit(Trigger.AutoCoinJoinEntered, State.AutoStarting) // TODO remove hack
.OnEntry(async () =>
{
IsAuto = true;
@@ -317,7 +313,7 @@ public partial class CoinJoinStateViewModel : ViewModelBase
await coinJoinManager.StopAsync(_wallet, CancellationToken.None);
- _stateMachine.Fire(Trigger.AutoCoinJoinEntered);
+ _stateMachine.Goto(State.AutoStarting);
});
_stateMachine.Configure(State.AutoStarting)

MODIFY
WalletWasabi.Tests/UnitTests/StateMachineTests.cs
WalletWasabi.Tests/UnitTests/StateMachineTests.cs
@@ -311,4 +311,24 @@ public class StateMachineTests
Assert.True(sut.IsInState(JukeBoxState.Playing));
Assert.True(onTriggerCalled);
}
+
+ [Fact]
+ public void OnEntry_Isnt_Called_For_Parent_State_Is_We_Enter_Another_Child()
+ {
+ StateMachine<JukeBoxState, JukeBoxTrigger> sut =
+ new StateMachine<JukeBoxState, JukeBoxTrigger>(JukeBoxState.Paused);
+
+ int entryCallCount = 0;
+
+ sut.Configure(JukeBoxState.Paused)
+ .Permit(JukeBoxTrigger.Pause, JukeBoxState.PausedChild)
+ .OnEntry(() =>
+ {
+ entryCallCount++;
+ });
+
+ sut.Start();
+
+ sut.Fire(JukeBoxTrigger.Pause);
+ }
}
\ No newline at end of file

remove state machine hacks