Skip to content

Commit

Permalink
Password check message improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
michielpost committed Oct 18, 2024
1 parent 34de312 commit a80aa4b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/aoWebWallet/Pages/GenerateWalletPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
Adornment="Adornment.End"
AdornmentIcon="@PasswordInputIcon"
OnAdornmentClick="TogglePasswordVisibility"
Error="@(!string.IsNullOrEmpty(PasswordError))"
ErrorText="@PasswordError"
/>

<MudTextField @bind-Value="ConfirmPassword"
Expand All @@ -29,6 +31,8 @@
Adornment="Adornment.End"
AdornmentIcon="@PasswordInputIcon"
OnAdornmentClick="TogglePasswordVisibility"
Error="@(!string.IsNullOrEmpty(ConfirmPasswordError))"
ErrorText="@ConfirmPasswordError"
/>

<MudButton Variant="Variant.Filled"
Expand Down
20 changes: 15 additions & 5 deletions src/aoWebWallet/Pages/GenerateWalletPage.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public partial class GenerateWalletPage : MvvmComponentBase<MainViewModel>
private bool PasswordVisible { get; set; } = false;
private InputType PasswordInput { get; set; } = InputType.Password;
private string PasswordInputIcon { get; set; } = Icons.Material.Filled.VisibilityOff;
private string PasswordError { get; set; } = string.Empty;
private string ConfirmPasswordError { get; set; } = string.Empty;

private void TogglePasswordVisibility()
{
Expand All @@ -30,28 +32,36 @@ private void TogglePasswordVisibility()

private void GenerateWallet()
{
PasswordError = string.Empty;
ConfirmPasswordError = string.Empty;

if (string.IsNullOrWhiteSpace(Password) || string.IsNullOrWhiteSpace(ConfirmPassword))
{
Snackbar.Add("Please enter and confirm your password.", Severity.Warning);
PasswordError = "Please enter and confirm your password.";
return;
}

if (Password != ConfirmPassword)
{
Snackbar.Add("Passwords do not match.", Severity.Error);
ConfirmPasswordError = "Passwords do not match.";
return;
}

if (Password.Length < 6)
{
Snackbar.Add("Password must be at least 6 characters long.", Severity.Warning);
PasswordError = "Password must be at least 6 characters long.";
return;
}

if(BindingContext.WalletList.Data?.Any(x => x.NeedsUnlock) ?? true)
{
PasswordError = "Unable to set a new password. Please unlock your wallet first.";
return;
}

BindingContext.SecretKey = Password;

// TODO: Implement wallet generation logic here
Snackbar.Add("Wallet generated successfully!", Severity.Success);
Snackbar.Add("Password set successfully!", Severity.Success);
}
}
}
2 changes: 1 addition & 1 deletion src/aoWebWallet/Shared/AddGenerateWalletComponent.razor
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</MudFocusTrap>

<MudText DefaultFocus="DefaultFocus" Color="Color.Secondary">@Progress</MudText>
<div Class="d-w-100 d-flex justify-center mt-2">
<div Class="d-w-100 d-flex mt-2">
<MudButton Disabled="ButtonDisabled" Class="text-transform-none" Color="Color.Primary" Variant="Variant.Filled" OnClick="Submit">
Create aoWW Wallet
</MudButton>
Expand Down

0 comments on commit a80aa4b

Please sign in to comment.