Skip to content
Permalink
Browse files

Paste bitcoin address automatically

  • Loading branch information...
lontivero committed Nov 5, 2018
1 parent 2911726 commit 49508518a3c573fc57d02e55c06bf8cddb71dc96
@@ -0,0 +1,57 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Input.Platform;
using Avalonia.Interactivity;
using Avalonia.Xaml.Interactivity;
using NBitcoin;
using System;
using System.Reactive.Disposables;
using System.Reactive.Linq;

namespace WalletWasabi.Gui.Behaviors
{
internal class PasteAddressOnClickBehavior : Behavior<TextBox>
{
private CompositeDisposable _disposables = new CompositeDisposable();

public void PasteClipboardContentIfBitcoinAddress()
{
var clipboard = (IClipboard)AvaloniaLocator.Current.GetService(typeof(IClipboard));
var text = clipboard.GetTextAsync().GetAwaiter().GetResult();

try
{
var address = BitcoinAddress.Create(text, Global.Network);
if(address is BitcoinWitPubKeyAddress)
{
if(string.IsNullOrWhiteSpace(AssociatedObject.Text) )
AssociatedObject.Text = text;
}
}
catch(FormatException)
{
}
}

protected override void OnAttached()
{
_disposables = new CompositeDisposable
{
Observable.FromEventPattern<RoutedEventArgs>(AssociatedObject, nameof(AssociatedObject.LostFocus)).Subscribe(args=>
{
PasteClipboardContentIfBitcoinAddress();
})
};

base.OnAttached();
}

protected override void OnDetaching()
{
base.OnDetaching();

_disposables.Dispose();
}
}
}
@@ -24,7 +24,11 @@
<DockPanel LastChildFill="True" Margin="20">
<StackPanel DockPanel.Dock="Bottom" Margin="0 10" Spacing="10" HorizontalAlignment="Left">
<TextBlock>Note that, you must select coins you want to spend from.</TextBlock>
<controls:ExtendedTextBox Text="{Binding Address}" Watermark="Address" UseFloatingWatermark="True" />
<controls:ExtendedTextBox Text="{Binding Address}" Watermark="Address" UseFloatingWatermark="True" >
<i:Interaction.Behaviors>
<behaviors:PasteAddressOnClickBehavior />
</i:Interaction.Behaviors>
</controls:ExtendedTextBox>
<controls:ExtendedTextBox Text="{Binding Label}" Watermark="Label" UseFloatingWatermark="True">
<ToolTip.Tip>
Start labelling today and your privacy will thank you tomorrow!

0 comments on commit 4950851

Please sign in to comment.
You can’t perform that action at this time.