Move parsers to Helpers
MODIFY
WalletWasabi.Gui/Behaviors/PasteAddressOnClickBehavior.cs
WalletWasabi.Gui/Behaviors/PasteAddressOnClickBehavior.cs
@@ -12,6 +12,7 @@ using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Threading.Tasks;
using WalletWasabi.Gui.Controls;
+using WalletWasabi.Helpers;
namespace WalletWasabi.Gui.Behaviors
{
@@ -68,18 +69,16 @@ namespace WalletWasabi.Gui.Behaviors
}
text = text.Trim();
- var addressText = IsBitcoinAddress(text, Global.Network);
- if (addressText.isValid)
+ if (AddressStringParser.TryParseBitcoinAddress(text, Global.Network, out BitcoinUrlBuilder addressResult))
{
- result = addressText.url;
+ result = addressResult;
return true;
}
else
{
- var urlText = IsBitcoinUrl(text, Global.Network);
- if (urlText.isValid)
+ if (AddressStringParser.TryParseBitcoinUrl(text, Global.Network, out BitcoinUrlBuilder urlResult))
{
- result = urlText.url;
+ result = urlResult;
return true;
}
}
@@ -99,37 +98,6 @@ namespace WalletWasabi.Gui.Behaviors
return false;
}
- private (bool isValid, BitcoinUrlBuilder url) IsBitcoinAddress(string text, Network expectedNetwork)
- {
- if (text.Length > 100)
- {
- return (false, null);
- }
-
- try
- {
- var bitcoinAddress = BitcoinAddress.Create(text, expectedNetwork);
- return (true, new BitcoinUrlBuilder($"bitcoin:{bitcoinAddress}"));
- }
- catch (FormatException)
- {
- return (false, null);
- }
- }
-
- private (bool isValid, BitcoinUrlBuilder url) IsBitcoinUrl(string text, Network expectedNetwork)
- {
- try
- {
- var bitcoinUrl = new BitcoinUrlBuilder(text);
- return (bitcoinUrl.Address.Network == expectedNetwork, bitcoinUrl);
- }
- catch (FormatException)
- {
- return (false, null);
- }
- }
-
public PasteAddressOnClickBehavior()
{
Global = Application.Current.Resources[Global.GlobalResourceKey] as Global;

ADD
WalletWasabi/Helpers/AddressStringParser.cs
+using NBitcoin;
+using NBitcoin.Payment;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace WalletWasabi.Helpers
+{
+ public static class AddressStringParser
+ {
+ public static bool TryParseBitcoinAddress(string text, Network expectedNetwork, out BitcoinUrlBuilder url)
+ {
+ url = null;
+
+ if (text is null || text.Length > 100 || text.Length < 20)
+ {
+ return false;
+ }
+
+ try
+ {
+ var bitcoinAddress = BitcoinAddress.Create(text, expectedNetwork);
+ url = new BitcoinUrlBuilder($"bitcoin:{bitcoinAddress}");
+ return true;
+ }
+ catch (FormatException)
+ {
+ return false;
+ }
+ }
+
+ public static bool TryParseBitcoinUrl(string text, Network expectedNetwork, out BitcoinUrlBuilder url)
+ {
+ url = null;
+
+ if (text is null || text.Length > 1000 || text.Length < 20)
+ {
+ return false;
+ }
+
+ try
+ {
+ var bitcoinUrl = new BitcoinUrlBuilder(text);
+ if (bitcoinUrl.Address.Network == expectedNetwork)
+ {
+ url = bitcoinUrl;
+ return true;
+ }
+
+ return false;
+ }
+ catch (FormatException)
+ {
+ return false;
+ }
+ }
+ }
+}

Move parsers to Helpers