Skip to content

Commit 5e8ea19

Browse files
committed
wire up validators again
1 parent 44f9528 commit 5e8ea19

3 files changed

Lines changed: 52 additions & 59 deletions

File tree

WriteUpProject/Views/MainView.axaml.cs

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -40,63 +40,6 @@ private void GenerateTXHex(object? sender, Avalonia.Interactivity.RoutedEventArg
4040
}
4141
}
4242
43-
private void ResetForm(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
44-
{
45-
MessageBox.Text = "";
46-
TxIdBox.Text = "";
47-
VoutBox.Text = "";
48-
AmountBox.Text = "";
49-
ChangeAddressBox.Text = "";
50-
FeeBox.Text = "";
51-
}
52-
53-
public void OnMessageChanged(object? sender, TextChangedEventArgs e)
54-
{
55-
string msg = MessageBox.Text ?? "";
56-
int byteLength = Encoding.UTF8.GetBytes(msg).Length;
57-
58-
if (byteLength > 80)
59-
{
60-
MessageByteCounter.Text = $"⚠️ Too long: {byteLength}/80 bytes";
61-
MessageByteCounter.Foreground = Brushes.Red;
62-
}
63-
else
64-
{
65-
MessageByteCounter.Text = $"🧮 {byteLength}/80 bytes";
66-
MessageByteCounter.Foreground = Brushes.Gray;
67-
}
68-
}
69-
public void OnTxIdChanged(object? sender, TextChangedEventArgs e)
70-
{
71-
string txid = TxIdBox.Text?.Trim() ?? "";
72-
if (uint256.TryParse(txid, out _))
73-
{
74-
TxIdValidator.Text = "✅ Valid TXID";
75-
TxIdValidator.Foreground = Brushes.Green;
76-
}
77-
else
78-
{
79-
TxIdValidator.Text = "⚠️ Invalid TXID";
80-
TxIdValidator.Foreground = Brushes.Red;
81-
}
82-
}
83-
84-
public void ChangeAddressChanged(object? sender, Avalonia.Controls.TextChangedEventArgs e)
85-
{
86-
int networkOptionIndex = NetworkCombobox.SelectedIndex;
87-
Network network = Helper.SupportedNetworks[networkOptionIndex];
88-
89-
if (Helper.TryParseAddress(ChangeAddressBox.Text ?? "", network))
90-
{
91-
ChangeAddressValidator.Text = "✅ Valid Address";
92-
ChangeAddressValidator.Foreground = Brushes.Green;
93-
}
94-
else
95-
{
96-
ChangeAddressValidator.Text = "⚠️ Invalid Address";
97-
ChangeAddressValidator.Foreground = Brushes.Red;
98-
}
99-
}
10043
10144
public async void SavePSBT(object? sender, RoutedEventArgs args)
10245
{

WriteUpProject/Views/Pages/Page2View.axaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,12 @@
141141
<!-- Message -->
142142
<StackPanel Spacing="8" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="3">
143143
<TextBlock Classes="label" Text="Message"/>
144-
<TextBox x:Name="CustomMessageBox"
144+
<TextBox x:Name="MessageBox"
145145
Classes="modern-input"
146146
Text="{Binding CustomMessage}"
147147
Watermark="Enter the change address"
148148
TextChanged="OnMessageChanged"/>
149-
<TextBlock x:Name="MessageValidator" Classes="validator"/>
149+
<TextBlock x:Name="MessageByteCounter" Classes="validator"/>
150150
</StackPanel>
151151

152152
<StackPanel Grid.Column="1" Grid.Row="4">

WriteUpProject/Views/Pages/Page2View.axaml.cs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
using Avalonia.Controls;
2+
using Avalonia.Media;
3+
using NBitcoin;
4+
using System.Linq;
5+
using System.Text;
6+
using WriteUpProject.Crypto;
27

38
namespace WriteUpProject.Views.Pages
49
{
@@ -11,14 +16,59 @@ public Page2View()
1116

1217
private void ChangeAddressChanged(object? sender, TextChangedEventArgs e)
1318
{
19+
var networks = new[] { Network.Main, Network.TestNet, Network.TestNet4, Network.RegTest };
20+
var input = ChangeAddressBox.Text ?? string.Empty;
21+
22+
bool isValid = networks.Any(n => Helper.TryParseAddress(input, n));
23+
24+
if (isValid)
25+
{
26+
AddressValidator.Text = "✅ Valid Address";
27+
AddressValidator.Foreground = Brushes.Green;
28+
}
29+
else
30+
{
31+
AddressValidator.Text = "⚠️ Invalid Address";
32+
AddressValidator.Foreground = Brushes.Red;
33+
}
1434
}
1535

1636
private void OnMessageChanged(object? sender, TextChangedEventArgs e)
1737
{
38+
string msg = MessageBox.Text ?? "";
39+
int byteLength = Encoding.UTF8.GetBytes(msg).Length;
40+
41+
if (byteLength > 80)
42+
{
43+
MessageByteCounter.Text = $"⚠️ Too long: {byteLength}/80 bytes";
44+
MessageByteCounter.Foreground = Brushes.Red;
45+
}
46+
else
47+
{
48+
MessageByteCounter.Text = $"🧮 {byteLength}/80 bytes";
49+
MessageByteCounter.Foreground = Brushes.Gray;
50+
}
1851
}
1952

2053
private void OnFeeRateChanged(object? sender, TextChangedEventArgs e)
2154
{
55+
if(int.TryParse(FeeRateBox.Text, out int feeRate))
56+
{
57+
if (feeRate > 10)
58+
{
59+
FeeRateValidator.Text = "⚠️ Warning: High FeeRate. Please check the average transaction fee, before wasting too much money.";
60+
FeeRateValidator.Foreground = Brushes.Gray;
61+
}
62+
else
63+
{
64+
FeeRateValidator.Text = string.Empty;
65+
}
66+
}
67+
else
68+
{
69+
FeeRateValidator.Text = "⚠️ Invalid FeeRate";
70+
FeeRateValidator.Foreground = Brushes.Red;
71+
}
2272
}
2373
}
2474
}

0 commit comments

Comments
 (0)