Skip to content

Commit 5c17a07

Browse files
committed
Use PIN when biometrics raises an exception
1 parent 6a32ea7 commit 5c17a07

File tree

7 files changed

+432
-432
lines changed

7 files changed

+432
-432
lines changed

lib/ui/lock_screen.dart

Lines changed: 50 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,42 @@ class _AppLockScreenState extends State<AppLockScreen> {
128128
}
129129
}
130130

131+
Future<void> authenticateWithBiometrics() async {
132+
bool authenticated = await sl.get<BiometricUtil>().authenticateWithBiometrics(context, AppLocalization.of(context).unlockBiometrics);
133+
if (authenticated) {
134+
_goHome();
135+
} else {
136+
setState(() {
137+
_showUnlockButton = true;
138+
});
139+
}
140+
}
141+
142+
Future<void> authenticateWithPin({bool transitions = false}) async {
143+
String expectedPin = await sl.get<Vault>().getPin();
144+
if (transitions) {
145+
Navigator.of(context).push(
146+
MaterialPageRoute(builder: (BuildContext context) {
147+
return _buildPinScreen(context, expectedPin);
148+
}),
149+
);
150+
} else {
151+
Navigator.of(context).push(
152+
NoPushTransitionRoute(builder: (BuildContext context) {
153+
return _buildPinScreen(context, expectedPin);
154+
}),
155+
);
156+
}
157+
Future.delayed(Duration(milliseconds: 200), () {
158+
if (mounted) {
159+
setState(() {
160+
_showUnlockButton = true;
161+
_showLock = true;
162+
});
163+
}
164+
});
165+
}
166+
131167
Future<void> _authenticate({bool transitions = false}) async {
132168
// Test if user is locked out
133169
// Get duration of lockout
@@ -145,54 +181,21 @@ class _AppLockScreenState extends State<AppLockScreen> {
145181
setState(() {
146182
_lockedOut = false;
147183
});
148-
sl.get<SharedPrefsUtil>().getAuthMethod().then((authMethod) {
149-
sl.get<BiometricUtil>().hasBiometrics().then((hasBiometrics) {
150-
if (authMethod.method == AuthMethod.BIOMETRICS && hasBiometrics) {
151-
setState(() {
152-
_showLock = true;
153-
_showUnlockButton = true;
154-
});
155-
sl
156-
.get<BiometricUtil>()
157-
.authenticateWithBiometrics(
158-
context, AppLocalization.of(context).unlockBiometrics)
159-
.then((authenticated) {
160-
if (authenticated) {
161-
_goHome();
162-
} else {
163-
setState(() {
164-
_showUnlockButton = true;
165-
});
166-
}
167-
});
168-
} else {
169-
// PIN Authentication
170-
sl.get<Vault>().getPin().then((expectedPin) {
171-
if (transitions) {
172-
Navigator.of(context).push(
173-
MaterialPageRoute(builder: (BuildContext context) {
174-
return _buildPinScreen(context, expectedPin);
175-
}),
176-
);
177-
} else {
178-
Navigator.of(context).push(
179-
NoPushTransitionRoute(builder: (BuildContext context) {
180-
return _buildPinScreen(context, expectedPin);
181-
}),
182-
);
183-
}
184-
Future.delayed(Duration(milliseconds: 200), () {
185-
if (mounted) {
186-
setState(() {
187-
_showUnlockButton = true;
188-
_showLock = true;
189-
});
190-
}
191-
});
192-
});
193-
}
184+
AuthenticationMethod authMethod = await sl.get<SharedPrefsUtil>().getAuthMethod();
185+
bool hasBiometrics = await sl.get<BiometricUtil>().hasBiometrics();
186+
if (authMethod.method == AuthMethod.BIOMETRICS && hasBiometrics) {
187+
setState(() {
188+
_showLock = true;
189+
_showUnlockButton = true;
194190
});
195-
});
191+
try {
192+
await authenticateWithBiometrics();
193+
} catch (e) {
194+
await authenticateWithPin(transitions: transitions);
195+
}
196+
} else {
197+
await authenticateWithPin(transitions: transitions);
198+
}
196199
}
197200

198201
@override

lib/ui/send/send_confirm_sheet.dart

Lines changed: 48 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -325,26 +325,20 @@ class _SendConfirmSheetState extends State<SendConfirmSheet> {
325325
AppButtonType.PRIMARY,
326326
CaseChange.toUpperCase(
327327
AppLocalization.of(context).confirm, context),
328-
Dimens.BUTTON_TOP_DIMENS, onPressed: () {
328+
Dimens.BUTTON_TOP_DIMENS, onPressed: () async {
329329
// Authenticate
330-
sl
331-
.get<SharedPrefsUtil>()
332-
.getAuthMethod()
333-
.then((authMethod) {
334-
sl
335-
.get<BiometricUtil>()
336-
.hasBiometrics()
337-
.then((hasBiometrics) {
338-
if (authMethod.method == AuthMethod.BIOMETRICS &&
339-
hasBiometrics) {
340-
sl
341-
.get<BiometricUtil>()
342-
.authenticateWithBiometrics(
343-
context,
344-
AppLocalization.of(context)
345-
.sendAmountConfirm
346-
.replaceAll("%1", amount))
347-
.then((authenticated) {
330+
AuthenticationMethod authMethod = await sl.get<SharedPrefsUtil>().getAuthMethod();
331+
bool hasBiometrics = await sl.get<BiometricUtil>().hasBiometrics();
332+
if (authMethod.method == AuthMethod.BIOMETRICS &&
333+
hasBiometrics) {
334+
try {
335+
bool authenticated = await sl
336+
.get<BiometricUtil>()
337+
.authenticateWithBiometrics(
338+
context,
339+
AppLocalization.of(context)
340+
.sendAmountConfirm
341+
.replaceAll("%1", amount));
348342
if (authenticated) {
349343
sl.get<HapticUtil>().fingerprintSucess();
350344
_showSendingAnimation(context);
@@ -358,38 +352,14 @@ class _SendConfirmSheetState extends State<SendConfirmSheet> {
358352
widget.localCurrency,
359353
paymentRequest: widget.paymentRequest);
360354
}
361-
});
355+
} catch (e) {
356+
await authenticateWithPin();
357+
}
362358
} else {
363-
// PIN Authentication
364-
sl.get<Vault>().getPin().then((expectedPin) {
365-
Navigator.of(context).push(MaterialPageRoute(
366-
builder: (BuildContext context) {
367-
return new PinScreen(
368-
PinOverlayType.ENTER_PIN,
369-
(pin) {
370-
Navigator.of(context).pop();
371-
_showSendingAnimation(context);
372-
StateContainer.of(context).requestSend(
373-
StateContainer.of(context)
374-
.wallet
375-
.frontier,
376-
destinationAltered,
377-
widget.maxSend ? "0" : widget.amountRaw,
378-
localCurrencyAmount:
379-
widget.localCurrency,
380-
paymentRequest: widget.paymentRequest);
381-
},
382-
expectedPin: expectedPin,
383-
description: AppLocalization.of(context)
384-
.sendAmountConfirmPin
385-
.replaceAll("%1", amount),
386-
);
387-
}));
388-
});
359+
await authenticateWithPin();
389360
}
390-
});
391-
});
392-
}),
361+
}
362+
)
393363
],
394364
),
395365
// A row for CANCEL Button
@@ -412,4 +382,33 @@ class _SendConfirmSheetState extends State<SendConfirmSheet> {
412382
],
413383
));
414384
}
385+
386+
Future<void> authenticateWithPin() async {
387+
// PIN Authentication
388+
sl.get<Vault>().getPin().then((expectedPin) {
389+
Navigator.of(context).push(MaterialPageRoute(
390+
builder: (BuildContext context) {
391+
return new PinScreen(
392+
PinOverlayType.ENTER_PIN,
393+
(pin) {
394+
Navigator.of(context).pop();
395+
_showSendingAnimation(context);
396+
StateContainer.of(context).requestSend(
397+
StateContainer.of(context)
398+
.wallet
399+
.frontier,
400+
destinationAltered,
401+
widget.maxSend ? "0" : widget.amountRaw,
402+
localCurrencyAmount:
403+
widget.localCurrency,
404+
paymentRequest: widget.paymentRequest);
405+
},
406+
expectedPin: expectedPin,
407+
description: AppLocalization.of(context)
408+
.sendAmountConfirmPin
409+
.replaceAll("%1", amount),
410+
);
411+
}));
412+
});
413+
}
415414
}

0 commit comments

Comments
 (0)