Refactor: move PasteAddressOnClick external control updates to the ViewModel
MODIFY
WalletWasabi.Gui/Behaviors/PasteAddressOnClickBehavior.cs
WalletWasabi.Gui/Behaviors/PasteAddressOnClickBehavior.cs
@@ -13,7 +13,7 @@ using System.Threading.Tasks;
namespace WalletWasabi.Gui.Behaviors
{
- internal class PasteAddressOnClickBehavior : Behavior<TextBox>
+ internal class PasteAddressOnClickBehavior : CommandBasedBehavior<TextBox>
{
private CompositeDisposable Disposables { get; set; }
@@ -56,13 +56,13 @@ namespace WalletWasabi.Gui.Behaviors
private TextBoxState _textBoxState = TextBoxState.None;
- public async Task<(bool isAddress, BitcoinUrlBuilder url)> ProcessClipboardAsync()
+ public async Task<(bool isValid, BitcoinUrlBuilder url)> ProcessClipboardAsync()
{
var result = await IsThereABitcoinAddressOnTheClipboardAsync();
- return result.isAddress ? result : await IsThereABitcoinUrlOnTheClipboardAsync();
+ return result.isValid ? result : await IsThereABitcoinUrlOnTheClipboardAsync();
}
- public async Task<(bool isAddress, BitcoinUrlBuilder url)> IsThereABitcoinAddressOnTheClipboardAsync()
+ public async Task<(bool isValid, BitcoinUrlBuilder url)> IsThereABitcoinAddressOnTheClipboardAsync()
{
var global = Application.Current.Resources[Global.GlobalResourceKey] as Global;
var network = global.Network;
@@ -84,7 +84,7 @@ namespace WalletWasabi.Gui.Behaviors
}
}
- public async Task<(bool isAddress, BitcoinUrlBuilder url)> IsThereABitcoinUrlOnTheClipboardAsync()
+ public async Task<(bool isValid, BitcoinUrlBuilder url)> IsThereABitcoinUrlOnTheClipboardAsync()
{
var global = Application.Current.Resources[Global.GlobalResourceKey] as Global;
var network = global.Network;
@@ -125,7 +125,7 @@ namespace WalletWasabi.Gui.Behaviors
AssociatedObject.GetObservable(InputElement.PointerReleasedEvent).Subscribe(async pointer =>
{
var uiConfig = Application.Current.Resources[Global.UiConfigResourceKey] as UiConfig;
- if (uiConfig.Autocopy is false)
+ if (uiConfig.Autocopy is null || uiConfig.Autocopy is false)
{
return;
}
@@ -135,39 +135,12 @@ namespace WalletWasabi.Gui.Behaviors
case TextBoxState.AddressInsert:
var result = await ProcessClipboardAsync();
- if (result.isAddress)
+ if (result.isValid)
{
- AssociatedObject.Text = result.url.Address.ToString();
+ CommandParameter = result.url;
+ ExecuteCommand();
}
MyTextBoxState = TextBoxState.NormalTextBoxOperation;
- var labeltextbox = AssociatedObject.Parent.FindControl<TextBox>("LabelTextBox");
- if (labeltextbox != null)
- {
- if (!string.IsNullOrEmpty(result.url.Label))
- {
- labeltextbox.Text = result.url.Label;
-
- var amountTextBox = AssociatedObject.Parent.FindControl<TextBox>("AmountTextBox");
- if (amountTextBox != null)
- {
- if (result.url.Amount != null)
- {
- amountTextBox.Text = result.url.Amount.ToString(false, true);
- }
-
- amountTextBox.Focus();
- }
- else
- {
- labeltextbox.Focus();
- }
- }
- else
- {
- labeltextbox.Focus();
- }
- }
-
break;
case TextBoxState.SelectAll:
@@ -201,7 +174,7 @@ namespace WalletWasabi.Gui.Behaviors
if (string.IsNullOrEmpty(AssociatedObject.Text))
{
var result = await ProcessClipboardAsync();
- if (result.isAddress)
+ if (result.isValid)
{
MyTextBoxState = TextBoxState.AddressInsert;
}

MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/SendTabView.xaml
WalletWasabi.Gui/Controls/WalletExplorer/SendTabView.xaml
<TextBlock>You must select coins you want to spend from.</TextBlock>
<controls:ExtendedTextBox Text="{Binding Address}" Watermark="Address" UseFloatingWatermark="True">
<i:Interaction.Behaviors>
- <behaviors:PasteAddressOnClickBehavior />
+ <behaviors:PasteAddressOnClickBehavior Command="{Binding OnAddressPasteCommand}" />
</i:Interaction.Behaviors>
</controls:ExtendedTextBox>
<StackPanel Spacing="8">

MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/SendTabViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/SendTabViewModel.cs
@@ -2,6 +2,7 @@ using Avalonia.Threading;
using AvalonStudio.Extensibility;
using AvalonStudio.Shell;
using NBitcoin;
+using NBitcoin.Payment;
using ReactiveUI;
using System;
using System.Collections.Generic;
@@ -224,6 +225,24 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
FeeRateCommand = ReactiveCommand.Create(ChangeFeeRateDisplay, outputScheduler: RxApp.MainThreadScheduler);
+ OnAddressPasteCommand = ReactiveCommand.Create((BitcoinUrlBuilder url) =>
+ {
+ if (url.Address != null)
+ {
+ Address = url.Address.ToString();
+ }
+
+ if (!string.IsNullOrWhiteSpace(url.Label))
+ {
+ Label = url.Label;
+ }
+
+ if (url.Amount != null)
+ {
+ AmountText = url.Amount.ToString(false, true);
+ }
+ });
+
BuildTransactionCommand = ReactiveCommand.CreateFromTask(async () =>
{
try
@@ -1007,6 +1026,9 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
public ReactiveCommand<Unit, Unit> MaxCommand { get; }
public ReactiveCommand<Unit, Unit> FeeRateCommand { get; }
+
+ public ReactiveCommand<BitcoinUrlBuilder, Unit> OnAddressPasteCommand { get; }
+
public bool IsTransactionBuilder { get; }
public override void OnOpen()

Refactor: move PasteAddressOnClick external control updates to the ViewModel