use linked CTS
MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/Send/PrivacySuggestionsFlyoutViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/Send/PrivacySuggestionsFlyoutViewModel.cs
@@ -34,9 +34,10 @@ public partial class PrivacySuggestionsFlyoutViewModel : ViewModelBase
public ObservableCollection<SuggestionViewModel> Suggestions { get; }
- public async Task BuildPrivacySuggestionsAsync(Wallet wallet, TransactionInfo info, BitcoinAddress destination, BuildTransactionResult transaction, bool isFixedAmount)
+ public async Task BuildPrivacySuggestionsAsync(Wallet wallet, TransactionInfo info, BitcoinAddress destination, BuildTransactionResult transaction, bool isFixedAmount, CancellationToken cancellationToken)
{
- using CancellationTokenSource cancellationTokenSource = new(TimeSpan.FromSeconds(15));
+ using CancellationTokenSource childCTS = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
+ childCTS.CancelAfter(15000);
Suggestions.Clear();
SelectedSuggestion = null;
@@ -56,7 +57,7 @@ public partial class PrivacySuggestionsFlyoutViewModel : ViewModelBase
if (hasChange && !isFixedAmount)
{
var suggestions =
- ChangeAvoidanceSuggestionViewModel.GenerateSuggestionsAsync(info, destination, wallet, cancellationTokenSource.Token);
+ ChangeAvoidanceSuggestionViewModel.GenerateSuggestionsAsync(info, destination, wallet, childCTS.Token);
await foreach (var suggestion in suggestions)
{

MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/Send/TransactionPreviewViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/Send/TransactionPreviewViewModel.cs
@@ -29,6 +29,7 @@ public partial class TransactionPreviewViewModel : RoutableViewModel
private readonly TransactionInfo _info;
private readonly BitcoinAddress _destination;
private BuildTransactionResult? _transaction;
+ private CancellationTokenSource _cancellationTokenSource;
[AutoNotify] private string _nextButtonText;
[AutoNotify] private bool _adjustFeeAvailable;
[AutoNotify] private TransactionSummaryViewModel? _displayedTransactionSummary;
@@ -39,6 +40,7 @@ public partial class TransactionPreviewViewModel : RoutableViewModel
_info = info;
_destination = destination;
_isFixedAmount = isFixedAmount;
+ _cancellationTokenSource = new CancellationTokenSource();
PrivacySuggestions = new PrivacySuggestionsFlyoutViewModel();
CurrentTransactionSummary = new TransactionSummaryViewModel(this, _wallet, _info, destination);
@@ -76,7 +78,7 @@ public partial class TransactionPreviewViewModel : RoutableViewModel
_info.ChangelessCoins = ca.TransactionResult.SpentCoins;
UpdateTransaction(CurrentTransactionSummary, ca.TransactionResult);
- await PrivacySuggestions.BuildPrivacySuggestionsAsync(_wallet, _info, _destination, ca.TransactionResult, _isFixedAmount);
+ await PrivacySuggestions.BuildPrivacySuggestionsAsync(_wallet, _info, _destination, ca.TransactionResult, _isFixedAmount, _cancellationTokenSource.Token);
}
else if (x is PocketSuggestionViewModel)
{
@@ -191,7 +193,7 @@ public partial class TransactionPreviewViewModel : RoutableViewModel
{
UpdateTransaction(CurrentTransactionSummary, newTransaction);
- await PrivacySuggestions.BuildPrivacySuggestionsAsync(_wallet, _info, _destination, newTransaction, _isFixedAmount);
+ await PrivacySuggestions.BuildPrivacySuggestionsAsync(_wallet, _info, _destination, newTransaction, _isFixedAmount, _cancellationTokenSource.Token);
}
}
@@ -396,7 +398,7 @@ public partial class TransactionPreviewViewModel : RoutableViewModel
{
UpdateTransaction(CurrentTransactionSummary, initialTransaction);
- await PrivacySuggestions.BuildPrivacySuggestionsAsync(_wallet, _info, _destination, initialTransaction, _isFixedAmount);
+ await PrivacySuggestions.BuildPrivacySuggestionsAsync(_wallet, _info, _destination, initialTransaction, _isFixedAmount, _cancellationTokenSource.Token);
}
else
{
@@ -421,6 +423,12 @@ public partial class TransactionPreviewViewModel : RoutableViewModel
protected override void OnNavigatedFrom(bool isInHistory)
{
+ if (!isInHistory)
+ {
+ _cancellationTokenSource.Cancel();
+ _cancellationTokenSource.Dispose();
+ }
+
base.OnNavigatedFrom(isInHistory);
DisplayedTransactionSummary = null;
@@ -428,6 +436,7 @@ public partial class TransactionPreviewViewModel : RoutableViewModel
private async Task OnConfirmAsync()
{
+ _cancellationTokenSource.Cancel();
var labelDialog = new LabelEntryDialogViewModel(_wallet, _info);
Navigate(NavigationTarget.CompactDialogScreen).To(labelDialog);

use linked CTS