Skip to content

Commit

Permalink
Add a new add/edit window
Browse files Browse the repository at this point in the history
  • Loading branch information
Coding-Enthusiast committed Feb 18, 2025
1 parent 68f3f01 commit 49e9a41
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 0 deletions.
3 changes: 3 additions & 0 deletions WatchOnlyBitcoinWallet/App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
<DataTemplate DataType="{x:Type vm:AboutViewModel}">
<views:AboutView/>
</DataTemplate>
<DataTemplate DataType="{x:Type vm:AddEditViewModel}">
<views:AddEditView/>
</DataTemplate>
<DataTemplate DataType="{x:Type vm:SettingsViewModel}">
<views:SettingsView/>
</DataTemplate>
Expand Down
86 changes: 86 additions & 0 deletions WatchOnlyBitcoinWallet/ViewModels/AddEditViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// WatchOnlyBitcoinWallet
// Copyright (c) 2016 Coding Enthusiast
// Distributed under the MIT software license, see the accompanying
// file LICENCE or http://www.opensource.org/licenses/mit-license.php.

using Autarkysoft.Bitcoin;
using Autarkysoft.Bitcoin.Encoders;
using WatchOnlyBitcoinWallet.MVVM;

namespace WatchOnlyBitcoinWallet.ViewModels
{
public class AddEditViewModel : ViewModelBase
{
public AddEditViewModel() : this(string.Empty, string.Empty)
{
}

public AddEditViewModel(string addr, string tag)
{
// Set fields since we don't want to change IsChanged to true.
_addr = addr;
_tag = tag;

OkCommand = new(Ok);
CancelCommand = new(Cancel);
}


public bool IsChanged { get; private set; } = false;

private string _addr;
public string AddressString
{
get => _addr;
set
{
if (SetField(ref _addr, value))
{
IsChanged = true;
}
}
}

private string _tag;
public string Tag
{
get => _tag;
set
{
if (SetField(ref _tag, value))
{
IsChanged = true;
}
}
}

private string _error = string.Empty;
public string Error
{
get => _error;
set => SetField(ref _error, value);
}


public BindableCommand OkCommand { get; }
private void Ok()
{
AddressType type = Address.GetAddressType(AddressString, NetworkType.MainNet);
if (type is AddressType.Unknown or AddressType.Invalid)
{
Error = "Invalid address type.";
}
else
{
RaiseCloseEvent();
}
}

public BindableCommand CancelCommand { get; }
private void Cancel()
{
IsChanged = false;
RaiseCloseEvent();
}
}
}
40 changes: 40 additions & 0 deletions WatchOnlyBitcoinWallet/Views/AddEditView.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:WatchOnlyBitcoinWallet.ViewModels"
mc:Ignorable="d"
x:Class="WatchOnlyBitcoinWallet.Views.AddEditView"
Height="110" Width="480"
FontSize="14">

<Design.DataContext>
<vm:AboutViewModel/>
</Design.DataContext>

<Grid ColumnDefinitions="400,*" RowDefinitions="auto,auto,*">
<TextBox Text="{Binding AddressString}"
Watermark="Enter a valid bitcoin address"
Margin="2"
Grid.Column="0" Grid.Row="0"/>
<TextBox Text="{Binding Tag}"
Watermark="[Optional] Enter a name for this address"
Margin="2"
Grid.Column="0" Grid.Row="1"/>
<TextBlock Text="{Binding Error}"
Grid.Column="0" Grid.Row="2"/>

<Button Content="OK"
Command="{Binding OkCommand}"
HorizontalContentAlignment="Center"
IsDefault="True"
Width="65"
Grid.Column="1" Grid.Row="0"/>
<Button Content="Cancel"
Command="{Binding CancelCommand}"
HorizontalContentAlignment="Center"
IsCancel="True"
Width="65"
Grid.Column="1" Grid.Row="1"/>
</Grid>
</UserControl>
17 changes: 17 additions & 0 deletions WatchOnlyBitcoinWallet/Views/AddEditView.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// WatchOnlyBitcoinWallet
// Copyright (c) 2016 Coding Enthusiast
// Distributed under the MIT software license, see the accompanying
// file LICENCE or http://www.opensource.org/licenses/mit-license.php.

using Avalonia.Controls;

namespace WatchOnlyBitcoinWallet.Views
{
public partial class AddEditView : UserControl
{
public AddEditView()
{
InitializeComponent();
}
}
}

0 comments on commit 49e9a41

Please sign in to comment.