11import 'dart:async' ;
22
33import 'package:auto_size_text/auto_size_text.dart' ;
4+ import 'package:event_taxi/event_taxi.dart' ;
45import 'package:flutter/material.dart' ;
56import 'package:manta_dart/manta_wallet.dart' ;
67import 'package:manta_dart/messages.dart' ;
78import 'package:natrium_wallet_flutter/app_icons.dart' ;
89
910import 'package:natrium_wallet_flutter/appstate_container.dart' ;
11+ import 'package:natrium_wallet_flutter/bus/events.dart' ;
1012import 'package:natrium_wallet_flutter/dimens.dart' ;
1113import 'package:natrium_wallet_flutter/model/db/appdb.dart' ;
1214import '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