diff --git a/lib/main.dart b/lib/main.dart index 8e971ec4b..6431d2f6e 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -5,7 +5,6 @@ import 'package:cake_wallet/buy/order.dart'; import 'package:cake_wallet/ionia/ionia_category.dart'; import 'package:cake_wallet/ionia/ionia_merchant.dart'; import 'package:cake_wallet/store/yat/yat_store.dart'; -import 'package:cake_wallet/utils/payment_request.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -39,8 +38,6 @@ import 'package:cw_core/unspent_coins_info.dart'; import 'package:cake_wallet/monero/monero.dart'; import 'package:cake_wallet/wallet_type_utils.dart'; -import 'src/screens/auth/auth_page.dart'; - final navigatorKey = GlobalKey(); final rootKey = GlobalKey(); @@ -205,47 +202,6 @@ class AppState extends State with SingleTickerProviderStateMixin { super.initState(); //_handleIncomingLinks(); //_handleInitialUri(); - - initUniLinks(); - } - - @override - void dispose() { - stream?.cancel(); - super.dispose(); - } - - /// handle app links while the app is already started - /// whether its in the foreground or in the background. - Future initUniLinks() async { - try { - stream = uriLinkStream.listen((Uri? uri) { - handleDeepLinking(uri); - }); - - final Uri? initialUri = await getInitialUri(); - - handleDeepLinking(initialUri); - } catch (e) { - print(e); - } - } - - void handleDeepLinking(Uri? uri) { - if (uri == null || !mounted) return; - - Navigator.of(navigatorKey.currentContext!).pushNamed(Routes.auth, - arguments: (bool isAuthenticatedSuccessfully, AuthPageState auth) { - if (isAuthenticatedSuccessfully) { - auth.close(route: Routes.send, arguments: PaymentRequest.fromUri(uri)); - } - }); - - // Navigator.pushNamed( - // navigatorKey.currentContext!, - // Routes.send, - // arguments: PaymentRequest.fromUri(uri), - // ); } Future _handleInitialUri() async { diff --git a/lib/src/screens/root/root.dart b/lib/src/screens/root/root.dart index c507f6e1f..014dd0451 100644 --- a/lib/src/screens/root/root.dart +++ b/lib/src/screens/root/root.dart @@ -1,10 +1,12 @@ import 'dart:async'; +import 'package:cake_wallet/utils/payment_request.dart'; import 'package:flutter/material.dart'; import 'package:cake_wallet/routes.dart'; import 'package:cake_wallet/src/screens/auth/auth_page.dart'; import 'package:cake_wallet/store/app_store.dart'; import 'package:cake_wallet/store/authentication_store.dart'; import 'package:cake_wallet/entities/qr_scanner.dart'; +import 'package:uni_links/uni_links.dart'; class Root extends StatefulWidget { Root( @@ -35,6 +37,9 @@ class RootState extends State with WidgetsBindingObserver { bool _isInactive; bool _postFrameCallback; + StreamSubscription? stream; + Uri? launchUri; + @override void initState() { _isInactiveController = StreamController.broadcast(); @@ -42,6 +47,34 @@ class RootState extends State with WidgetsBindingObserver { _postFrameCallback = false; WidgetsBinding.instance.addObserver(this); super.initState(); + + initUniLinks(); + } + + @override + void dispose() { + stream?.cancel(); + super.dispose(); + } + + /// handle app links while the app is already started + /// whether its in the foreground or in the background. + Future initUniLinks() async { + try { + stream = uriLinkStream.listen((Uri? uri) { + handleDeepLinking(uri); + }); + + handleDeepLinking(await getInitialUri()); + } catch (e) { + print(e); + } + } + + void handleDeepLinking(Uri? uri) { + if (uri == null || !mounted) return; + + launchUri = uri; } @override @@ -75,7 +108,11 @@ class RootState extends State with WidgetsBindingObserver { } _reset(); - auth.close(); + auth.close( + route: launchUri != null ? Routes.send : null, + arguments: PaymentRequest.fromUri(launchUri), + ); + launchUri = null; }); }); }