increasing the UI response time on send and coinjoin by optimizing the transaction list(history) refresh
MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/HistoryTabViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/HistoryTabViewModel.cs
@@ -7,6 +7,7 @@ using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
+using System.Diagnostics;
using System.Linq;
using System.Reactive.Linq;
using System.Text;
@@ -34,7 +35,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
{
Interlocked.Exchange(ref _disableClipboard, 0);
Transactions = new ObservableCollection<TransactionViewModel>();
- RewriteTable();
+ RewriteTableAsync();
var coinsChanged = Observable.FromEventPattern(Global.WalletService.Coins, nameof(Global.WalletService.Coins.CollectionChanged));
var newBlockProcessed = Observable.FromEventPattern(Global.WalletService, nameof(Global.WalletService.NewBlockProcessed));
@@ -43,10 +44,11 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
coinsChanged
.Merge(newBlockProcessed)
.Merge(coinSpent)
+ .Throttle(TimeSpan.FromSeconds(5))
.ObserveOn(RxApp.MainThreadScheduler)
- .Subscribe(o =>
+ .Subscribe(_ =>
{
- RewriteTable();
+ RewriteTableAsync();
});
this.WhenAnyValue(x => x.SelectedTransaction).Subscribe(async transaction =>
@@ -74,8 +76,42 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
DateSortDirection = SortOrder.Decreasing;
}
- private void RewriteTable()
+ private async void RewriteTableAsync()
{
+ var txRecordList = await Task.Run(() =>
+ {
+ return BuildTxRecordList();
+ });
+
+ var rememberSelectedTransactionId = SelectedTransaction?.TransactionId;
+ Transactions?.Clear();
+
+ var trs = txRecordList.Select(txr => new TransactionInfo()
+ {
+ DateTime = txr.dateTime.ToLocalTime(),
+ Confirmed = txr.height != WalletWasabi.Models.Height.MemPool && txr.height != WalletWasabi.Models.Height.Unknown,
+ AmountBtc = $"{txr.amount.ToString(fplus: true, trimExcessZero: true)}",
+ Label = txr.label,
+ TransactionId = txr.transactionId.ToString()
+ }).Select(ti => new TransactionViewModel(ti));
+
+ Transactions = new ObservableCollection<TransactionViewModel>(trs);
+
+ if (Transactions.Count > 0 && !(rememberSelectedTransactionId is null))
+ {
+ var txToSelect = Transactions.FirstOrDefault(x => x.TransactionId == rememberSelectedTransactionId);
+ if (txToSelect != default)
+ {
+ Interlocked.Exchange(ref _disableClipboard, 1);
+ SelectedTransaction = txToSelect;
+ }
+ }
+ RefreshOrdering();
+ }
+
+ private static List<(DateTimeOffset dateTime, Height height, Money amount, string label, uint256 transactionId)> BuildTxRecordList()
+ {
+ List<Transaction> trs = new List<Transaction>();
var txRecordList = new List<(DateTimeOffset dateTime, Height height, Money amount, string label, uint256 transactionId)>();
foreach (SmartCoin coin in Global.WalletService.Coins)
{
@@ -141,34 +177,8 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
}
}
}
-
txRecordList = txRecordList.OrderByDescending(x => x.dateTime).ThenBy(x => x.amount).ToList();
-
- var rememberSelectedTransactionId = SelectedTransaction?.TransactionId;
- Transactions?.Clear();
- foreach (var txr in txRecordList)
- {
- var txinfo = new TransactionInfo
- {
- DateTime = txr.dateTime.ToLocalTime(),
- Confirmed = txr.height != WalletWasabi.Models.Height.MemPool && txr.height != WalletWasabi.Models.Height.Unknown,
- AmountBtc = $"{txr.amount.ToString(fplus: true, trimExcessZero: true)}",
- Label = txr.label,
- TransactionId = txr.transactionId.ToString()
- };
- Transactions.Add(new TransactionViewModel(txinfo));
- }
-
- if (Transactions.Count > 0 && !(rememberSelectedTransactionId is null))
- {
- var txToSelect = Transactions.FirstOrDefault(x => x.TransactionId == rememberSelectedTransactionId);
- if (txToSelect != default)
- {
- Interlocked.Exchange(ref _disableClipboard, 1);
- SelectedTransaction = txToSelect;
- }
- }
- RefreshOrdering();
+ return txRecordList;
}
public ObservableCollection<TransactionViewModel> Transactions

increasing the UI response time on send and coinjoin by optimizing the transaction list(history) refresh