mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-11-16 17:27:37 +00:00
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:
parent
4c50cc7551
commit
e4fd534949
2 changed files with 42 additions and 34 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
@ -255,10 +252,7 @@ class RootState extends State<Root> with WidgetsBindingObserver {
|
|||
(_) => 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;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue