mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-12-01 12:04:21 +01:00
CW-1290-Add-Duress-pin-feature (#2664)
* add duress PIN feature * add localization * Update configure.dart * Update configure.dart * add duress PIN validation logic * - fix error popup - put behind a feature flag --------- Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
This commit is contained in:
@@ -9,8 +9,12 @@ import 'package:cake_wallet/src/screens/pin_code/pin_code_widget.dart';
|
||||
import 'package:cake_wallet/src/screens/settings/widgets/settings_cell_with_arrow.dart';
|
||||
import 'package:cake_wallet/src/screens/settings/widgets/settings_picker_cell.dart';
|
||||
import 'package:cake_wallet/src/screens/settings/widgets/settings_switcher_cell.dart';
|
||||
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
|
||||
import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
|
||||
import 'package:cake_wallet/utils/device_info.dart';
|
||||
import 'package:cake_wallet/store/settings_store.dart';
|
||||
import 'package:cake_wallet/utils/feature_flag.dart';
|
||||
import 'package:cake_wallet/utils/show_pop_up.dart';
|
||||
import 'package:cake_wallet/view_model/settings/security_settings_view_model.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_mobx/flutter_mobx.dart';
|
||||
@@ -64,6 +68,41 @@ class SecurityBackupPage extends BasePage {
|
||||
}
|
||||
});
|
||||
}),
|
||||
if (FeatureFlag.duressPinEnabled)
|
||||
Observer(builder: (_) {
|
||||
return SettingsSwitcherCell(
|
||||
key: ValueKey('security_backup_page_duress_pin_button_key'),
|
||||
title: 'Duress PIN',
|
||||
value: _securitySettingsViewModel.enableDuressPin,
|
||||
onValueChange: (BuildContext context, bool value) {
|
||||
_authService.authenticateAction(context, route: Routes.securityBackupDuressPin,
|
||||
onAuthSuccess: (isAuthenticatedSuccessfully) async {
|
||||
if (isAuthenticatedSuccessfully) {
|
||||
if (!value) {
|
||||
_securitySettingsViewModel.setEnableDuressPin(value);
|
||||
_securitySettingsViewModel.clearDuressPin();
|
||||
return;
|
||||
}
|
||||
final res = await _showDuressPinDescription(context);
|
||||
if (res) {
|
||||
final confirmation = await _showDuressPinConfirmation(context);
|
||||
|
||||
if (confirmation) {
|
||||
Navigator.of(context).pushNamed(
|
||||
Routes.setupDuressPin,
|
||||
arguments: (PinCodeState<PinCodeWidget> pinCtx, String _) async {
|
||||
pinCtx.close();
|
||||
_securitySettingsViewModel.setEnableDuressPin(true);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
conditionToDetermineIfToUse2FA: _securitySettingsViewModel
|
||||
.shouldRequireTOTP2FAForAllSecurityAndBackupSettings);
|
||||
});
|
||||
}),
|
||||
Observer(builder: (_) {
|
||||
return SettingsPickerCell<PinCodeRequiredDuration>(
|
||||
key: ValueKey('security_backup_page_require_pin_after_button_key'),
|
||||
@@ -139,3 +178,27 @@ class SecurityBackupPage extends BasePage {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> _showDuressPinDescription(BuildContext context) async {
|
||||
final ok = await showPopUp<bool>(
|
||||
context: context,
|
||||
builder: (BuildContext context) => AlertWithOneAction(
|
||||
alertTitle: S.of(context).alert_notice,
|
||||
alertContent: S.current.duress_pin_description,
|
||||
buttonText: S.of(context).ok,
|
||||
buttonAction: () => Navigator.of(context).pop(true)));
|
||||
return ok ?? false;
|
||||
}
|
||||
|
||||
Future<bool> _showDuressPinConfirmation(BuildContext context) async {
|
||||
final ok = await showPopUp<bool>(
|
||||
context: context,
|
||||
builder: (BuildContext context) => AlertWithTwoActions(
|
||||
alertTitle: S.of(context).confirm,
|
||||
alertContent: S.current.did_you_back_up_seeds,
|
||||
leftButtonText: S.current.no,
|
||||
rightButtonText: S.current.yes,
|
||||
actionLeftButton: () => Navigator.of(context).pop(false),
|
||||
actionRightButton: () => Navigator.of(context).pop(true)));
|
||||
return ok ?? false;
|
||||
}
|
||||
|
||||
@@ -8,15 +8,16 @@ import 'package:cake_wallet/view_model/setup_pin_code_view_model.dart';
|
||||
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
|
||||
|
||||
class SetupPinCodePage extends BasePage {
|
||||
SetupPinCodePage(this.pinCodeViewModel, {this.onSuccessfulPinSetup})
|
||||
SetupPinCodePage(this.pinCodeViewModel,{this.onSuccessfulPinSetup, this.isDuressPin = false})
|
||||
: pinCodeStateKey = GlobalKey<PinCodeState>();
|
||||
|
||||
final SetupPinCodeViewModel pinCodeViewModel;
|
||||
final void Function(PinCodeState<PinCodeWidget>, String)? onSuccessfulPinSetup;
|
||||
final bool isDuressPin;
|
||||
final GlobalKey<PinCodeState> pinCodeStateKey;
|
||||
|
||||
@override
|
||||
String get title => S.current.setup_pin;
|
||||
String get title => isDuressPin ? S.current.durres_PIN : S.current.setup_pin;
|
||||
|
||||
@override
|
||||
Widget body(BuildContext context) => PinCodeWidget(
|
||||
@@ -53,8 +54,10 @@ class SetupPinCodePage extends BasePage {
|
||||
builder: (BuildContext context) {
|
||||
return AlertWithOneAction(
|
||||
buttonKey: ValueKey('setup_pin_code_success_button_key'),
|
||||
alertTitle: S.current.setup_pin,
|
||||
alertContent: S.of(context).setup_successful,
|
||||
alertTitle: isDuressPin ? S.current.durres_PIN : S.current.setup_pin,
|
||||
alertContent: isDuressPin
|
||||
? S.current.durres_PIN_set_up_successfully
|
||||
: S.current.setup_successful,
|
||||
buttonText: S.of(context).ok,
|
||||
buttonAction: () {
|
||||
Navigator.of(context).pop();
|
||||
@@ -68,14 +71,13 @@ class SetupPinCodePage extends BasePage {
|
||||
);
|
||||
});
|
||||
} catch (e) {
|
||||
// FIXME: Add translation for alert content text.
|
||||
await showPopUp<void>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertWithOneAction(
|
||||
alertTitle: S.current.setup_pin,
|
||||
alertTitle: isDuressPin ? S.current.durres_PIN : S.current.setup_pin,
|
||||
alertContent:
|
||||
'Setup pin is failed with error: ${e.toString()}',
|
||||
'${S.current.setup_pin_is_failed} ${e.toString()}',
|
||||
buttonText: S.of(context).ok,
|
||||
buttonAction: () => Navigator.of(context).pop(),
|
||||
alertBarrierDismissible: false,
|
||||
@@ -83,7 +85,29 @@ class SetupPinCodePage extends BasePage {
|
||||
});
|
||||
}
|
||||
},
|
||||
onChangedPin: (String pin) => pinCodeViewModel.pinCode = pin,
|
||||
onChangedPin: (String pin) async {
|
||||
try {
|
||||
await pinCodeViewModel.setPinCode(pin);
|
||||
} catch (e) {
|
||||
await showPopUp<void>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertWithOneAction(
|
||||
alertTitle: S.current.durres_PIN,
|
||||
alertContent: e.toString(),
|
||||
buttonText: S.of(context).ok,
|
||||
buttonAction: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
alertBarrierDismissible: false,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
pinCodeStateKey.currentState?.reset();
|
||||
pinCodeViewModel.reset();
|
||||
}
|
||||
},
|
||||
onChangedPinLength: (int length) =>
|
||||
pinCodeViewModel.pinCodeLength = length,
|
||||
initialPinLength: pinCodeViewModel.pinCodeLength);
|
||||
|
||||
Reference in New Issue
Block a user