mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-08 20:09:24 +00:00
[skip ci] fix issues from code review
This commit is contained in:
parent
59484e5b91
commit
f15bc28219
6 changed files with 73 additions and 52 deletions
|
@ -8,10 +8,15 @@ import 'package:cake_wallet/di.dart';
|
|||
import 'package:cake_wallet/store/settings_store.dart';
|
||||
|
||||
class AuthService with Store {
|
||||
AuthService({required this.secureStorage, required this.sharedPreferences});
|
||||
AuthService({
|
||||
required this.secureStorage,
|
||||
required this.sharedPreferences,
|
||||
required this.settingsStore,
|
||||
});
|
||||
|
||||
final FlutterSecureStorage secureStorage;
|
||||
final SharedPreferences sharedPreferences;
|
||||
final SettingsStore settingsStore;
|
||||
|
||||
Future<void> setPassword(String password) async {
|
||||
final key = generateStoreKeyFor(key: SecretStoreKey.pinCodePassword);
|
||||
|
@ -49,7 +54,7 @@ class AuthService with Store {
|
|||
bool requireAuth() {
|
||||
final timestamp = sharedPreferences.getInt(PreferencesKey.lastAuthTimeMilliseconds);
|
||||
final duration = _durationToRequireAuth(timestamp ?? 0);
|
||||
final requiredPinInterval = getIt.get<SettingsStore>().pinTimeOutDuration;
|
||||
final requiredPinInterval = settingsStore.pinTimeOutDuration;
|
||||
|
||||
return duration >= requiredPinInterval.value;
|
||||
}
|
||||
|
|
10
lib/di.dart
10
lib/di.dart
|
@ -308,7 +308,10 @@ Future setup(
|
|||
|
||||
getIt.registerFactory<AuthService>(() => AuthService(
|
||||
secureStorage: getIt.get<FlutterSecureStorage>(),
|
||||
sharedPreferences: getIt.get<SharedPreferences>()));
|
||||
sharedPreferences: getIt.get<SharedPreferences>(),
|
||||
settingsStore: getIt.get<SettingsStore>(),
|
||||
),
|
||||
);
|
||||
|
||||
getIt.registerFactory<AuthViewModel>(() => AuthViewModel(
|
||||
getIt.get<AuthService>(),
|
||||
|
@ -393,7 +396,10 @@ Future setup(
|
|||
getIt.registerFactory(() => WalletListViewModel(
|
||||
_walletInfoSource,
|
||||
getIt.get<AppStore>(),
|
||||
getIt.get<WalletLoadingService>()));
|
||||
getIt.get<WalletLoadingService>(),
|
||||
getIt.get<AuthService>(),
|
||||
),
|
||||
);
|
||||
|
||||
getIt.registerFactory(() =>
|
||||
WalletListPage(walletListViewModel: getIt.get<WalletListViewModel>()));
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import 'dart:async';
|
||||
import 'package:cake_wallet/bitcoin/bitcoin.dart';
|
||||
import 'package:cake_wallet/core/auth_service.dart';
|
||||
import 'package:cake_wallet/entities/language_service.dart';
|
||||
import 'package:cake_wallet/buy/order.dart';
|
||||
import 'package:cake_wallet/ionia/ionia_category.dart';
|
||||
|
@ -257,6 +258,7 @@ class AppState extends State<App> with SingleTickerProviderStateMixin {
|
|||
Widget build(BuildContext context) {
|
||||
return Observer(builder: (BuildContext context) {
|
||||
final appStore = getIt.get<AppStore>();
|
||||
final authService = getIt.get<AuthService>();
|
||||
final settingsStore = appStore.settingsStore;
|
||||
final statusBarColor = Colors.transparent;
|
||||
final authenticationStore = getIt.get<AuthenticationStore>();
|
||||
|
@ -281,6 +283,7 @@ class AppState extends State<App> with SingleTickerProviderStateMixin {
|
|||
appStore: appStore,
|
||||
authenticationStore: authenticationStore,
|
||||
navigatorKey: navigatorKey,
|
||||
authService: authService,
|
||||
child: MaterialApp(
|
||||
navigatorKey: navigatorKey,
|
||||
debugShowCheckedModeBanner: false,
|
||||
|
|
|
@ -62,40 +62,38 @@ class SecurityBackupPage extends BasePage {
|
|||
})),
|
||||
StandardListSeparator(padding: EdgeInsets.symmetric(horizontal: 24)),
|
||||
Observer(builder: (_) {
|
||||
return Column(
|
||||
children: [
|
||||
SettingsSwitcherCell(
|
||||
title: S.current.settings_allow_biometrical_authentication,
|
||||
value: _securitySettingsViewModel.allowBiometricalAuthentication,
|
||||
onValueChange: (BuildContext context, bool value) {
|
||||
if (value) {
|
||||
Navigator.of(context).pushNamed(Routes.auth,
|
||||
arguments: (bool isAuthenticatedSuccessfully, AuthPageState auth) async {
|
||||
if (isAuthenticatedSuccessfully) {
|
||||
if (await _securitySettingsViewModel.biometricAuthenticated()) {
|
||||
_securitySettingsViewModel
|
||||
.setAllowBiometricalAuthentication(isAuthenticatedSuccessfully);
|
||||
}
|
||||
} else {
|
||||
_securitySettingsViewModel
|
||||
.setAllowBiometricalAuthentication(isAuthenticatedSuccessfully);
|
||||
}
|
||||
|
||||
auth.close();
|
||||
});
|
||||
return SettingsSwitcherCell(
|
||||
title: S.current.settings_allow_biometrical_authentication,
|
||||
value: _securitySettingsViewModel.allowBiometricalAuthentication,
|
||||
onValueChange: (BuildContext context, bool value) {
|
||||
if (value) {
|
||||
Navigator.of(context).pushNamed(Routes.auth,
|
||||
arguments: (bool isAuthenticatedSuccessfully, AuthPageState auth) async {
|
||||
if (isAuthenticatedSuccessfully) {
|
||||
if (await _securitySettingsViewModel.biometricAuthenticated()) {
|
||||
_securitySettingsViewModel
|
||||
.setAllowBiometricalAuthentication(isAuthenticatedSuccessfully);
|
||||
}
|
||||
} else {
|
||||
_securitySettingsViewModel.setAllowBiometricalAuthentication(value);
|
||||
_securitySettingsViewModel
|
||||
.setAllowBiometricalAuthentication(isAuthenticatedSuccessfully);
|
||||
}
|
||||
}),
|
||||
SettingsPickerCell<PinCodeRequiredDuration>(
|
||||
title: S.current.require_pin_after,
|
||||
items: PinCodeRequiredDuration.values,
|
||||
selectedItem: _securitySettingsViewModel.pinCodeRequiredDuration,
|
||||
onItemSelected: (PinCodeRequiredDuration code) {
|
||||
_securitySettingsViewModel.setPinCodeRequiredDuration(code);
|
||||
},
|
||||
),
|
||||
],
|
||||
|
||||
auth.close();
|
||||
});
|
||||
} else {
|
||||
_securitySettingsViewModel.setAllowBiometricalAuthentication(value);
|
||||
}
|
||||
});
|
||||
}),
|
||||
Observer(builder: (_) {
|
||||
return SettingsPickerCell<PinCodeRequiredDuration>(
|
||||
title: S.current.require_pin_after,
|
||||
items: PinCodeRequiredDuration.values,
|
||||
selectedItem: _securitySettingsViewModel.pinCodeRequiredDuration,
|
||||
onItemSelected: (PinCodeRequiredDuration code) {
|
||||
_securitySettingsViewModel.setPinCodeRequiredDuration(code);
|
||||
},
|
||||
);
|
||||
}),
|
||||
]),
|
||||
|
|
|
@ -18,7 +18,6 @@ import 'package:cw_core/node.dart';
|
|||
import 'package:cake_wallet/monero/monero.dart';
|
||||
import 'package:cake_wallet/entities/action_list_display_mode.dart';
|
||||
import 'package:cake_wallet/entities/fiat_api_mode.dart';
|
||||
import 'package:cake_wallet/.secrets.g.dart' as secrets;
|
||||
|
||||
part 'settings_store.g.dart';
|
||||
|
||||
|
@ -169,7 +168,7 @@ abstract class SettingsStoreBase with Store {
|
|||
|
||||
static const defaultPinLength = 4;
|
||||
static const defaultActionsMode = 11;
|
||||
static const defaultPinCodeTimeOutDuration = 10;
|
||||
static const defaultPinCodeTimeOutDuration = PinCodeRequiredDuration.tenminutes;
|
||||
|
||||
@observable
|
||||
FiatCurrency fiatCurrency;
|
||||
|
@ -299,8 +298,10 @@ abstract class SettingsStoreBase with Store {
|
|||
sharedPreferences.getInt(PreferencesKey.displayActionListModeKey) ??
|
||||
defaultActionsMode));
|
||||
var pinLength = sharedPreferences.getInt(PreferencesKey.currentPinLength);
|
||||
final pinCodeTimeOutDuration = PinCodeRequiredDuration.deserialize(raw: sharedPreferences.getInt(PreferencesKey.pinTimeOutDuration)
|
||||
?? defaultPinCodeTimeOutDuration);
|
||||
final timeOutDuration = sharedPreferences.getInt(PreferencesKey.pinTimeOutDuration);
|
||||
final pinCodeTimeOutDuration = timeOutDuration != null
|
||||
? PinCodeRequiredDuration.deserialize(raw: timeOutDuration)
|
||||
: defaultPinCodeTimeOutDuration;
|
||||
|
||||
// If no value
|
||||
if (pinLength == null || pinLength == 0) {
|
||||
|
|
|
@ -15,9 +15,12 @@ part 'wallet_list_view_model.g.dart';
|
|||
class WalletListViewModel = WalletListViewModelBase with _$WalletListViewModel;
|
||||
|
||||
abstract class WalletListViewModelBase with Store {
|
||||
WalletListViewModelBase(this._walletInfoSource, this._appStore,
|
||||
this._walletLoadingService)
|
||||
: wallets = ObservableList<WalletListItem>() {
|
||||
WalletListViewModelBase(
|
||||
this._walletInfoSource,
|
||||
this._appStore,
|
||||
this._walletLoadingService,
|
||||
this._authService,
|
||||
) : wallets = ObservableList<WalletListItem>() {
|
||||
_updateList();
|
||||
}
|
||||
|
||||
|
@ -27,6 +30,7 @@ abstract class WalletListViewModelBase with Store {
|
|||
final AppStore _appStore;
|
||||
final Box<WalletInfo> _walletInfoSource;
|
||||
final WalletLoadingService _walletLoadingService;
|
||||
final AuthService _authService;
|
||||
|
||||
WalletType get currentWalletType => _appStore.wallet!.type;
|
||||
|
||||
|
@ -47,16 +51,20 @@ abstract class WalletListViewModelBase with Store {
|
|||
|
||||
void _updateList() {
|
||||
wallets.clear();
|
||||
wallets.addAll(_walletInfoSource.values.map((info) => WalletListItem(
|
||||
name: info.name,
|
||||
type: info.type,
|
||||
key: info.key,
|
||||
isCurrent: info.name == _appStore.wallet!.name &&
|
||||
info.type == _appStore.wallet!.type,
|
||||
isEnabled: availableWalletTypes.contains(info.type))));
|
||||
wallets.addAll(
|
||||
_walletInfoSource.values.map(
|
||||
(info) => WalletListItem(
|
||||
name: info.name,
|
||||
type: info.type,
|
||||
key: info.key,
|
||||
isCurrent: info.name == _appStore.wallet!.name && info.type == _appStore.wallet!.type,
|
||||
isEnabled: availableWalletTypes.contains(info.type),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
bool checkIfAuthRequired(){
|
||||
return getIt.get<AuthService>().requireAuth();
|
||||
bool checkIfAuthRequired() {
|
||||
return _authService.requireAuth();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue