Skip to content

Commit

Permalink
user pin validation when getting credential
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkbee1 committed Jun 5, 2024
1 parent cb928b2 commit 3365fbd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 35 deletions.
60 changes: 26 additions & 34 deletions lib/dashboard/user_pin/view/user_pin_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ class UserPinPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (context) =>
PinCodeViewCubit(),
create: (context) => PinCodeViewCubit(),
child: UserPinView(
onCancel: onCancel,
onProceed: onProceed,
Expand Down Expand Up @@ -79,42 +78,35 @@ class _UserPinViewState extends State<UserPinView> {
@override
Widget build(BuildContext context) {
final l10n = context.l10n;
return BlocBuilder<ProfileCubit, ProfileState>(
builder: (context, state) {
return WillPopScope(
onWillPop: () async => false,
child: BasePage(
backgroundColor: Theme.of(context).colorScheme.background,
scrollView: false,
body: PinCodeWidget(
title: widget.txCode?.description ??
l10n.pleaseInsertTheSecredCodeReceived,
passwordDigits: widget.txCode?.length ?? 4,
deleteButton: Text(
l10n.delete,
style: Theme.of(context).textTheme.labelLarge,
),
cancelButton: Text(
l10n.cancel,
style: Theme.of(context).textTheme.labelLarge,
),
cancelCallback: _onPasscodeCancelled,
isValidCallback: () {
Navigator.pop(context);
widget.onProceed.call(pinCodeValue!);
},
),
return WillPopScope(
onWillPop: () async => false,
child: BasePage(
backgroundColor: Theme.of(context).colorScheme.surface,
scrollView: false,
body: PinCodeWidget(
title: widget.txCode?.description ??
l10n.pleaseInsertTheSecredCodeReceived,
passwordDigits: widget.txCode?.length ?? 4,
deleteButton: Text(
l10n.delete,
style: Theme.of(context).textTheme.labelLarge,
),
);
},
cancelButton: Text(
l10n.cancel,
style: Theme.of(context).textTheme.labelLarge,
),
cancelCallback: _onPasscodeCancelled,
isValidCallback: () {
Navigator.pop(context);
widget.onProceed
.call(context.read<PinCodeViewCubit>().state.enteredPasscode);
},
isUserPin: true,
),
),
);
}

Future<void> _onPasscodeEntered(String enteredPasscode) async {
pinCodeValue = enteredPasscode;
_verificationNotifier.add(true);
}

void _onPasscodeCancelled() {
Navigator.of(context).pop();
widget.onCancel.call();
Expand Down
9 changes: 8 additions & 1 deletion lib/pin_code/widgets/pin_code_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class PinCodeWidget extends StatefulWidget {
this.header,
this.onLoginAttempt,
this.isNewCode = false,
this.isUserPin = false,
}) : circleUIConfig = circleUIConfig ?? const CircleUIConfig(),
keyboardUIConfig = keyboardUIConfig ?? const KeyboardUIConfig();

Expand All @@ -33,6 +34,8 @@ class PinCodeWidget extends StatefulWidget {
final String? subTitle;
final int passwordDigits;
final bool isNewCode;
// When a specific pin is requested to get a credential
final bool isUserPin;

// Cancel button and delete button will be switched based on the screen state
final Widget cancelButton;
Expand Down Expand Up @@ -74,7 +77,7 @@ class _PinCodeWidgetState extends State<PinCodeWidget>
});
}
if (current.enteredPasscode.length == widget.passwordDigits) {
if (current.isPinCodeValid) {
if (current.isPinCodeValid || widget.isUserPin) {
_validationCallback();
} else {
if (widget.title == l10n.confirmYourPinCode) {
Expand All @@ -89,6 +92,10 @@ class _PinCodeWidgetState extends State<PinCodeWidget>
listener: (context, state) {
widget.onLoginAttempt
?.call(state.loginAttemptCount, state.loginAttemptsRemaining);
// if (state.enteredPasscode.length == widget.passwordDigits &&
// widget.isUserPin) {
// _validationCallback();
// }
},
builder: (context, state) {
final enteredPasscode = state.enteredPasscode;
Expand Down

0 comments on commit 3365fbd

Please sign in to comment.