From 58b2dfb26cc32a1f445ad916b941fea2c910349f Mon Sep 17 00:00:00 2001 From: Serhii Date: Tue, 19 Mar 2024 21:55:34 +0200 Subject: [PATCH] Fix deep link handling issue (#1297) * Update root.dart * Revert "Update root.dart" This reverts commit 5808903aafa81c316eb8a32a462ee18392e08f2f. * Update root.dart * increase delay * fix with mobx reaction * lunchUri fix --- lib/src/screens/root/root.dart | 42 ++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/lib/src/screens/root/root.dart b/lib/src/screens/root/root.dart index 5704c99ad..8a75b78bb 100644 --- a/lib/src/screens/root/root.dart +++ b/lib/src/screens/root/root.dart @@ -5,6 +5,7 @@ import 'package:cake_wallet/generated/i18n.dart'; import 'package:cake_wallet/reactions/wallet_connect.dart'; import 'package:cake_wallet/utils/device_info.dart'; import 'package:cake_wallet/utils/payment_request.dart'; +import 'package:cw_core/wallet_base.dart'; import 'package:flutter/material.dart'; import 'package:cake_wallet/routes.dart'; import 'package:cake_wallet/src/screens/auth/auth_page.dart'; @@ -12,6 +13,7 @@ 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:fluttertoast/fluttertoast.dart'; +import 'package:mobx/mobx.dart'; import 'package:uni_links/uni_links.dart'; import 'package:cake_wallet/src/screens/setup_2fa/setup_2fa_enter_code_page.dart'; @@ -49,6 +51,7 @@ class RootState extends State with WidgetsBindingObserver { bool _requestAuth; StreamSubscription? stream; + ReactionDisposer? _walletReactionDisposer; Uri? launchUri; @override @@ -72,6 +75,7 @@ class RootState extends State with WidgetsBindingObserver { @override void dispose() { stream?.cancel(); + _walletReactionDisposer?.call(); super.dispose(); } @@ -169,10 +173,20 @@ class RootState extends State with WidgetsBindingObserver { ); }); } else if (_isValidPaymentUri()) { - widget.navigatorKey.currentState?.pushNamed( - Routes.send, - arguments: PaymentRequest.fromUri(launchUri), - ); + if (widget.authenticationStore.state == AuthenticationState.uninitialized) { + launchUri = null; + } else { + if (widget.appStore.wallet == null) { + waitForWalletInstance(context, launchUri!); + launchUri = null; + } else { + widget.navigatorKey.currentState?.pushNamed( + Routes.send, + arguments: PaymentRequest.fromUri(launchUri), + ); + launchUri = null; + } + } launchUri = null; } else if (isWalletConnectLink) { if (isEVMCompatibleChain(widget.appStore.wallet!.type)) { @@ -233,4 +247,24 @@ class RootState extends State with WidgetsBindingObserver { fontSize: 16.0, ); } + + void waitForWalletInstance(BuildContext context, Uri tempLaunchUri) { + WidgetsBinding.instance.addPostFrameCallback((_) { + if (context.mounted) { + _walletReactionDisposer = reaction( + (_) => widget.appStore.wallet, + (WalletBase? wallet) { + if (wallet != null) { + widget.navigatorKey.currentState?.pushNamed( + Routes.send, + arguments: PaymentRequest.fromUri(tempLaunchUri), + ); + _walletReactionDisposer?.call(); + _walletReactionDisposer = null; + } + }, + ); + } + }); + } }