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
Serhii committed
Mar 19, 2024 at 21:55 UTC
58b2dfb26cc32a1f445ad916b941fea2c910349f
1 file changed
+38
-4
lib/src/screens/root/root.dart
+38
-4
@@ -5,6 +5,7 @@ import 'package:cake_wallet/generated/i18n.dart';
5
import 'package:cake_wallet/reactions/wallet_connect.dart';
6
import 'package:cake_wallet/utils/device_info.dart';
7
import 'package:cake_wallet/utils/payment_request.dart';
8
+import 'package:cw_core/wallet_base.dart';
9
import 'package:flutter/material.dart';
10
import 'package:cake_wallet/routes.dart';
11
import 'package:cake_wallet/src/screens/auth/auth_page.dart';
@@ -12,6 +13,7 @@ import 'package:cake_wallet/store/app_store.dart';
13
import 'package:cake_wallet/store/authentication_store.dart';
14
import 'package:cake_wallet/entities/qr_scanner.dart';
15
import 'package:fluttertoast/fluttertoast.dart';
16
+import 'package:mobx/mobx.dart';
17
import 'package:uni_links/uni_links.dart';
18
import 'package:cake_wallet/src/screens/setup_2fa/setup_2fa_enter_code_page.dart';
19
@@ -49,6 +51,7 @@ class RootState extends State<Root> with WidgetsBindingObserver {
51
bool _requestAuth;
52
53
StreamSubscription<Uri?>? stream;
54
+ ReactionDisposer? _walletReactionDisposer;
55
Uri? launchUri;
56
57
@override
@@ -72,6 +75,7 @@ class RootState extends State<Root> with WidgetsBindingObserver {
75
@override
76
void dispose() {
77
stream?.cancel();
78
+ _walletReactionDisposer?.call();
79
super.dispose();
80
}
81
@@ -169,10 +173,20 @@ class RootState extends State<Root> with WidgetsBindingObserver {
173
);
174
});
175
} else if (_isValidPaymentUri()) {
172
- widget.navigatorKey.currentState?.pushNamed(
173
- Routes.send,
174
- arguments: PaymentRequest.fromUri(launchUri),
175
- );
176
+ if (widget.authenticationStore.state == AuthenticationState.uninitialized) {
177
+ launchUri = null;
178
+ } else {
179
+ if (widget.appStore.wallet == null) {
180
+ waitForWalletInstance(context, launchUri!);
181
+ launchUri = null;
182
+ } else {
183
+ widget.navigatorKey.currentState?.pushNamed(
184
+ Routes.send,
185
+ arguments: PaymentRequest.fromUri(launchUri),
186
+ );
187
+ launchUri = null;
188
+ }
189
+ }
190
launchUri = null;
191
} else if (isWalletConnectLink) {
192
if (isEVMCompatibleChain(widget.appStore.wallet!.type)) {
@@ -233,4 +247,24 @@ class RootState extends State<Root> with WidgetsBindingObserver {
247
fontSize: 16.0,
248
);
249
}
250
+
251
+ void waitForWalletInstance(BuildContext context, Uri tempLaunchUri) {
252
+ WidgetsBinding.instance.addPostFrameCallback((_) {
253
+ if (context.mounted) {
254
+ _walletReactionDisposer = reaction(
255
+ (_) => widget.appStore.wallet,
256
+ (WalletBase? wallet) {
257
+ if (wallet != null) {
258
+ widget.navigatorKey.currentState?.pushNamed(
259
+ Routes.send,
260
+ arguments: PaymentRequest.fromUri(tempLaunchUri),
261
+ );
262
+ _walletReactionDisposer?.call();
263
+ _walletReactionDisposer = null;
264
+ }
265
+ },
266
+ );
267
+ }
268
+ });
269
+ }
270
}