Fix issues from code review

This commit is contained in:
Godwin Asuquo 2022-12-09 17:08:52 +01:00
parent 75463912d0
commit 9ef1186c45
4 changed files with 99 additions and 100 deletions

View file

@ -43,11 +43,13 @@ class AuthService with Store {
}
void saveLastAuthTime() {
int timestamp = DateTime.now().millisecondsSinceEpoch;
sharedPreferences.setInt(PreferencesKey.lastAuthTimeMilliseconds, timestamp);
}
bool requireAuth() {
final timestamp = sharedPreferences.getInt(PreferencesKey.lastAuthTimeMilliseconds);
final duration = _durationToRequireAuth(timestamp ?? 0);
final requiredPinInterval = getIt.get<SettingsStore>().pinTimeOutDuration;

View file

@ -1,6 +1,5 @@
import 'dart:async';
import 'package:cake_wallet/core/auth_service.dart';
import 'package:cake_wallet/di.dart';
import 'package:flutter/material.dart';
import 'package:cake_wallet/routes.dart';
import 'package:cake_wallet/src/screens/auth/auth_page.dart';
@ -14,12 +13,15 @@ class Root extends StatefulWidget {
required this.authenticationStore,
required this.appStore,
required this.child,
required this.navigatorKey})
required this.navigatorKey,
required this.authService,
})
: super(key: key);
final AuthenticationStore authenticationStore;
final AppStore appStore;
final GlobalKey<NavigatorState> navigatorKey;
final AuthService authService;
final Widget child;
@override
@ -30,7 +32,7 @@ class RootState extends State<Root> with WidgetsBindingObserver {
RootState()
: _isInactiveController = StreamController<bool>.broadcast(),
_isInactive = false,
_requestAuth = getIt.get<AuthService>().requireAuth(),
_requestAuth = true,
_postFrameCallback = false;
Stream<bool> get isInactive => _isInactiveController.stream;
@ -41,7 +43,7 @@ class RootState extends State<Root> with WidgetsBindingObserver {
@override
void initState() {
_requestAuth = widget.authService.requireAuth();
_isInactiveController = StreamController<bool>.broadcast();
_isInactive = false;
_postFrameCallback = false;
@ -58,7 +60,7 @@ class RootState extends State<Root> with WidgetsBindingObserver {
}
setState(() {
_requestAuth = getIt.get<AuthService>().requireAuth();
_requestAuth = widget.authService.requireAuth();
});
if (!_isInactive &&

View file

@ -221,15 +221,14 @@ class WalletListBodyState extends State<WalletListBody> {
Future<void> _loadWallet(WalletListItem wallet) async {
if (await widget.walletListViewModel.checkIfAuthRequired()) {
await Navigator.of(context).pushNamed(Routes.auth, arguments:
(bool isAuthenticatedSuccessfully, AuthPageState auth) async {
await Navigator.of(context).pushNamed(Routes.auth,
arguments: (bool isAuthenticatedSuccessfully, AuthPageState auth) async {
if (!isAuthenticatedSuccessfully) {
return;
}
try {
auth.changeProcessText(
S.of(context).wallet_list_loading_wallet(wallet.name));
auth.changeProcessText(S.of(context).wallet_list_loading_wallet(wallet.name));
await widget.walletListViewModel.loadWallet(wallet);
auth.hideProgressText();
auth.close();
@ -237,9 +236,8 @@ class WalletListBodyState extends State<WalletListBody> {
Navigator.of(context).pop();
});
} catch (e) {
auth.changeProcessText(S
.of(context)
.wallet_list_failed_to_load(wallet.name, e.toString()));
auth.changeProcessText(
S.of(context).wallet_list_failed_to_load(wallet.name, e.toString()));
}
});
} else {
@ -249,17 +247,15 @@ class WalletListBodyState extends State<WalletListBody> {
hideProgressText();
Navigator.of(context).pop();
} catch (e) {
changeProcessText(S
.of(context)
.wallet_list_failed_to_load(wallet.name, e.toString()));
changeProcessText(S.of(context).wallet_list_failed_to_load(wallet.name, e.toString()));
}
}
}
Future<void> _removeWallet(WalletListItem wallet) async {
if (widget.walletListViewModel.checkIfAuthRequired()) {
await Navigator.of(context).pushNamed(Routes.auth, arguments:
(bool isAuthenticatedSuccessfully, AuthPageState auth) async {
await Navigator.of(context).pushNamed(Routes.auth,
arguments: (bool isAuthenticatedSuccessfully, AuthPageState auth) async {
if (!isAuthenticatedSuccessfully) {
return;
}
@ -270,7 +266,7 @@ class WalletListBodyState extends State<WalletListBody> {
}
}
_onSuccessfulAuth(WalletListItem wallet, AuthPageState? auth)async{
void _onSuccessfulAuth(WalletListItem wallet, AuthPageState? auth) async {
bool confirmed = false;
await showPopUp<void>(
context: context,
@ -290,14 +286,13 @@ class WalletListBodyState extends State<WalletListBody> {
if (confirmed) {
try {
auth != null ?
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 != null ?
auth.changeProcessText(
auth != null
? auth.changeProcessText(
S.of(context).wallet_list_failed_to_remove(wallet.name, e.toString()),
)
: changeProcessText(