use strings for more user friendly uiconfig :)
MODIFY
WalletWasabi.Gui/Controls/SortingArrow.cs
WalletWasabi.Gui/Controls/SortingArrow.cs
@@ -27,14 +27,14 @@ namespace WalletWasabi.Gui.Controls
public struct SortingPreference : IEquatable<SortingPreference>
{
- public SortingPreference(SortOrder sortOrder, int propertyTarget)
+ public SortingPreference(SortOrder sortOrder, string colTarget)
{
SortOrder = sortOrder;
- ColumnTarget = propertyTarget;
+ ColumnTarget = colTarget;
}
public SortOrder SortOrder { get; set; }
- public int ColumnTarget { get; set; }
+ public string ColumnTarget { get; set; }
public bool Equals([AllowNull] SortingPreference other) => SortOrder == other.SortOrder && ColumnTarget == other.ColumnTarget;
}

MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/CoinListViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/CoinListViewModel.cs
@@ -23,14 +23,6 @@ using WalletWasabi.Wallets;
namespace WalletWasabi.Gui.Controls.WalletExplorer
{
- internal enum CoinListViewSortTarget
- {
- Amount,
- Privacy,
- Clusters,
- Status
- }
-
public class CoinListViewModel : ViewModelBase
{
private static HashSet<SmartCoinStatus> NotVisibleStatuses = new HashSet<SmartCoinStatus>()
@@ -70,8 +62,11 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
CanDequeueCoins = canDequeueCoins;
DisplayCommonOwnershipWarning = displayCommonOwnershipWarning;
+ ValidateSavedColumnConfig();
+
var savedSort = Global.UiConfig.CoinListViewSortingPreference;
- SortColumn(savedSort.SortOrder, (CoinListViewSortTarget)savedSort.ColumnTarget, false);
+
+ SortColumn(savedSort.SortOrder, savedSort.ColumnTarget, false);
RefreshOrdering();
// Otherwise they're all selected as null on load.
@@ -97,22 +92,22 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
this.WhenAnyValue(x => x.AmountSortDirection)
.ObserveOn(RxApp.MainThreadScheduler)
.Where(x => x != SortOrder.None)
- .Subscribe(x => SortColumn(x, CoinListViewSortTarget.Amount));
+ .Subscribe(x => SortColumn(x, nameof(AmountSortDirection)));
this.WhenAnyValue(x => x.ClustersSortDirection)
.ObserveOn(RxApp.MainThreadScheduler)
.Where(x => x != SortOrder.None)
- .Subscribe(x => SortColumn(x, CoinListViewSortTarget.Clusters));
+ .Subscribe(x => SortColumn(x, nameof(ClustersSortDirection)));
this.WhenAnyValue(x => x.StatusSortDirection)
.ObserveOn(RxApp.MainThreadScheduler)
.Where(x => x != SortOrder.None)
- .Subscribe(x => SortColumn(x, CoinListViewSortTarget.Status));
+ .Subscribe(x => SortColumn(x, nameof(StatusSortDirection)));
this.WhenAnyValue(x => x.PrivacySortDirection)
.ObserveOn(RxApp.MainThreadScheduler)
.Where(x => x != SortOrder.None)
- .Subscribe(x => SortColumn(x, CoinListViewSortTarget.Privacy));
+ .Subscribe(x => SortColumn(x, nameof(PrivacySortDirection)));
SelectAllCheckBoxCommand = ReactiveCommand.Create(() =>
{
@@ -320,22 +315,35 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
DequeueCoinsPressed?.Invoke(this, coin);
}
- private void SortColumn(SortOrder x, CoinListViewSortTarget y, bool saveToUiConfig = true)
+ private void ValidateSavedColumnConfig()
+ {
+ var savedCol = Global.UiConfig.CoinListViewSortingPreference.ColumnTarget;
+
+ if ( savedCol != nameof(AmountSortDirection)
+ & savedCol != nameof(PrivacySortDirection)
+ & savedCol != nameof(ClustersSortDirection)
+ & savedCol != nameof(StatusSortDirection) )
+ {
+ Global.UiConfig.CoinListViewSortingPreference = new SortingPreference(SortOrder.Increasing, nameof(AmountSortDirection));
+ }
+ }
+
+ private void SortColumn(SortOrder sortOrder, string target, bool saveToUiConfig = true)
{
- var sortPref = new SortingPreference(x, (int)y);
+ var sortPref = new SortingPreference(sortOrder, target);
if (saveToUiConfig)
{
Global.UiConfig.CoinListViewSortingPreference = sortPref;
}
- var sortTarget = (CoinListViewSortTarget)sortPref.ColumnTarget;
+ var sortTarget = sortPref.ColumnTarget;
var sortOrd = sortPref.SortOrder;
- AmountSortDirection = sortTarget == CoinListViewSortTarget.Amount ? sortOrd : SortOrder.None;
- PrivacySortDirection = sortTarget == CoinListViewSortTarget.Privacy ? sortOrd : SortOrder.None;
- ClustersSortDirection = sortTarget == CoinListViewSortTarget.Clusters ? sortOrd : SortOrder.None;
- StatusSortDirection = sortTarget == CoinListViewSortTarget.Status ? sortOrd : SortOrder.None;
+ AmountSortDirection = sortTarget == nameof(AmountSortDirection) ? sortOrd : SortOrder.None;
+ PrivacySortDirection = sortTarget == nameof(PrivacySortDirection) ? sortOrd : SortOrder.None;
+ ClustersSortDirection = sortTarget == nameof(ClustersSortDirection) ? sortOrd : SortOrder.None;
+ StatusSortDirection = sortTarget == nameof(StatusSortDirection) ? sortOrd : SortOrder.None;
}
private void RefreshOrdering()

MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/HistoryTabViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/HistoryTabViewModel.cs
@@ -16,13 +16,6 @@ using WalletWasabi.Wallets;
namespace WalletWasabi.Gui.Controls.WalletExplorer
{
- internal enum HistoryTabViewSortTarget
- {
- Date,
- Amount,
- Transaction
- }
-
public class HistoryTabViewModel : WasabiDocumentTabViewModel, IWalletViewModel
{
private ObservableCollection<TransactionViewModel> _transactions;
@@ -39,26 +32,28 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
Transactions = new ObservableCollection<TransactionViewModel>();
+ ValidateSavedColumnConfig();
+
SortCommand = ReactiveCommand.Create(RefreshOrdering);
var savedSort = Global.UiConfig.HistoryTabViewSortingPreference;
- SortColumn(savedSort.SortOrder, (HistoryTabViewSortTarget)savedSort.ColumnTarget, false);
+ SortColumn(savedSort.SortOrder, savedSort.ColumnTarget, false);
RefreshOrdering();
this.WhenAnyValue(x => x.DateSortDirection)
.ObserveOn(RxApp.MainThreadScheduler)
.Where(x => x != SortOrder.None)
- .Subscribe(x => SortColumn(x, HistoryTabViewSortTarget.Date));
+ .Subscribe(x => SortColumn(x, nameof(DateSortDirection)));
this.WhenAnyValue(x => x.AmountSortDirection)
.ObserveOn(RxApp.MainThreadScheduler)
.Where(x => x != SortOrder.None)
- .Subscribe(x => SortColumn(x, HistoryTabViewSortTarget.Amount));
+ .Subscribe(x => SortColumn(x, nameof(AmountSortDirection)));
this.WhenAnyValue(x => x.TransactionSortDirection)
.ObserveOn(RxApp.MainThreadScheduler)
.Where(x => x != SortOrder.None)
- .Subscribe(x => SortColumn(x, HistoryTabViewSortTarget.Transaction));
+ .Subscribe(x => SortColumn(x, nameof(TransactionSortDirection)));
SortCommand.ThrownExceptions
.ObserveOn(RxApp.TaskpoolScheduler)
@@ -168,21 +163,33 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
}
}
- private void SortColumn(SortOrder x, HistoryTabViewSortTarget y, bool saveToUiConfig = true)
+ private void ValidateSavedColumnConfig()
+ {
+ var savedCol = Global.UiConfig.HistoryTabViewSortingPreference.ColumnTarget;
+
+ if (savedCol != nameof(DateSortDirection)
+ & savedCol != nameof(AmountSortDirection)
+ & savedCol != nameof(TransactionSortDirection))
+ {
+ Global.UiConfig.HistoryTabViewSortingPreference = new SortingPreference(SortOrder.Increasing, nameof(DateSortDirection));
+ }
+ }
+
+ private void SortColumn(SortOrder sortOrder, string target, bool saveToUiConfig = true)
{
- var sortPref = new SortingPreference(x, (int)y);
+ var sortPref = new SortingPreference(sortOrder, target);
if (saveToUiConfig)
{
Global.UiConfig.HistoryTabViewSortingPreference = sortPref;
}
- var sortTarget = (HistoryTabViewSortTarget)sortPref.ColumnTarget;
+ var sortTarget = sortPref.ColumnTarget;
var sortOrd = sortPref.SortOrder;
- DateSortDirection = sortTarget == HistoryTabViewSortTarget.Date ? sortOrd : SortOrder.None;
- AmountSortDirection = sortTarget == HistoryTabViewSortTarget.Amount ? sortOrd : SortOrder.None;
- TransactionSortDirection = sortTarget == HistoryTabViewSortTarget.Transaction ? sortOrd : SortOrder.None;
+ DateSortDirection = sortTarget == nameof(DateSortDirection) ? sortOrd : SortOrder.None;
+ AmountSortDirection = sortTarget == nameof(AmountSortDirection) ? sortOrd : SortOrder.None;
+ TransactionSortDirection = sortTarget == nameof(TransactionSortDirection) ? sortOrd : SortOrder.None;
}
private void RefreshOrdering()

MODIFY
WalletWasabi.Gui/Converters/SortingPreferenceJsonConverter.cs
WalletWasabi.Gui/Converters/SortingPreferenceJsonConverter.cs
@@ -15,7 +15,8 @@ namespace WalletWasabi.Gui.Converters
{
try
{
- return serializer.Deserialize(reader, typeof(SortingPreference));
+ var readValue = (SortingPreference)serializer.Deserialize(reader, typeof(SortingPreference));
+ return new SortingPreference(readValue.SortOrder, $"{readValue.ColumnTarget}SortDirection");
}
catch
{
@@ -25,7 +26,15 @@ namespace WalletWasabi.Gui.Converters
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
- serializer.Serialize(writer, value);
+ if (value is null)
+ {
+ return;
+ }
+
+ var saveValue = (SortingPreference)value;
+ var newSaveValue = new SortingPreference(saveValue.SortOrder, saveValue.ColumnTarget.Replace("SortDirection", null));
+
+ serializer.Serialize(writer, newSaveValue);
}
}
}

MODIFY
WalletWasabi.Gui/UiConfig.cs
WalletWasabi.Gui/UiConfig.cs
@@ -102,10 +102,10 @@ namespace WalletWasabi.Gui
[JsonProperty(PropertyName = "CoinListViewSortingPreference")]
[JsonConverter(typeof(SortingPreferenceJsonConverter))]
- public SortingPreference CoinListViewSortingPreference { get; internal set; } = new SortingPreference(SortOrder.Increasing, 0);
+ public SortingPreference CoinListViewSortingPreference { get; internal set; } = new SortingPreference(SortOrder.Increasing, "Amount");
[JsonProperty(PropertyName = "HistoryTabViewSortingPreference")]
[JsonConverter(typeof(SortingPreferenceJsonConverter))]
- public SortingPreference HistoryTabViewSortingPreference { get; internal set; } = new SortingPreference(SortOrder.Increasing, 0);
+ public SortingPreference HistoryTabViewSortingPreference { get; internal set; } = new SortingPreference(SortOrder.Increasing, "Date");
}
}

use strings for more user friendly uiconfig :)