Implement persistence for history tab view
MODIFY
WalletWasabi.Gui/Controls/SortingArrow.cs
WalletWasabi.Gui/Controls/SortingArrow.cs
@@ -23,13 +23,13 @@ namespace WalletWasabi.Gui.Controls
public SortingPreference(SortOrder sortOrder, int propertyTarget)
{
SortOrder = sortOrder;
- PropertyTarget = propertyTarget;
+ ColumnTarget = propertyTarget;
}
public SortOrder SortOrder { get; set; }
- public int PropertyTarget { get; set; }
+ public int ColumnTarget { get; set; }
- public bool Equals([AllowNull] SortingPreference other) => SortOrder == other.SortOrder && PropertyTarget == other.PropertyTarget;
+ 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
@@ -71,7 +71,8 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
CanDequeueCoins = canDequeueCoins;
DisplayCommonOwnershipWarning = displayCommonOwnershipWarning;
- SetSortOrder(Global.UiConfig.CoinListViewSortingPreference);
+ var savedSort = Global.UiConfig.CoinListViewSortingPreference;
+ SortColumn(savedSort.SortOrder, (CoinListViewSortTarget)savedSort.ColumnTarget, false);
RefreshOrdering();
// Otherwise they're all selected as null on load.
@@ -181,10 +182,22 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
.Subscribe(ex => Logger.LogError(ex));
}
- private void SortColumn(SortOrder x, CoinListViewSortTarget privacy)
+ private void SortColumn(SortOrder x, CoinListViewSortTarget y, bool saveToUiConfig = true)
{
- Global.UiConfig.CoinListViewSortingPreference = new SortingPreference(x, (int)privacy);
- SetSortOrder(Global.UiConfig.CoinListViewSortingPreference);
+ var sortPref = new SortingPreference(x, (int)y);
+
+ if (saveToUiConfig)
+ {
+ Global.UiConfig.CoinListViewSortingPreference = sortPref;
+ }
+
+ var sortTarget = (CoinListViewSortTarget)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;
}
public event EventHandler<SmartCoin> DequeueCoinsPressed;
@@ -549,17 +562,6 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
isStrongPrivate);
}
- private void SetSortOrder(SortingPreference sortPref)
- {
- var sortTarget = (CoinListViewSortTarget)sortPref.PropertyTarget;
- 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;
- }
-
public void OnClose()
{
foreach (var cvm in RootList.Items)

MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/HistoryTabViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/HistoryTabViewModel.cs
@@ -16,6 +16,13 @@ using WalletWasabi.Wallets;
namespace WalletWasabi.Gui.Controls.WalletExplorer
{
+ internal enum HistoryTabViewSortTarget
+ {
+ Date,
+ Amount,
+ Transaction
+ }
+
public class HistoryTabViewModel : WasabiDocumentTabViewModel, IWalletViewModel
{
private ObservableCollection<TransactionViewModel> _transactions;
@@ -33,7 +40,25 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
Transactions = new ObservableCollection<TransactionViewModel>();
SortCommand = ReactiveCommand.Create(RefreshOrdering);
- DateSortDirection = SortOrder.Decreasing;
+
+ var savedSort = Global.UiConfig.HistoryTabViewSortingPreference;
+ SortColumn(savedSort.SortOrder, (HistoryTabViewSortTarget)savedSort.ColumnTarget, false);
+ RefreshOrdering();
+
+ this.WhenAnyValue(x => x.DateSortDirection)
+ .ObserveOn(RxApp.MainThreadScheduler)
+ .Where(x => x != SortOrder.None)
+ .Subscribe(x => SortColumn(x, HistoryTabViewSortTarget.Date));
+
+ this.WhenAnyValue(x => x.AmountSortDirection)
+ .ObserveOn(RxApp.MainThreadScheduler)
+ .Where(x => x != SortOrder.None)
+ .Subscribe(x => SortColumn(x, HistoryTabViewSortTarget.Amount));
+
+ this.WhenAnyValue(x => x.TransactionSortDirection)
+ .ObserveOn(RxApp.MainThreadScheduler)
+ .Where(x => x != SortOrder.None)
+ .Subscribe(x => SortColumn(x, HistoryTabViewSortTarget.Transaction));
SortCommand.ThrownExceptions
.ObserveOn(RxApp.TaskpoolScheduler)
@@ -67,43 +92,19 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
public SortOrder DateSortDirection
{
get => _dateSortDirection;
- set
- {
- this.RaiseAndSetIfChanged(ref _dateSortDirection, value);
- if (value != SortOrder.None)
- {
- AmountSortDirection = SortOrder.None;
- TransactionSortDirection = SortOrder.None;
- }
- }
+ set => this.RaiseAndSetIfChanged(ref _dateSortDirection, value);
}
public SortOrder AmountSortDirection
{
get => _amountSortDirection;
- set
- {
- this.RaiseAndSetIfChanged(ref _amountSortDirection, value);
- if (value != SortOrder.None)
- {
- DateSortDirection = SortOrder.None;
- TransactionSortDirection = SortOrder.None;
- }
- }
+ set => this.RaiseAndSetIfChanged(ref _amountSortDirection, value);
}
public SortOrder TransactionSortDirection
{
get => _transactionSortDirection;
- set
- {
- this.RaiseAndSetIfChanged(ref _transactionSortDirection, value);
- if (value != SortOrder.None)
- {
- AmountSortDirection = SortOrder.None;
- DateSortDirection = SortOrder.None;
- }
- }
+ set => this.RaiseAndSetIfChanged(ref _transactionSortDirection, value);
}
public override void OnOpen(CompositeDisposable disposables)
@@ -167,6 +168,23 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
}
}
+ private void SortColumn(SortOrder x, HistoryTabViewSortTarget y, bool saveToUiConfig = true)
+ {
+ var sortPref = new SortingPreference(x, (int)y);
+
+ if (saveToUiConfig)
+ {
+ Global.UiConfig.HistoryTabViewSortingPreference = sortPref;
+ }
+
+ var sortTarget = (HistoryTabViewSortTarget)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;
+ }
+
private void RefreshOrdering()
{
if (TransactionSortDirection != SortOrder.None)

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

Implement persistence for history tab view