Generic Enhancements (#1426)
* Better handle deep links after authentication * handle no auth required case and some enhancements * deprecate old variables [skip ci]
Omar Hatem committed
May 3, 2024 at 20:36 UTC
e4fd53494927d4915fcf9aa9e52d83ed6e108914
2 files changed
+42
-34
cw_core/lib/wallet_info.dart
+2
@@ -154,9 +154,11 @@ class WalletInfo extends HiveObject {
154
@HiveField(15)
155
List<String>? usedAddresses;
156
157
+ @deprecated
158
@HiveField(16)
159
DerivationType? derivationType; // no longer used
160
161
+ @deprecated
162
@HiveField(17)
163
String? derivationPath; // no longer used
164
lib/src/screens/root/root.dart
+40
-34
@@ -52,6 +52,7 @@ class RootState extends State<Root> with WidgetsBindingObserver {
52
53
StreamSubscription<Uri?>? stream;
54
ReactionDisposer? _walletReactionDisposer;
55
+ ReactionDisposer? _deepLinksReactionDisposer;
56
Uri? launchUri;
57
58
@override
@@ -76,6 +77,7 @@ class RootState extends State<Root> with WidgetsBindingObserver {
77
void dispose() {
78
stream?.cancel();
79
_walletReactionDisposer?.call();
80
+ _deepLinksReactionDisposer?.call();
81
super.dispose();
82
}
83
@@ -93,10 +95,32 @@ class RootState extends State<Root> with WidgetsBindingObserver {
95
}
96
}
97
96
- void handleDeepLinking(Uri? uri) {
98
+ void handleDeepLinking(Uri? uri) async {
99
if (uri == null || !mounted) return;
100
101
launchUri = uri;
102
+
103
+ bool requireAuth = await widget.authService.requireAuth();
104
+
105
+ if (!requireAuth && widget.authenticationStore.state == AuthenticationState.allowed) {
106
+ _navigateToDeepLinkScreen();
107
+ return;
108
+ }
109
+
110
+ _deepLinksReactionDisposer = reaction(
111
+ (_) => widget.authenticationStore.state,
112
+ (AuthenticationState state) {
113
+ if (state == AuthenticationState.allowed) {
114
+ if (widget.appStore.wallet == null) {
115
+ waitForWalletInstance(context, launchUri!);
116
+ } else {
117
+ _navigateToDeepLinkScreen();
118
+ }
119
+ _deepLinksReactionDisposer?.call();
120
+ _deepLinksReactionDisposer = null;
121
+ }
122
+ },
123
+ );
124
}
125
126
@override
@@ -172,35 +196,8 @@ class RootState extends State<Root> with WidgetsBindingObserver {
196
},
197
);
198
});
175
- } else if (_isValidPaymentUri()) {
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)) {
193
- widget.navigatorKey.currentState?.pushNamed(
194
- Routes.walletConnectConnectionsListing,
195
- arguments: launchUri,
196
- );
197
- launchUri = null;
198
- } else {
199
- _nonETHWalletErrorToast(S.current.switchToEVMCompatibleWallet);
200
- }
199
}
200
203
- launchUri = null;
201
return WillPopScope(
202
onWillPop: () async => false,
203
child: widget.child,
@@ -252,13 +249,10 @@ class RootState extends State<Root> with WidgetsBindingObserver {
249
WidgetsBinding.instance.addPostFrameCallback((_) {
250
if (context.mounted) {
251
_walletReactionDisposer = reaction(
255
- (_) => widget.appStore.wallet,
256
- (WalletBase? wallet) {
252
+ (_) => widget.appStore.wallet,
253
+ (WalletBase? wallet) {
254
if (wallet != null) {
258
- widget.navigatorKey.currentState?.pushNamed(
259
- Routes.send,
260
- arguments: PaymentRequest.fromUri(tempLaunchUri),
261
- );
255
+ _navigateToDeepLinkScreen();
256
_walletReactionDisposer?.call();
257
_walletReactionDisposer = null;
258
}
@@ -267,4 +261,16 @@ class RootState extends State<Root> with WidgetsBindingObserver {
261
}
262
});
263
}
264
+
265
+ void _navigateToDeepLinkScreen() {
266
+ if (_getRouteToGo() != null) {
267
+ WidgetsBinding.instance.addPostFrameCallback((_) {
268
+ widget.navigatorKey.currentState?.pushNamed(
269
+ _getRouteToGo()!,
270
+ arguments: isWalletConnectLink ? launchUri : PaymentRequest.fromUri(launchUri),
271
+ );
272
+ launchUri = null;
273
+ });
274
+ }
275
+ }
276
}