[skip ci] fix issues from code review
Godwin Asuquo committed
Dec 13, 2022 at 16:19 UTC
f15bc2821960d6d780d11dec793aa115abda90ed
6 files changed
+73
-52
lib/core/auth_service.dart
+7
-2
@@ -8,10 +8,15 @@ import 'package:cake_wallet/di.dart';
8
import 'package:cake_wallet/store/settings_store.dart';
9
10
class AuthService with Store {
11
- AuthService({required this.secureStorage, required this.sharedPreferences});
11
+ AuthService({
12
+ required this.secureStorage,
13
+ required this.sharedPreferences,
14
+ required this.settingsStore,
15
+ });
16
17
final FlutterSecureStorage secureStorage;
18
final SharedPreferences sharedPreferences;
19
+ final SettingsStore settingsStore;
20
21
Future<void> setPassword(String password) async {
22
final key = generateStoreKeyFor(key: SecretStoreKey.pinCodePassword);
@@ -49,7 +54,7 @@ class AuthService with Store {
54
bool requireAuth() {
55
final timestamp = sharedPreferences.getInt(PreferencesKey.lastAuthTimeMilliseconds);
56
final duration = _durationToRequireAuth(timestamp ?? 0);
52
- final requiredPinInterval = getIt.get<SettingsStore>().pinTimeOutDuration;
57
+ final requiredPinInterval = settingsStore.pinTimeOutDuration;
58
59
return duration >= requiredPinInterval.value;
60
}
lib/di.dart
+8
-2
@@ -308,7 +308,10 @@ Future setup(
308
309
getIt.registerFactory<AuthService>(() => AuthService(
310
secureStorage: getIt.get<FlutterSecureStorage>(),
311
- sharedPreferences: getIt.get<SharedPreferences>()));
311
+ sharedPreferences: getIt.get<SharedPreferences>(),
312
+ settingsStore: getIt.get<SettingsStore>(),
313
+ ),
314
+ );
315
316
getIt.registerFactory<AuthViewModel>(() => AuthViewModel(
317
getIt.get<AuthService>(),
@@ -393,7 +396,10 @@ Future setup(
396
getIt.registerFactory(() => WalletListViewModel(
397
_walletInfoSource,
398
getIt.get<AppStore>(),
396
- getIt.get<WalletLoadingService>()));
399
+ getIt.get<WalletLoadingService>(),
400
+ getIt.get<AuthService>(),
401
+ ),
402
+ );
403
404
getIt.registerFactory(() =>
405
WalletListPage(walletListViewModel: getIt.get<WalletListViewModel>()));
lib/main.dart
+3
@@ -1,5 +1,6 @@
1
import 'dart:async';
2
import 'package:cake_wallet/bitcoin/bitcoin.dart';
3
+import 'package:cake_wallet/core/auth_service.dart';
4
import 'package:cake_wallet/entities/language_service.dart';
5
import 'package:cake_wallet/buy/order.dart';
6
import 'package:cake_wallet/ionia/ionia_category.dart';
@@ -257,6 +258,7 @@ class AppState extends State<App> with SingleTickerProviderStateMixin {
258
Widget build(BuildContext context) {
259
return Observer(builder: (BuildContext context) {
260
final appStore = getIt.get<AppStore>();
261
+ final authService = getIt.get<AuthService>();
262
final settingsStore = appStore.settingsStore;
263
final statusBarColor = Colors.transparent;
264
final authenticationStore = getIt.get<AuthenticationStore>();
@@ -281,6 +283,7 @@ class AppState extends State<App> with SingleTickerProviderStateMixin {
283
appStore: appStore,
284
authenticationStore: authenticationStore,
285
navigatorKey: navigatorKey,
286
+ authService: authService,
287
child: MaterialApp(
288
navigatorKey: navigatorKey,
289
debugShowCheckedModeBanner: false,
lib/src/screens/settings/security_backup_page.dart
+30
-32
@@ -62,40 +62,38 @@ class SecurityBackupPage extends BasePage {
62
})),
63
StandardListSeparator(padding: EdgeInsets.symmetric(horizontal: 24)),
64
Observer(builder: (_) {
65
- return Column(
66
- children: [
67
- SettingsSwitcherCell(
68
- title: S.current.settings_allow_biometrical_authentication,
69
- value: _securitySettingsViewModel.allowBiometricalAuthentication,
70
- onValueChange: (BuildContext context, bool value) {
71
- if (value) {
72
- Navigator.of(context).pushNamed(Routes.auth,
73
- arguments: (bool isAuthenticatedSuccessfully, AuthPageState auth) async {
74
- if (isAuthenticatedSuccessfully) {
75
- if (await _securitySettingsViewModel.biometricAuthenticated()) {
76
- _securitySettingsViewModel
77
- .setAllowBiometricalAuthentication(isAuthenticatedSuccessfully);
78
- }
79
- } else {
80
- _securitySettingsViewModel
81
- .setAllowBiometricalAuthentication(isAuthenticatedSuccessfully);
82
- }
83
-
84
- auth.close();
85
- });
65
+ return SettingsSwitcherCell(
66
+ title: S.current.settings_allow_biometrical_authentication,
67
+ value: _securitySettingsViewModel.allowBiometricalAuthentication,
68
+ onValueChange: (BuildContext context, bool value) {
69
+ if (value) {
70
+ Navigator.of(context).pushNamed(Routes.auth,
71
+ arguments: (bool isAuthenticatedSuccessfully, AuthPageState auth) async {
72
+ if (isAuthenticatedSuccessfully) {
73
+ if (await _securitySettingsViewModel.biometricAuthenticated()) {
74
+ _securitySettingsViewModel
75
+ .setAllowBiometricalAuthentication(isAuthenticatedSuccessfully);
76
+ }
77
} else {
87
- _securitySettingsViewModel.setAllowBiometricalAuthentication(value);
78
+ _securitySettingsViewModel
79
+ .setAllowBiometricalAuthentication(isAuthenticatedSuccessfully);
80
}
89
- }),
90
- SettingsPickerCell<PinCodeRequiredDuration>(
91
- title: S.current.require_pin_after,
92
- items: PinCodeRequiredDuration.values,
93
- selectedItem: _securitySettingsViewModel.pinCodeRequiredDuration,
94
- onItemSelected: (PinCodeRequiredDuration code) {
95
- _securitySettingsViewModel.setPinCodeRequiredDuration(code);
96
- },
97
- ),
98
- ],
81
+
82
+ auth.close();
83
+ });
84
+ } else {
85
+ _securitySettingsViewModel.setAllowBiometricalAuthentication(value);
86
+ }
87
+ });
88
+ }),
89
+ Observer(builder: (_) {
90
+ return SettingsPickerCell<PinCodeRequiredDuration>(
91
+ title: S.current.require_pin_after,
92
+ items: PinCodeRequiredDuration.values,
93
+ selectedItem: _securitySettingsViewModel.pinCodeRequiredDuration,
94
+ onItemSelected: (PinCodeRequiredDuration code) {
95
+ _securitySettingsViewModel.setPinCodeRequiredDuration(code);
96
+ },
97
);
98
}),
99
]),
lib/store/settings_store.dart
+5
-4
@@ -18,7 +18,6 @@ import 'package:cw_core/node.dart';
18
import 'package:cake_wallet/monero/monero.dart';
19
import 'package:cake_wallet/entities/action_list_display_mode.dart';
20
import 'package:cake_wallet/entities/fiat_api_mode.dart';
21
-import 'package:cake_wallet/.secrets.g.dart' as secrets;
21
22
part 'settings_store.g.dart';
23
@@ -169,7 +168,7 @@ abstract class SettingsStoreBase with Store {
168
169
static const defaultPinLength = 4;
170
static const defaultActionsMode = 11;
172
- static const defaultPinCodeTimeOutDuration = 10;
171
+ static const defaultPinCodeTimeOutDuration = PinCodeRequiredDuration.tenminutes;
172
173
@observable
174
FiatCurrency fiatCurrency;
@@ -299,8 +298,10 @@ abstract class SettingsStoreBase with Store {
298
sharedPreferences.getInt(PreferencesKey.displayActionListModeKey) ??
299
defaultActionsMode));
300
var pinLength = sharedPreferences.getInt(PreferencesKey.currentPinLength);
302
- final pinCodeTimeOutDuration = PinCodeRequiredDuration.deserialize(raw: sharedPreferences.getInt(PreferencesKey.pinTimeOutDuration)
303
- ?? defaultPinCodeTimeOutDuration);
301
+ final timeOutDuration = sharedPreferences.getInt(PreferencesKey.pinTimeOutDuration);
302
+ final pinCodeTimeOutDuration = timeOutDuration != null
303
+ ? PinCodeRequiredDuration.deserialize(raw: timeOutDuration)
304
+ : defaultPinCodeTimeOutDuration;
305
306
// If no value
307
if (pinLength == null || pinLength == 0) {
lib/view_model/wallet_list/wallet_list_view_model.dart
+20
-12
@@ -15,9 +15,12 @@ part 'wallet_list_view_model.g.dart';
15
class WalletListViewModel = WalletListViewModelBase with _$WalletListViewModel;
16
17
abstract class WalletListViewModelBase with Store {
18
- WalletListViewModelBase(this._walletInfoSource, this._appStore,
19
- this._walletLoadingService)
20
- : wallets = ObservableList<WalletListItem>() {
18
+ WalletListViewModelBase(
19
+ this._walletInfoSource,
20
+ this._appStore,
21
+ this._walletLoadingService,
22
+ this._authService,
23
+ ) : wallets = ObservableList<WalletListItem>() {
24
_updateList();
25
}
26
@@ -27,6 +30,7 @@ abstract class WalletListViewModelBase with Store {
30
final AppStore _appStore;
31
final Box<WalletInfo> _walletInfoSource;
32
final WalletLoadingService _walletLoadingService;
33
+ final AuthService _authService;
34
35
WalletType get currentWalletType => _appStore.wallet!.type;
36
@@ -47,16 +51,20 @@ abstract class WalletListViewModelBase with Store {
51
52
void _updateList() {
53
wallets.clear();
50
- wallets.addAll(_walletInfoSource.values.map((info) => WalletListItem(
51
- name: info.name,
52
- type: info.type,
53
- key: info.key,
54
- isCurrent: info.name == _appStore.wallet!.name &&
55
- info.type == _appStore.wallet!.type,
56
- isEnabled: availableWalletTypes.contains(info.type))));
54
+ wallets.addAll(
55
+ _walletInfoSource.values.map(
56
+ (info) => WalletListItem(
57
+ name: info.name,
58
+ type: info.type,
59
+ key: info.key,
60
+ isCurrent: info.name == _appStore.wallet!.name && info.type == _appStore.wallet!.type,
61
+ isEnabled: availableWalletTypes.contains(info.type),
62
+ ),
63
+ ),
64
+ );
65
}
66
59
- bool checkIfAuthRequired(){
60
- return getIt.get<AuthService>().requireAuth();
67
+ bool checkIfAuthRequired() {
68
+ return _authService.requireAuth();
69
}
70
}