Button mechanisms
MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/TransactionBroadcasterView.xaml
WalletWasabi.Gui/Controls/WalletExplorer/TransactionBroadcasterView.xaml
<TextBlock DockPanel.Dock="Top" Text="Insert PSBT or Transaction Hex" FontWeight="Bold" />
<DockPanel DockPanel.Dock="Bottom" LastChildFill="True">
-
- <Button DockPanel.Dock="Right" Command="{Binding ParseTransactionCommand}">
+ <Button DockPanel.Dock="Right" Command="{Binding BroadcastTransactionCommand}">
<StackPanel Orientation="Horizontal">
<controls:Spinner Height="20" Width="20" IsVisible="{Binding IsBusy}" Margin="0 0 8 0" />
- <TextBlock Text="Broadcast Transaction" />
+
+ <TextBlock Text ="{Binding ButtonText}">
+ </TextBlock>
</StackPanel>
</Button>
<i:Interaction.Behaviors>
<behaviors:CommandOnClickBehavior Command="{Binding PasteCommand}" />
</i:Interaction.Behaviors>
- <controls:ExtendedTextBox BorderThickness="0" Margin="0" Padding="0" Text="{Binding TransactionString}" Classes="selectableTextBlock" Watermark="Click here to insert from clipboard" TextWrapping="Wrap" AcceptsReturn="True">
+ <controls:ExtendedTextBox BorderThickness="0" Margin="0" Padding="0" Text="{Binding TransactionString}" IsReadOnly="{Binding IsBusy}" Watermark="Click here to insert from clipboard" TextWrapping="Wrap" AcceptsReturn="True">
<i:Interaction.Behaviors>
<behaviors:CommandOnClickBehavior Command="{Binding PasteCommand}" />
</i:Interaction.Behaviors>

MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/TransactionBroadcasterViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/TransactionBroadcasterViewModel.cs
@@ -4,6 +4,7 @@ using System;
using System.Reactive;
using System.Reactive.Disposables;
using System.Reactive.Linq;
+using System.Threading.Tasks;
namespace WalletWasabi.Gui.Controls.WalletExplorer
{
@@ -12,9 +13,12 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
private string _transactionString;
private string _errorMessage;
private string _successMessage;
+ private bool _isBusy;
+ private string _buttonText;
private CompositeDisposable Disposables { get; set; }
public ReactiveCommand<Unit, Unit> PasteCommand { get; set; }
+ public ReactiveCommand<Unit, Unit> BroadcastTransactionCommand { get; set; }
public string TransactionString
{
@@ -34,35 +38,41 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
set => this.RaiseAndSetIfChanged(ref _successMessage, value);
}
- public TransactionBroadcasterViewModel(WalletViewModel walletViewModel) : base("Transaction Broadcaster", walletViewModel)
- {
- PasteCommand = ReactiveCommand.CreateFromTask(async () =>
+ public bool IsBusy
{
- if (!string.IsNullOrEmpty(TransactionString)) return;
- var textToPaste = await Application.Current.Clipboard.GetTextAsync();
- TransactionString = textToPaste;
- });
-
- Observable.Merge(PasteCommand.ThrownExceptions).Subscribe(OnException);
+ get => _isBusy;
+ set => this.RaiseAndSetIfChanged(ref _isBusy, value);
}
- private static bool IsValidTransaction(string txstring)
+ public string ButtonText
{
- return false;
+ get => _buttonText;
+ set => this.RaiseAndSetIfChanged(ref _buttonText, value);
}
- private void OnTransactionTextChanged(string text)
+ public TransactionBroadcasterViewModel(WalletViewModel walletViewModel) : base("Transaction Broadcaster", walletViewModel)
{
- try
+ ButtonText = "Broadcast Transaction";
+
+ PasteCommand = ReactiveCommand.CreateFromTask(async () =>
{
- if (!IsValidTransaction(null))
+ if (!string.IsNullOrEmpty(TransactionString))
{
+ return;
}
- }
- catch (Exception ex)
+
+ var textToPaste = await Application.Current.Clipboard.GetTextAsync();
+ TransactionString = textToPaste;
+ });
+
+ BroadcastTransactionCommand = ReactiveCommand.CreateFromTask(async () =>
{
- OnException(ex);
- }
+ await OnDoTransactionBroadcastAsync();
+ });
+
+ Observable.Merge(PasteCommand.ThrownExceptions)
+ .Merge(BroadcastTransactionCommand.ThrownExceptions)
+ .Subscribe(OnException);
}
private void OnException(Exception ex)
@@ -79,8 +89,9 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
Disposables = new CompositeDisposable();
- var tc = this.WhenAnyValue(x => x.TransactionString)
- .Subscribe(OnTransactionTextChanged);
+ this.WhenAnyValue(x => x.TransactionString)
+ .Throttle(TimeSpan.FromSeconds(1))
+ .Subscribe(async (text) => await OnTransactionTextChangedAsync(text));
base.OnOpen();
}
@@ -90,7 +101,48 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
Disposables?.Dispose();
Disposables = null;
+ TransactionString = "";
+
return base.OnClose();
}
+
+ private async Task OnTransactionTextChangedAsync(string text)
+ {
+ try
+ {
+ if (string.IsNullOrEmpty(text))
+ {
+ return;
+ };
+
+ await BroadcastTransactionCommand.Execute();
+ }
+ catch (Exception ex)
+ {
+ OnException(ex);
+ }
+ }
+
+ private async Task OnDoTransactionBroadcastAsync()
+ {
+ try
+ {
+ IsBusy = true;
+ ButtonText = "Broadcasting Transaction...";
+
+ // TODO: Parse transaction and broadcast it.
+
+ await Task.Delay(3000);
+ }
+ catch (Exception ex)
+ {
+ OnException(ex);
+ }
+ finally
+ {
+ IsBusy = false;
+ ButtonText = "Broadcast Transaction";
+ }
+ }
}
}

Button mechanisms