Call BnB when Transaction changed
MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/Send/TransactionPreviewViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/Send/TransactionPreviewViewModel.cs
@@ -29,10 +29,10 @@ public partial class TransactionPreviewViewModel : RoutableViewModel
private readonly bool _isFixedAmount;
private readonly Wallet _wallet;
private readonly BitcoinAddress _destination;
- private BuildTransactionResult? _transaction;
private TransactionInfo _info;
private TransactionInfo _currentTransactionInfo;
private CancellationTokenSource _cancellationTokenSource;
+ [AutoNotify] private BuildTransactionResult? _transaction;
[AutoNotify] private string _nextButtonText;
[AutoNotify] private bool _adjustFeeAvailable;
[AutoNotify] private TransactionSummaryViewModel? _displayedTransactionSummary;
@@ -74,7 +74,7 @@ public partial class TransactionPreviewViewModel : RoutableViewModel
});
PrivacySuggestions.WhenAnyValue(x => x.SelectedSuggestion)
- .SubscribeAsync(async x =>
+ .Subscribe(x =>
{
PrivacySuggestions.IsOpen = false;
PrivacySuggestions.SelectedSuggestion = null;
@@ -83,8 +83,6 @@ public partial class TransactionPreviewViewModel : RoutableViewModel
{
_info.ChangelessCoins = ca.TransactionResult.SpentCoins;
UpdateTransaction(CurrentTransactionSummary, ca.TransactionResult);
-
- await PrivacySuggestions.BuildPrivacySuggestionsAsync(_wallet, _info, _destination, ca.TransactionResult, _isFixedAmount, _cancellationTokenSource.Token);
}
});
@@ -97,6 +95,13 @@ public partial class TransactionPreviewViewModel : RoutableViewModel
}
});
+ this.WhenAnyValue(x => x.Transaction)
+ .WhereNotNull()
+ .Throttle(TimeSpan.FromMilliseconds(100))
+ .ObserveOn(RxApp.MainThreadScheduler)
+ .DoAsync(async transaction => await PrivacySuggestions.BuildPrivacySuggestionsAsync(_wallet, _info, _destination, transaction, _isFixedAmount, _cancellationTokenSource.Token))
+ .Subscribe();
+
SetupCancel(enableCancel: true, enableCancelOnEscape: true, enableCancelOnPressed: false);
EnableBack = true;
@@ -129,14 +134,13 @@ public partial class TransactionPreviewViewModel : RoutableViewModel
}
});
- UndoCommand = ReactiveCommand.CreateFromTask(async () =>
+ UndoCommand = ReactiveCommand.Create(() =>
{
if (_undoHistory.TryPop(out var previous))
{
_info = previous.Item2;
UpdateTransaction(CurrentTransactionSummary, previous.Item1, false);
CanUndo = _undoHistory.Any();
- await PrivacySuggestions.BuildPrivacySuggestionsAsync(_wallet, _info, _destination, previous.Item1, _isFixedAmount, _cancellationTokenSource.Token);
}
});
@@ -171,9 +175,9 @@ public partial class TransactionPreviewViewModel : RoutableViewModel
private async Task OnExportPsbtAsync()
{
- if (_transaction is { })
+ if (Transaction is { })
{
- var saved = await TransactionHelpers.ExportTransactionToBinaryAsync(_transaction);
+ var saved = await TransactionHelpers.ExportTransactionToBinaryAsync(Transaction);
if (saved)
{
@@ -191,8 +195,8 @@ public partial class TransactionPreviewViewModel : RoutableViewModel
AddToUndoHistory();
}
- _transaction = transaction;
- CheckChangePocketAvailable(_transaction);
+ Transaction = transaction;
+ CheckChangePocketAvailable(Transaction);
_currentTransactionInfo = _info.Clone();
}
@@ -221,15 +225,13 @@ public partial class TransactionPreviewViewModel : RoutableViewModel
if (newTransaction is { })
{
UpdateTransaction(CurrentTransactionSummary, newTransaction);
-
- await PrivacySuggestions.BuildPrivacySuggestionsAsync(_wallet, _info, _destination, newTransaction, _isFixedAmount, _cancellationTokenSource.Token);
}
}
private async Task OnChangePocketsAsync()
{
var selectPocketsDialog =
- await NavigateDialogAsync(new PrivacyControlViewModel(_wallet, _info, _transaction?.SpentCoins, false));
+ await NavigateDialogAsync(new PrivacyControlViewModel(_wallet, _info, Transaction?.SpentCoins, false));
if (selectPocketsDialog.Kind == DialogResultKind.Normal && selectPocketsDialog.Result is { })
{
@@ -244,7 +246,7 @@ public partial class TransactionPreviewViewModel : RoutableViewModel
if (!_info.Coins.Any())
{
var privacyControlDialogResult =
- await NavigateDialogAsync(new PrivacyControlViewModel(_wallet, _info, _transaction?.SpentCoins, isSilent: true));
+ await NavigateDialogAsync(new PrivacyControlViewModel(_wallet, _info, Transaction?.SpentCoins, isSilent: true));
if (privacyControlDialogResult.Kind == DialogResultKind.Normal &&
privacyControlDialogResult.Result is { } coins)
{
@@ -386,7 +388,7 @@ public partial class TransactionPreviewViewModel : RoutableViewModel
_info.MinimumRequiredAmount = minimumRequiredAmount;
var selectPocketsDialog =
- await NavigateDialogAsync(new PrivacyControlViewModel(_wallet, _info, usedCoins: _transaction?.SpentCoins, isSilent: doSilentPocketSelection));
+ await NavigateDialogAsync(new PrivacyControlViewModel(_wallet, _info, usedCoins: Transaction?.SpentCoins, isSilent: doSilentPocketSelection));
if (selectPocketsDialog.Kind == DialogResultKind.Normal && selectPocketsDialog.Result is { })
{
@@ -413,8 +415,6 @@ public partial class TransactionPreviewViewModel : RoutableViewModel
if (await BuildTransactionAsync(BuildTransactionReason.Initialization) is { } initialTransaction)
{
UpdateTransaction(CurrentTransactionSummary, initialTransaction);
-
- await PrivacySuggestions.BuildPrivacySuggestionsAsync(_wallet, _info, _destination, initialTransaction, _isFixedAmount, _cancellationTokenSource.Token);
}
else
{
@@ -520,9 +520,9 @@ public partial class TransactionPreviewViewModel : RoutableViewModel
private void AddToUndoHistory()
{
- if (_transaction is { })
+ if (Transaction is { })
{
- _undoHistory.Push((_transaction, _currentTransactionInfo));
+ _undoHistory.Push((Transaction, _currentTransactionInfo));
CanUndo = true;
}
}

Call BnB when Transaction changed