Address Paste Improvement
MODIFY
WalletWasabi.Gui/Behaviors/PasteAddressOnClickBehavior.cs
WalletWasabi.Gui/Behaviors/PasteAddressOnClickBehavior.cs
@@ -7,6 +7,7 @@ using NBitcoin;
using System;
using System.Reactive.Disposables;
using System.Reactive.Linq;
+using System.Threading.Tasks;
namespace WalletWasabi.Gui.Behaviors
{
@@ -16,20 +17,37 @@ namespace WalletWasabi.Gui.Behaviors
public void PasteClipboardContentIfBitcoinAddress()
{
- var clipboard = (IClipboard)AvaloniaLocator.Current.GetService(typeof(IClipboard));
- var text = clipboard.GetTextAsync().GetAwaiter().GetResult();
+ if(IsThereABitcoinAddressOnTheClipboard(out string address))
+ {
+ if(string.IsNullOrWhiteSpace(AssociatedObject.Text) )
+ AssociatedObject.Text = address;
+ }
+ }
- try
+ public bool IsThereABitcoinAddressOnTheClipboard(out string address)
{
- var address = BitcoinAddress.Create(text, Global.Network);
- if(address is BitcoinWitPubKeyAddress)
+ address = string.Empty;
+
+ var clipboard = (IClipboard)AvaloniaLocator.Current.GetService(typeof(IClipboard));
+
+ // TODO: fix this
+ var clipboardTask = clipboard.GetTextAsync();
+ Task.WaitAny(Task.Delay(10), clipboardTask);
+ if(!clipboardTask.IsCompleted)
{
- if(string.IsNullOrWhiteSpace(AssociatedObject.Text) )
- AssociatedObject.Text = text;
+ return false;
}
+
+ var text = clipboardTask.Result;
+ try
+ {
+ var bitcoinAddress = BitcoinAddress.Create(text, Global.Network);
+ address = text;
+ return bitcoinAddress is BitcoinWitPubKeyAddress;
}
catch(FormatException)
{
+ return false;
}
}
@@ -39,13 +57,41 @@ namespace WalletWasabi.Gui.Behaviors
{
AssociatedObject.GetObservable(TextBox.IsFocusedProperty).Subscribe(focused =>
{
- if(focused && string.IsNullOrWhiteSpace(AssociatedObject.Text))
+ if(focused)
+ {
+ if(string.IsNullOrWhiteSpace(AssociatedObject.Text))
{
PasteClipboardContentIfBitcoinAddress();
}
+ }
})
};
+ _disposables.Add(
+ AssociatedObject.GetObservable(TextBox.PointerReleasedEvent).Subscribe(pointer =>
+ {
+ if(!string.IsNullOrWhiteSpace(AssociatedObject.Text))
+ {
+ AssociatedObject.SelectionStart = 0;
+ AssociatedObject.SelectionEnd = AssociatedObject.Text?.Length ?? 0;
+ }
+ })
+ );
+
+ _disposables.Add(
+ AssociatedObject.GetObservable(TextBox.PointerEnterEvent).Subscribe(pointerEnter =>
+ {
+ if(IsThereABitcoinAddressOnTheClipboard(out string address))
+ {
+ ToolTip.SetTip(AssociatedObject, "Click to paste address from clipboard");
+ }
+ else
+ {
+ ToolTip.SetTip(AssociatedObject, "");
+ }
+ })
+ );
+
base.OnAttached();
}

Address Paste Improvement