mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-16 17:27:39 +00:00
Merge pull request #905 from cypherstack/autopin
Add an optional preference to accept a correct PIN automatically
This commit is contained in:
commit
b53b1153fe
4 changed files with 116 additions and 7 deletions
|
@ -188,12 +188,14 @@ class _LockscreenViewState extends ConsumerState<LockscreenView> {
|
|||
_timeout = Duration.zero;
|
||||
|
||||
_checkUseBiometrics();
|
||||
_pinTextController.addListener(_onPinChanged);
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
dispose() {
|
||||
// _shakeController.dispose();
|
||||
_pinTextController.removeListener(_onPinChanged);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
|
@ -208,13 +210,27 @@ class _LockscreenViewState extends ConsumerState<LockscreenView> {
|
|||
);
|
||||
}
|
||||
|
||||
final _pinTextController = TextEditingController();
|
||||
final FocusNode _pinFocusNode = FocusNode();
|
||||
|
||||
late SecureStorageInterface _secureStore;
|
||||
late Biometrics biometrics;
|
||||
int pinCount = 1;
|
||||
|
||||
final _pinTextController = TextEditingController();
|
||||
|
||||
void _onPinChanged() async {
|
||||
String enteredPin = _pinTextController.text;
|
||||
final storedPin = await _secureStore.read(key: 'stack_pin');
|
||||
final autoPin = ref.read(prefsChangeNotifierProvider).autoPin;
|
||||
|
||||
if (enteredPin.length >= 4 && autoPin && enteredPin == storedPin) {
|
||||
await Future<void>.delayed(
|
||||
const Duration(milliseconds: 200),
|
||||
);
|
||||
unawaited(_onUnlock());
|
||||
}
|
||||
}
|
||||
|
||||
Widget get _body => Background(
|
||||
child: SafeArea(
|
||||
child: Scaffold(
|
||||
|
|
|
@ -61,9 +61,12 @@ class _ChangePinViewState extends ConsumerState<ChangePinView> {
|
|||
|
||||
int pinCount = 1;
|
||||
|
||||
final TextEditingController _pinTextController = TextEditingController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_secureStore = ref.read(secureStoreProvider);
|
||||
_pinTextController.addListener(_onPinChanged);
|
||||
super.initState();
|
||||
}
|
||||
|
||||
|
@ -74,9 +77,23 @@ class _ChangePinViewState extends ConsumerState<ChangePinView> {
|
|||
_pinPutController2.dispose();
|
||||
_pinPutFocusNode1.dispose();
|
||||
_pinPutFocusNode2.dispose();
|
||||
_pinTextController.removeListener(_onPinChanged);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _onPinChanged() async {
|
||||
String enteredPin = _pinTextController.text;
|
||||
final storedPin = await _secureStore.read(key: 'stack_pin');
|
||||
final autoPin = ref.read(prefsChangeNotifierProvider).autoPin;
|
||||
|
||||
if (enteredPin.length >= 4 && autoPin && enteredPin == storedPin) {
|
||||
await _pageController.nextPage(
|
||||
duration: const Duration(milliseconds: 300),
|
||||
curve: Curves.linear,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Background(
|
||||
|
|
|
@ -10,8 +10,7 @@
|
|||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../../pinpad_views/lock_screen_view.dart';
|
||||
import 'change_pin_view/change_pin_view.dart';
|
||||
|
||||
import '../../../../providers/global/prefs_provider.dart';
|
||||
import '../../../../route_generator.dart';
|
||||
import '../../../../themes/stack_colors.dart';
|
||||
|
@ -21,6 +20,8 @@ import '../../../../widgets/background.dart';
|
|||
import '../../../../widgets/custom_buttons/app_bar_icon_button.dart';
|
||||
import '../../../../widgets/custom_buttons/draggable_switch_button.dart';
|
||||
import '../../../../widgets/rounded_white_container.dart';
|
||||
import '../../../pinpad_views/lock_screen_view.dart';
|
||||
import 'change_pin_view/change_pin_view.dart';
|
||||
|
||||
class SecurityView extends StatelessWidget {
|
||||
const SecurityView({
|
||||
|
@ -203,6 +204,54 @@ class SecurityView extends StatelessWidget {
|
|||
},
|
||||
),
|
||||
),
|
||||
// The "autoPin" preference (whether to automatically accept a correct PIN).
|
||||
const SizedBox(
|
||||
height: 8,
|
||||
),
|
||||
RoundedWhiteContainer(
|
||||
child: Consumer(
|
||||
builder: (_, ref, __) {
|
||||
return RawMaterialButton(
|
||||
// splashColor: Theme.of(context).extension<StackColors>()!.highlight,
|
||||
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(
|
||||
Constants.size.circularBorderRadius,
|
||||
),
|
||||
),
|
||||
onPressed: null,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
"Auto-accept correct PIN",
|
||||
style: STextStyles.titleBold12(context),
|
||||
textAlign: TextAlign.left,
|
||||
),
|
||||
SizedBox(
|
||||
height: 20,
|
||||
width: 40,
|
||||
child: DraggableSwitchButton(
|
||||
isOn: ref.watch(
|
||||
prefsChangeNotifierProvider
|
||||
.select((value) => value.autoPin),
|
||||
),
|
||||
onValueChanged: (newValue) {
|
||||
ref
|
||||
.read(prefsChangeNotifierProvider)
|
||||
.autoPin = newValue;
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
|
|
@ -11,18 +11,19 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
import '../app_config.dart';
|
||||
import '../db/hive/db.dart';
|
||||
import '../services/event_bus/events/global/tor_status_changed_event.dart';
|
||||
import '../services/event_bus/global_event_bus.dart';
|
||||
import '../app_config.dart';
|
||||
import '../wallets/crypto_currency/crypto_currency.dart';
|
||||
import '../wallets/wallet/wallet_mixin_interfaces/cash_fusion_interface.dart';
|
||||
import 'amount/amount_unit.dart';
|
||||
import 'constants.dart';
|
||||
import 'enums/backup_frequency_type.dart';
|
||||
import 'enums/languages_enum.dart';
|
||||
import 'enums/sync_type_enum.dart';
|
||||
import '../wallets/crypto_currency/crypto_currency.dart';
|
||||
import '../wallets/wallet/wallet_mixin_interfaces/cash_fusion_interface.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
class Prefs extends ChangeNotifier {
|
||||
Prefs._();
|
||||
|
@ -1103,4 +1104,30 @@ class Prefs extends ChangeNotifier {
|
|||
|
||||
return actualMap;
|
||||
}
|
||||
|
||||
// Automatic PIN entry.
|
||||
|
||||
bool _autoPin = false;
|
||||
|
||||
bool get autoPin => _autoPin;
|
||||
|
||||
set autoPin(bool autoPin) {
|
||||
if (_autoPin != autoPin) {
|
||||
DB.instance.put<dynamic>(
|
||||
boxName: DB.boxNamePrefs,
|
||||
key: "autoPin",
|
||||
value: autoPin,
|
||||
);
|
||||
_autoPin = autoPin;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> _getAutoPin() async {
|
||||
return await DB.instance.get<dynamic>(
|
||||
boxName: DB.boxNamePrefs,
|
||||
key: "autoPin",
|
||||
) as bool? ??
|
||||
false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue