[CW-225] Add pin timeout setting

This commit is contained in:
Godwin Asuquo
2022-11-22 22:52:28 +02:00
parent c67e8c5037
commit 818a8afe20
25 changed files with 250 additions and 66 deletions
@@ -1,9 +1,11 @@
import 'package:cake_wallet/entities/pin_code_required_duration.dart';
import 'package:cake_wallet/routes.dart';
import 'package:cake_wallet/src/screens/auth/auth_page.dart';
import 'package:cake_wallet/src/screens/base_page.dart';
import 'package:cake_wallet/generated/i18n.dart';
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/standard_list.dart';
import 'package:cake_wallet/view_model/settings/settings_view_model.dart';
@@ -20,27 +22,28 @@ class SecurityBackupPage extends BasePage {
@override
Widget body(BuildContext context) {
return Container(
padding: EdgeInsets.only(top: 10),
child: Column(mainAxisSize: MainAxisSize.min, children: [
SettingsCellWithArrow(
title: S.current.show_keys,
handler: (_) => Navigator.of(context).pushNamed(Routes.auth,
handler: (_) => settingsViewModel.checkPinCodeRiquired() ? Navigator.of(context).pushNamed(Routes.auth,
arguments: (bool isAuthenticatedSuccessfully, AuthPageState auth) {
if (isAuthenticatedSuccessfully) {
auth.close(route: Routes.showKeys);
}
}),
}) : Navigator.of(context).pushNamed(Routes.showKeys),
),
StandardListSeparator(padding: EdgeInsets.symmetric(horizontal: 24)),
SettingsCellWithArrow(
title: S.current.create_backup,
handler: (_) => Navigator.of(context).pushNamed(Routes.auth,
handler: (_) => settingsViewModel.checkPinCodeRiquired() ? Navigator.of(context).pushNamed(Routes.auth,
arguments: (bool isAuthenticatedSuccessfully, AuthPageState auth) {
if (isAuthenticatedSuccessfully) {
auth.close(route: Routes.backup);
}
}),
}) : Navigator.of(context).pushNamed(Routes.backup),
),
StandardListSeparator(padding: EdgeInsets.symmetric(horizontal: 24)),
SettingsCellWithArrow(
@@ -56,28 +59,41 @@ class SecurityBackupPage extends BasePage {
})),
StandardListSeparator(padding: EdgeInsets.symmetric(horizontal: 24)),
Observer(builder: (_) {
return SettingsSwitcherCell(
title: S.current.settings_allow_biometrical_authentication,
value: settingsViewModel.allowBiometricalAuthentication,
onValueChange: (BuildContext context, bool value) {
if (value) {
Navigator.of(context).pushNamed(Routes.auth,
arguments: (bool isAuthenticatedSuccessfully, AuthPageState auth) async {
if (isAuthenticatedSuccessfully) {
if (await settingsViewModel.biometricAuthenticated()) {
settingsViewModel.setAllowBiometricalAuthentication(isAuthenticatedSuccessfully);
}
} else {
settingsViewModel.setAllowBiometricalAuthentication(isAuthenticatedSuccessfully);
}
return Column(
children: [
SettingsSwitcherCell(
title: S.current.settings_allow_biometrical_authentication,
value: settingsViewModel.allowBiometricalAuthentication,
onValueChange: (BuildContext context, bool value) {
if (value) {
Navigator.of(context).pushNamed(Routes.auth,
arguments: (bool isAuthenticatedSuccessfully, AuthPageState auth) async {
if (isAuthenticatedSuccessfully) {
if (await settingsViewModel.biometricAuthenticated()) {
settingsViewModel.setAllowBiometricalAuthentication(isAuthenticatedSuccessfully);
}
} else {
settingsViewModel.setAllowBiometricalAuthentication(isAuthenticatedSuccessfully);
}
auth.close();
});
} else {
settingsViewModel.setAllowBiometricalAuthentication(value);
}
});
auth.close();
});
} else {
settingsViewModel.setAllowBiometricalAuthentication(value);
}
}),
SettingsPickerCell<PinCodeRequiredDuration>(
title: S.current.require_pin_after,
items: PinCodeRequiredDuration.values,
selectedItem: settingsViewModel.pinCodeRequiredDuration,
onItemSelected: (PinCodeRequiredDuration code) {
settingsViewModel.setPinCodeRequiredDuration(code);
},
),
],
);
}),
]),
);
}
@@ -220,7 +220,8 @@ class WalletListBodyState extends State<WalletListBody> {
}
Future<void> _loadWallet(WalletListItem wallet) async {
await Navigator.of(context).pushNamed(Routes.auth, arguments:
if(await widget.walletListViewModel.checkIfAuthRequired()){
await Navigator.of(context).pushNamed(Routes.auth, arguments:
(bool isAuthenticatedSuccessfully, AuthPageState auth) async {
if (!isAuthenticatedSuccessfully) {
return;
@@ -241,17 +242,36 @@ class WalletListBodyState extends State<WalletListBody> {
.wallet_list_failed_to_load(wallet.name, e.toString()));
}
});
}else{
try {
changeProcessText(S.of(context).wallet_list_loading_wallet(wallet.name));
await widget.walletListViewModel.loadWallet(wallet);
hideProgressText();
Navigator.of(context).pop();
} catch (e) {
changeProcessText(S
.of(context)
.wallet_list_failed_to_load(wallet.name, e.toString()));
}
}
}
Future<void> _removeWallet(WalletListItem wallet) async {
await Navigator.of(context).pushNamed(Routes.auth, arguments:
if(widget.walletListViewModel.checkIfAuthRequired()){
await Navigator.of(context).pushNamed(Routes.auth, arguments:
(bool isAuthenticatedSuccessfully, AuthPageState auth) async {
if (!isAuthenticatedSuccessfully) {
return;
}
_onSuccessfulAuth(wallet, auth);
});
}else{
_onSuccessfulAuth(wallet, null);
}
}
bool confirmed = false;
_onSuccessfulAuth(WalletListItem wallet, AuthPageState? auth)async{
bool confirmed = false;
await showPopUp<void>(
context: context,
builder: (BuildContext context) {
@@ -270,18 +290,23 @@ class WalletListBodyState extends State<WalletListBody> {
if (confirmed) {
try {
auth.changeProcessText(
S.of(context).wallet_list_removing_wallet(wallet.name));
auth != null ?
auth.changeProcessText(
S.of(context).wallet_list_removing_wallet(wallet.name))
: changeProcessText( S.of(context).wallet_list_removing_wallet(wallet.name));
await widget.walletListViewModel.remove(wallet);
} catch (e) {
auth.changeProcessText(S
.of(context)
.wallet_list_failed_to_remove(wallet.name, e.toString()));
auth != null ?
auth.changeProcessText(
S.of(context).wallet_list_failed_to_remove(wallet.name, e.toString()),
)
: changeProcessText(
S.of(context).wallet_list_failed_to_remove(wallet.name, e.toString()),
);
}
}
auth.close();
});
auth?.close();
}
void changeProcessText(String text) {