Added Validation logics
This commit is contained in:
@@ -2,29 +2,56 @@
|
|||||||
x:Class="Wallet.Avalonia.CreateWalletView"
|
x:Class="Wallet.Avalonia.CreateWalletView"
|
||||||
xmlns="https://github.com/avaloniaui"
|
xmlns="https://github.com/avaloniaui"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:ui="using:FluentAvalonia.UI.Controls"
|
||||||
xmlns:vm="using:Wallet"
|
xmlns:vm="using:Wallet"
|
||||||
Title="Create Wallet"
|
Title="Create a new wallet"
|
||||||
x:DataType="vm:CreateWalletViewModel"
|
x:DataType="vm:CreateWalletViewModel"
|
||||||
CloseButtonText="Cancel"
|
CloseButtonText="Cancel"
|
||||||
IsPrimaryButtonEnabled="{Binding !Active}"
|
DefaultButton="Primary"
|
||||||
IsSecondaryButtonEnabled="{Binding !Active}"
|
|
||||||
PrimaryButtonText="Create">
|
PrimaryButtonText="Create">
|
||||||
|
<ContentDialog.Styles>
|
||||||
|
<Style Selector="ui|ContentDialog.Write">
|
||||||
|
<Setter Property="IsPrimaryButtonEnabled" Value="True" />
|
||||||
|
</Style>
|
||||||
|
<Style Selector="ui|ContentDialog.Read">
|
||||||
|
<Setter Property="IsPrimaryButtonEnabled" Value="False" />
|
||||||
|
</Style>
|
||||||
|
<Style Selector="ui|ContentDialog.Active">
|
||||||
|
<Setter Property="IsPrimaryButtonEnabled" Value="False" />
|
||||||
|
</Style>
|
||||||
|
</ContentDialog.Styles>
|
||||||
|
<Interaction.Behaviors>
|
||||||
|
<DataTriggerBehavior Binding="{Binding Validation.HasErrors}" Value="True">
|
||||||
|
<AddClassAction ClassName="Read" RemoveIfExists="True" />
|
||||||
|
<RemoveClassAction ClassName="Write" />
|
||||||
|
</DataTriggerBehavior>
|
||||||
|
<DataTriggerBehavior Binding="{Binding Validation.HasErrors}" Value="False">
|
||||||
|
<AddClassAction ClassName="Write" RemoveIfExists="True" />
|
||||||
|
<RemoveClassAction ClassName="Read" />
|
||||||
|
</DataTriggerBehavior>
|
||||||
|
<DataTriggerBehavior Binding="{Binding Active}" Value="True">
|
||||||
|
<AddClassAction ClassName="Active" RemoveIfExists="True" />
|
||||||
|
</DataTriggerBehavior>
|
||||||
|
<DataTriggerBehavior Binding="{Binding Active}" Value="False">
|
||||||
|
<RemoveClassAction ClassName="Active" />
|
||||||
|
</DataTriggerBehavior>
|
||||||
|
</Interaction.Behaviors>
|
||||||
<Grid>
|
<Grid>
|
||||||
<StackPanel Width="400" IsEnabled="{Binding !Active}">
|
<StackPanel
|
||||||
<TextBox
|
Width="400"
|
||||||
Margin="0,0,0,18"
|
IsEnabled="{Binding !Active}"
|
||||||
Text="{Binding Name}"
|
Spacing="18">
|
||||||
Watermark="Enter Wallet name" />
|
<StackPanel>
|
||||||
<TextBox
|
<TextBlock Margin="0,0,0,6" Text="Name" />
|
||||||
Margin="0,0,0,18"
|
<TextBox Text="{Binding Name}" Watermark="e.g. Personal" />
|
||||||
Classes="revealPasswordButton"
|
</StackPanel>
|
||||||
PasswordChar="●"
|
<StackPanel>
|
||||||
Text="{Binding Password}"
|
<TextBlock Margin="0,0,0,6" Text="Password" />
|
||||||
Watermark="Enter password" />
|
|
||||||
<TextBox
|
<TextBox
|
||||||
Classes="revealPasswordButton"
|
Classes="revealPasswordButton"
|
||||||
PasswordChar="●"
|
PasswordChar="●"
|
||||||
Watermark="Confirm password" />
|
Text="{Binding Password}" />
|
||||||
|
</StackPanel>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<ProgressRing
|
<ProgressRing
|
||||||
Width="48"
|
Width="48"
|
||||||
|
|||||||
@@ -1,17 +1,11 @@
|
|||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Reactive.Disposables;
|
|
||||||
using Toolkit.Foundation;
|
using Toolkit.Foundation;
|
||||||
|
|
||||||
namespace Wallet;
|
namespace Wallet;
|
||||||
|
|
||||||
public partial class CreateWalletViewModel(IServiceProvider provider,
|
public partial class CreateWalletViewModel : Observable,
|
||||||
IServiceFactory factory,
|
|
||||||
IPublisher publisher,
|
|
||||||
IMediator mediator,
|
|
||||||
ISubscriber subscriber,
|
|
||||||
IDisposer disposer) :
|
|
||||||
Observable(provider, factory, mediator, publisher, subscriber, disposer),
|
|
||||||
IPrimaryConfirmation
|
IPrimaryConfirmation
|
||||||
{
|
{
|
||||||
[MaybeNull]
|
[MaybeNull]
|
||||||
@@ -22,6 +16,32 @@ public partial class CreateWalletViewModel(IServiceProvider provider,
|
|||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private string password;
|
private string password;
|
||||||
|
|
||||||
|
[MaybeNull]
|
||||||
|
[ObservableProperty]
|
||||||
|
private string? repeatedPassword;
|
||||||
|
|
||||||
|
[ObservableProperty]
|
||||||
|
private IValidation validation;
|
||||||
|
|
||||||
|
public CreateWalletViewModel(IValidation validation,
|
||||||
|
IServiceProvider provider,
|
||||||
|
IServiceFactory factory,
|
||||||
|
IMediator mediator,
|
||||||
|
IPublisher publisher,
|
||||||
|
ISubscriber subscriber,
|
||||||
|
IDisposer disposer) : base(provider, factory, mediator, publisher, subscriber, disposer)
|
||||||
|
{
|
||||||
|
Validation = validation;
|
||||||
|
|
||||||
|
Validation.Add(() => Name, [new ValidationRule(() => Name is { Length: > 0 })],
|
||||||
|
ValidationTrigger.Immediate);
|
||||||
|
|
||||||
|
Validation.Add(() => Password, [new ValidationRule(() => Password is { Length: > 0 })],
|
||||||
|
ValidationTrigger.Immediate);
|
||||||
|
|
||||||
|
Name = name;
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<bool> ConfirmPrimary()
|
public async Task<bool> ConfirmPrimary()
|
||||||
{
|
{
|
||||||
using (await new ActivityLock(this))
|
using (await new ActivityLock(this))
|
||||||
@@ -30,4 +50,14 @@ public partial class CreateWalletViewModel(IServiceProvider provider,
|
|||||||
bool>(Create.As(new Wallet<(string, string)>((Name, Password))));
|
bool>(Create.As(new Wallet<(string, string)>((Name, Password))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void OnPropertyChanged(PropertyChangedEventArgs args)
|
||||||
|
{
|
||||||
|
if (args.PropertyName is string name)
|
||||||
|
{
|
||||||
|
Validation.Validate(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
base.OnPropertyChanged(args);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,24 +1,36 @@
|
|||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
using CommunityToolkit.Mvvm.Input;
|
using CommunityToolkit.Mvvm.Input;
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using Toolkit.Foundation;
|
using Toolkit.Foundation;
|
||||||
|
|
||||||
namespace Wallet;
|
namespace Wallet;
|
||||||
|
|
||||||
public partial class OpenWalletViewModel(IServiceProvider provider,
|
public partial class OpenWalletViewModel : Observable
|
||||||
|
{
|
||||||
|
private readonly IValidation validation;
|
||||||
|
|
||||||
|
[ObservableProperty]
|
||||||
|
private string? name;
|
||||||
|
|
||||||
|
[ObservableProperty]
|
||||||
|
private string? password;
|
||||||
|
|
||||||
|
|
||||||
|
[ObservableProperty]
|
||||||
|
private string? repeatedPassword;
|
||||||
|
|
||||||
|
public OpenWalletViewModel(IValidation validation,
|
||||||
|
IServiceProvider provider,
|
||||||
IServiceFactory factory,
|
IServiceFactory factory,
|
||||||
IMediator mediator,
|
IMediator mediator,
|
||||||
IPublisher publisher,
|
IPublisher publisher,
|
||||||
ISubscriber subscriber,
|
ISubscriber subscriber,
|
||||||
IDisposer disposer,
|
IDisposer disposer,
|
||||||
string name) :
|
string name) : base(provider, factory, mediator, publisher, subscriber, disposer)
|
||||||
Observable(provider, factory, mediator, publisher, subscriber, disposer)
|
|
||||||
{
|
{
|
||||||
[ObservableProperty]
|
this.validation = validation;
|
||||||
private string? name = name;
|
|
||||||
|
|
||||||
[ObservableProperty]
|
Name = name;
|
||||||
private string? password;
|
}
|
||||||
|
|
||||||
[RelayCommand]
|
[RelayCommand]
|
||||||
private async Task Invoke()
|
private async Task Invoke()
|
||||||
|
|||||||
Reference in New Issue
Block a user