Added Validation logics
This commit is contained in:
@@ -2,29 +2,56 @@
|
||||
x:Class="Wallet.Avalonia.CreateWalletView"
|
||||
xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:ui="using:FluentAvalonia.UI.Controls"
|
||||
xmlns:vm="using:Wallet"
|
||||
Title="Create Wallet"
|
||||
Title="Create a new wallet"
|
||||
x:DataType="vm:CreateWalletViewModel"
|
||||
CloseButtonText="Cancel"
|
||||
IsPrimaryButtonEnabled="{Binding !Active}"
|
||||
IsSecondaryButtonEnabled="{Binding !Active}"
|
||||
DefaultButton="Primary"
|
||||
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>
|
||||
<StackPanel Width="400" IsEnabled="{Binding !Active}">
|
||||
<TextBox
|
||||
Margin="0,0,0,18"
|
||||
Text="{Binding Name}"
|
||||
Watermark="Enter Wallet name" />
|
||||
<TextBox
|
||||
Margin="0,0,0,18"
|
||||
Classes="revealPasswordButton"
|
||||
PasswordChar="●"
|
||||
Text="{Binding Password}"
|
||||
Watermark="Enter password" />
|
||||
<TextBox
|
||||
Classes="revealPasswordButton"
|
||||
PasswordChar="●"
|
||||
Watermark="Confirm password" />
|
||||
<StackPanel
|
||||
Width="400"
|
||||
IsEnabled="{Binding !Active}"
|
||||
Spacing="18">
|
||||
<StackPanel>
|
||||
<TextBlock Margin="0,0,0,6" Text="Name" />
|
||||
<TextBox Text="{Binding Name}" Watermark="e.g. Personal" />
|
||||
</StackPanel>
|
||||
<StackPanel>
|
||||
<TextBlock Margin="0,0,0,6" Text="Password" />
|
||||
<TextBox
|
||||
Classes="revealPasswordButton"
|
||||
PasswordChar="●"
|
||||
Text="{Binding Password}" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
<ProgressRing
|
||||
Width="48"
|
||||
|
||||
@@ -1,17 +1,11 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Reactive.Disposables;
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Wallet;
|
||||
|
||||
public partial class CreateWalletViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IPublisher publisher,
|
||||
IMediator mediator,
|
||||
ISubscriber subscriber,
|
||||
IDisposer disposer) :
|
||||
Observable(provider, factory, mediator, publisher, subscriber, disposer),
|
||||
public partial class CreateWalletViewModel : Observable,
|
||||
IPrimaryConfirmation
|
||||
{
|
||||
[MaybeNull]
|
||||
@@ -22,6 +16,32 @@ public partial class CreateWalletViewModel(IServiceProvider provider,
|
||||
[ObservableProperty]
|
||||
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()
|
||||
{
|
||||
using (await new ActivityLock(this))
|
||||
@@ -30,4 +50,14 @@ public partial class CreateWalletViewModel(IServiceProvider provider,
|
||||
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,25 +1,37 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Wallet;
|
||||
|
||||
public partial class OpenWalletViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
ISubscriber subscriber,
|
||||
IDisposer disposer,
|
||||
string name) :
|
||||
Observable(provider, factory, mediator, publisher, subscriber, disposer)
|
||||
public partial class OpenWalletViewModel : Observable
|
||||
{
|
||||
private readonly IValidation validation;
|
||||
|
||||
[ObservableProperty]
|
||||
private string? name = name;
|
||||
private string? name;
|
||||
|
||||
[ObservableProperty]
|
||||
private string? password;
|
||||
|
||||
|
||||
[ObservableProperty]
|
||||
private string? repeatedPassword;
|
||||
|
||||
public OpenWalletViewModel(IValidation validation,
|
||||
IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
ISubscriber subscriber,
|
||||
IDisposer disposer,
|
||||
string name) : base(provider, factory, mediator, publisher, subscriber, disposer)
|
||||
{
|
||||
this.validation = validation;
|
||||
|
||||
Name = name;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task Invoke()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user