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