Skip to content

Commit

Permalink
Lock wallet manually
Browse files Browse the repository at this point in the history
Fixes #952
  • Loading branch information
Chralu committed Jun 4, 2024
1 parent 661a95f commit 6d38b50
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 10 deletions.
1 change: 1 addition & 0 deletions lib/application/authentication/authentication.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:aewallet/application/utils.dart';
import 'package:aewallet/domain/models/authentication.dart';
import 'package:aewallet/domain/repositories/authentication.dart';
import 'package:aewallet/domain/usecases/authentication/authentication.dart';
import 'package:aewallet/infrastructure/datasources/vault/vault.dart';
import 'package:aewallet/infrastructure/repositories/authentication.nonweb.dart';
import 'package:aewallet/infrastructure/repositories/authentication.web.dart';
import 'package:aewallet/model/authentication_method.dart';
Expand Down
6 changes: 6 additions & 0 deletions lib/application/authentication/startup_authent.dart
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ class AuthenticationGuardNotifier
return null;
}

Future<void> lock() async {
final vault = Vault.instance();
await vault.lock();
await vault.ensureVaultIsUnlocked();
}

Future<void> scheduleNextStartupAutolock() async {
log(
'Schedule next startup Autolock',
Expand Down
1 change: 1 addition & 0 deletions lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"manage": "Manage",
"invalidSeedPaste": "Pasted seed is not valid.",
"unlockBiometrics": "Authenticate to Unlock",
"manualLockAction": "Lock Application",
"lockAppSetting": "Activate auto lock",
"locked": "Locked",
"unlock": "Unlock",
Expand Down
1 change: 1 addition & 0 deletions lib/l10n/intl_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"manage": "Gérer",
"invalidSeedPaste": "La phrase secrète que vous souhaitez coller n'est pas valide.",
"unlockBiometrics": "Authentifier pour déverrouiller",
"manualLockAction": "Verouiller l'application",
"lockAppSetting": "Activation du verouillage auto",
"locked": "Bloqué",
"unlock": "Ouvrir",
Expand Down
1 change: 1 addition & 0 deletions lib/ui/menu/settings/components/settings_list_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ abstract class _SettingsListItem extends ConsumerWidget {
required String heading,
required TextStyle headingStyle,
required IconData icon,
bool? displayChevron,
VoidCallback? onPressed,
}) = _SettingsListItemSingleLine;

Expand Down
17 changes: 10 additions & 7 deletions lib/ui/menu/settings/components/settings_list_item_singleline.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,15 @@ class _SettingsListItemSingleLine extends _SettingsListItem {
required this.heading,
required this.headingStyle,
required this.icon,
this.displayChevron = true,
this.onPressed,
});

final String heading;
final TextStyle headingStyle;
final IconData icon;
final VoidCallback? onPressed;
final bool? displayChevron;

@override
Widget build(BuildContext context, WidgetRef ref) {
Expand Down Expand Up @@ -166,13 +168,14 @@ class _SettingsListItemSingleLine extends _SettingsListItem {
),
),
const Spacer(),
Icon(
Symbols.chevron_right,
color: ArchethicTheme.iconDrawer,
weight: IconSize.weightM,
opticalSize: IconSize.opticalSizeM,
grade: IconSize.gradeM,
),
if (displayChevron != null && displayChevron == true)
Icon(
Symbols.chevron_right,
color: ArchethicTheme.iconDrawer,
weight: IconSize.weightM,
opticalSize: IconSize.opticalSizeM,
grade: IconSize.gradeM,
),
],
),
),
Expand Down
16 changes: 16 additions & 0 deletions lib/ui/menu/settings/main_settings_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,22 @@ class MainMenuView extends ConsumerWidget {
],
),
const _SettingsListItem.spacer(),
_SettingsListItem.singleLine(
heading: localizations.manualLockAction,
headingStyle:
ArchethicThemeStyles.textStyleSize16W600Primary,
icon: Symbols.lock,
displayChevron: false,
onPressed: () {
ref
.read(
AuthenticationProviders
.authenticationGuard.notifier,
)
.lock();
},
),
const _SettingsListItem.spacer(),
_SettingsListItem.title(text: localizations.information),
const _SettingsListItem.spacer(),
if (connectivityStatusProvider ==
Expand Down
6 changes: 3 additions & 3 deletions lib/ui/views/authenticate/auto_lock_guard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ class _AutoLockGuardState extends ConsumerState<AutoLockGuard>
timer = RestartableTimer(
durationBeforeLock,
() async {
final vault = Vault.instance();
await vault.lock();
await vault.ensureVaultIsUnlocked();
await ref
.read(AuthenticationProviders.authenticationGuard.notifier)
.lock();
},
);
}
Expand Down

0 comments on commit 6d38b50

Please sign in to comment.