Skip to content

Commit 16097fe

Browse files
committed
Re-work authentication & pin screen
1 parent 4bc7398 commit 16097fe

File tree

13 files changed

+268
-256
lines changed

13 files changed

+268
-256
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fix errors while sending

lib/bus/authenticated_event.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import 'package:event_taxi/event_taxi.dart';
2+
3+
enum AUTH_EVENT_TYPE { SEND, CHANGE_MANUAL, CHANGE }
4+
5+
class AuthenticatedEvent implements Event {
6+
final AUTH_EVENT_TYPE authType;
7+
8+
AuthenticatedEvent(this.authType);
9+
}

lib/bus/events.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ export 'contact_removed_event.dart';
1212
export 'transfer_complete_event.dart';
1313
export 'transfer_confirm_event.dart';
1414
export 'account_changed_event.dart';
15-
export 'account_modified_event.dart';
15+
export 'account_modified_event.dart';
16+
export 'authenticated_event.dart';

lib/ui/intro/intro_backup_confirm.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,15 @@ class _IntroBackupConfirmState extends State<IntroBackupConfirm> {
107107
context,
108108
AppButtonType.PRIMARY,
109109
AppLocalization.of(context).yes.toUpperCase(),
110-
Dimens.BUTTON_TOP_DIMENS, onPressed: () {
111-
Navigator.of(context).push(MaterialPageRoute(
110+
Dimens.BUTTON_TOP_DIMENS, onPressed: () async {
111+
String pin = await Navigator.of(context).push(MaterialPageRoute(
112112
builder: (BuildContext context) {
113113
return new PinScreen(PinOverlayType.NEW_PIN,
114-
(_pinEnteredCallback));
114+
);
115115
}));
116+
if (pin != null && pin.length > 5) {
117+
_pinEnteredCallback(pin);
118+
}
116119
}),
117120
],
118121
),
@@ -138,7 +141,6 @@ class _IntroBackupConfirmState extends State<IntroBackupConfirm> {
138141
}
139142

140143
void _pinEnteredCallback(String pin) async {
141-
Navigator.of(context).pop();
142144
await sl.get<SharedPrefsUtil>().setSeedBackedUp(true);
143145
await sl.get<Vault>().writePin(pin);
144146
PriceConversion conversion = await sl.get<SharedPrefsUtil>().getPriceConversion();

lib/ui/intro/intro_password.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,10 +286,13 @@ class _IntroPasswordState extends State<IntroPassword> {
286286
await sl.get<DBHelper>().dropAccounts();
287287
await NanoUtil().loginAccount(widget.seed, context);
288288
StateContainer.of(context).requestUpdate();
289-
Navigator.of(context).push(
289+
String pin = await Navigator.of(context).push(
290290
MaterialPageRoute(builder: (BuildContext context) {
291-
return PinScreen(PinOverlayType.NEW_PIN, _pinEnteredCallback);
291+
return PinScreen(PinOverlayType.NEW_PIN);
292292
}));
293+
if (pin != null && pin.length > 5) {
294+
_pinEnteredCallback(pin);
295+
}
293296
} else {
294297
// Generate a new seed and encrypt
295298
String seed = NanoSeeds.generateSeed();
@@ -307,7 +310,6 @@ class _IntroPasswordState extends State<IntroPassword> {
307310
}
308311

309312
void _pinEnteredCallback(String pin) async {
310-
Navigator.of(context).pop();
311313
await sl.get<Vault>().writePin(pin);
312314
PriceConversion conversion = await sl.get<SharedPrefsUtil>().getPriceConversion();
313315
// Update wallet

lib/ui/intro/intro_password_on_launch.dart

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -119,24 +119,22 @@ class _IntroPasswordOnLaunchState extends State<IntroPasswordOnLaunch> {
119119
children: <Widget>[
120120
// Skip Button
121121
AppButton.buildAppButton(context, AppButtonType.PRIMARY,
122-
AppLocalization.of(context).noSkipButton, Dimens.BUTTON_TOP_DIMENS, onPressed: () {
122+
AppLocalization.of(context).noSkipButton, Dimens.BUTTON_TOP_DIMENS, onPressed: () async {
123123
if (widget.seed != null) {
124-
sl.get<Vault>()
125-
.setSeed(widget.seed)
126-
.then((result) {
127-
sl.get<DBHelper>().dropAccounts().then((_) {
128-
NanoUtil().loginAccount(widget.seed, context).then((_) {
129-
StateContainer.of(context).requestUpdate();
130-
Navigator.of(context).push(
131-
MaterialPageRoute(builder:
132-
(BuildContext context) {
133-
return PinScreen(
134-
PinOverlayType.NEW_PIN,
135-
(_pinEnteredCallback));
136-
}));
137-
});
138-
});
139-
});
124+
await sl.get<Vault>().setSeed(widget.seed);
125+
await sl.get<DBHelper>().dropAccounts();
126+
await NanoUtil().loginAccount(widget.seed, context);
127+
StateContainer.of(context).requestUpdate();
128+
String pin = await Navigator.of(context).push(
129+
MaterialPageRoute(builder:
130+
(BuildContext context) {
131+
return PinScreen(
132+
PinOverlayType.NEW_PIN,
133+
);
134+
}));
135+
if (pin != null && pin.length > 5) {
136+
_pinEnteredCallback(pin);
137+
}
140138
} else {
141139
sl.get<Vault>().setSeed(NanoSeeds.generateSeed()).then((result) {
142140
// Update wallet
@@ -175,7 +173,6 @@ class _IntroPasswordOnLaunchState extends State<IntroPasswordOnLaunch> {
175173
}
176174

177175
void _pinEnteredCallback(String pin) async {
178-
Navigator.of(context).pop();
179176
await sl.get<Vault>().writePin(pin);
180177
PriceConversion conversion = await sl.get<SharedPrefsUtil>().getPriceConversion();
181178
// Update wallet

lib/ui/lock_screen.dart

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ class _AppLockScreenState extends State<AppLockScreen> {
4444
}
4545

4646
Widget _buildPinScreen(BuildContext context, String expectedPin) {
47-
return PinScreen(PinOverlayType.ENTER_PIN, (pin) {
48-
_goHome();
49-
},
47+
return PinScreen(PinOverlayType.ENTER_PIN,
5048
expectedPin: expectedPin,
5149
description: AppLocalization.of(context).unlockPin,
5250
pinScreenBackgroundColor:
@@ -141,27 +139,30 @@ class _AppLockScreenState extends State<AppLockScreen> {
141139

142140
Future<void> authenticateWithPin({bool transitions = false}) async {
143141
String expectedPin = await sl.get<Vault>().getPin();
142+
bool auth = false;
144143
if (transitions) {
145-
Navigator.of(context).push(
144+
auth = await Navigator.of(context).push(
146145
MaterialPageRoute(builder: (BuildContext context) {
147146
return _buildPinScreen(context, expectedPin);
148147
}),
149148
);
150149
} else {
151-
Navigator.of(context).push(
150+
auth = await Navigator.of(context).push(
152151
NoPushTransitionRoute(builder: (BuildContext context) {
153152
return _buildPinScreen(context, expectedPin);
154153
}),
155154
);
156155
}
157-
Future.delayed(Duration(milliseconds: 200), () {
158-
if (mounted) {
159-
setState(() {
160-
_showUnlockButton = true;
161-
_showLock = true;
162-
});
163-
}
164-
});
156+
await Future.delayed(Duration(milliseconds: 200));
157+
if (mounted) {
158+
setState(() {
159+
_showUnlockButton = true;
160+
_showLock = true;
161+
});
162+
}
163+
if (auth) {
164+
_goHome();
165+
}
165166
}
166167

167168
Future<void> _authenticate({bool transitions = false}) async {

lib/ui/send/send_confirm_sheet.dart

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import 'dart:async';
22

33
import 'package:auto_size_text/auto_size_text.dart';
4+
import 'package:event_taxi/event_taxi.dart';
45
import 'package:flutter/material.dart';
56
import 'package:manta_dart/manta_wallet.dart';
67
import 'package:manta_dart/messages.dart';
78
import 'package:natrium_wallet_flutter/app_icons.dart';
89

910
import 'package:natrium_wallet_flutter/appstate_container.dart';
11+
import 'package:natrium_wallet_flutter/bus/events.dart';
1012
import 'package:natrium_wallet_flutter/dimens.dart';
1113
import 'package:natrium_wallet_flutter/model/db/appdb.dart';
1214
import 'package:natrium_wallet_flutter/model/db/contact.dart';
@@ -60,9 +62,28 @@ class _SendConfirmSheetState extends State<SendConfirmSheet> {
6062
bool sent;
6163
bool isMantaTransaction;
6264

65+
StreamSubscription<AuthenticatedEvent> _authSub;
66+
67+
void _registerBus() {
68+
_authSub = EventTaxiImpl.singleton()
69+
.registerTo<AuthenticatedEvent>()
70+
.listen((event) {
71+
if (event.authType == AUTH_EVENT_TYPE.SEND) {
72+
_doSend();
73+
}
74+
});
75+
}
76+
77+
void _destroyBus() {
78+
if (_authSub != null) {
79+
_authSub.cancel();
80+
}
81+
}
82+
6383
@override
6484
void initState() {
6585
super.initState();
86+
_registerBus();
6687
this.animationOpen = false;
6788
this.sent = false;
6889
this.isMantaTransaction = widget.manta != null && widget.paymentRequest != null;
@@ -81,6 +102,12 @@ class _SendConfirmSheetState extends State<SendConfirmSheet> {
81102
destinationAltered = widget.destination.replaceAll("xrb_", "nano_");
82103
}
83104

105+
@override
106+
void dispose() {
107+
_destroyBus();
108+
super.dispose();
109+
}
110+
84111
void _showSendingAnimation(BuildContext context) {
85112
animationOpen = true;
86113
Navigator.of(context).push(AnimationLoadingOverlay(
@@ -307,8 +334,8 @@ class _SendConfirmSheetState extends State<SendConfirmSheet> {
307334
.replaceAll("%1", amount));
308335
if (authenticated) {
309336
sl.get<HapticUtil>().fingerprintSucess();
310-
_showSendingAnimation(context);
311-
await _doSend();
337+
EventTaxiImpl.singleton()
338+
.fire(AuthenticatedEvent(AUTH_EVENT_TYPE.SEND));
312339
}
313340
} catch (e) {
314341
await authenticateWithPin();
@@ -343,6 +370,7 @@ class _SendConfirmSheetState extends State<SendConfirmSheet> {
343370

344371
Future<void> _doSend() async {
345372
try {
373+
_showSendingAnimation(context);
346374
ProcessResponse resp = await sl.get<AccountService>().requestSend(
347375
StateContainer.of(context).wallet.representative,
348376
StateContainer.of(context).wallet.frontier,
@@ -381,22 +409,21 @@ class _SendConfirmSheetState extends State<SendConfirmSheet> {
381409

382410
Future<void> authenticateWithPin() async {
383411
// PIN Authentication
384-
sl.get<Vault>().getPin().then((expectedPin) {
385-
Navigator.of(context).push(MaterialPageRoute(
412+
String expectedPin = await sl.get<Vault>().getPin();
413+
bool auth = await Navigator.of(context).push(MaterialPageRoute(
386414
builder: (BuildContext context) {
387415
return new PinScreen(
388416
PinOverlayType.ENTER_PIN,
389-
(pin) async {
390-
Navigator.of(context).pop();
391-
_showSendingAnimation(context);
392-
await _doSend();
393-
},
394417
expectedPin: expectedPin,
395418
description: AppLocalization.of(context)
396419
.sendAmountConfirmPin
397420
.replaceAll("%1", amount),
398421
);
399422
}));
400-
});
423+
if (auth != null && auth) {
424+
await Future.delayed(Duration(milliseconds: 200));
425+
EventTaxiImpl.singleton()
426+
.fire(AuthenticatedEvent(AUTH_EVENT_TYPE.SEND));
427+
}
401428
}
402429
}

0 commit comments

Comments
 (0)