Generic Enhancements (#1426)

* Better handle deep links after authentication

* handle no auth required case and some enhancements

* deprecate old variables [skip ci]
This commit is contained in:
Omar Hatem 2024-05-03 20:36:00 +03:00 committed by GitHub
parent 4c50cc7551
commit e4fd534949
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 42 additions and 34 deletions

View file

@ -154,9 +154,11 @@ class WalletInfo extends HiveObject {
@HiveField(15)
List<String>? usedAddresses;
@deprecated
@HiveField(16)
DerivationType? derivationType; // no longer used
@deprecated
@HiveField(17)
String? derivationPath; // no longer used

View file

@ -52,6 +52,7 @@ class RootState extends State<Root> with WidgetsBindingObserver {
StreamSubscription<Uri?>? stream;
ReactionDisposer? _walletReactionDisposer;
ReactionDisposer? _deepLinksReactionDisposer;
Uri? launchUri;
@override
@ -76,6 +77,7 @@ class RootState extends State<Root> with WidgetsBindingObserver {
void dispose() {
stream?.cancel();
_walletReactionDisposer?.call();
_deepLinksReactionDisposer?.call();
super.dispose();
}
@ -93,10 +95,32 @@ class RootState extends State<Root> with WidgetsBindingObserver {
}
}
void handleDeepLinking(Uri? uri) {
void handleDeepLinking(Uri? uri) async {
if (uri == null || !mounted) return;
launchUri = uri;
bool requireAuth = await widget.authService.requireAuth();
if (!requireAuth && widget.authenticationStore.state == AuthenticationState.allowed) {
_navigateToDeepLinkScreen();
return;
}
_deepLinksReactionDisposer = reaction(
(_) => widget.authenticationStore.state,
(AuthenticationState state) {
if (state == AuthenticationState.allowed) {
if (widget.appStore.wallet == null) {
waitForWalletInstance(context, launchUri!);
} else {
_navigateToDeepLinkScreen();
}
_deepLinksReactionDisposer?.call();
_deepLinksReactionDisposer = null;
}
},
);
}
@override
@ -172,35 +196,8 @@ class RootState extends State<Root> with WidgetsBindingObserver {
},
);
});
} else if (_isValidPaymentUri()) {
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)) {
widget.navigatorKey.currentState?.pushNamed(
Routes.walletConnectConnectionsListing,
arguments: launchUri,
);
launchUri = null;
} else {
_nonETHWalletErrorToast(S.current.switchToEVMCompatibleWallet);
}
}
launchUri = null;
return WillPopScope(
onWillPop: () async => false,
child: widget.child,
@ -252,13 +249,10 @@ class RootState extends State<Root> with WidgetsBindingObserver {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (context.mounted) {
_walletReactionDisposer = reaction(
(_) => widget.appStore.wallet,
(WalletBase? wallet) {
(_) => widget.appStore.wallet,
(WalletBase? wallet) {
if (wallet != null) {
widget.navigatorKey.currentState?.pushNamed(
Routes.send,
arguments: PaymentRequest.fromUri(tempLaunchUri),
);
_navigateToDeepLinkScreen();
_walletReactionDisposer?.call();
_walletReactionDisposer = null;
}
@ -267,4 +261,16 @@ class RootState extends State<Root> with WidgetsBindingObserver {
}
});
}
void _navigateToDeepLinkScreen() {
if (_getRouteToGo() != null) {
WidgetsBinding.instance.addPostFrameCallback((_) {
widget.navigatorKey.currentState?.pushNamed(
_getRouteToGo()!,
arguments: isWalletConnectLink ? launchUri : PaymentRequest.fromUri(launchUri),
);
launchUri = null;
});
}
}
}