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)
|
@HiveField(15)
|
||||||
List<String>? usedAddresses;
|
List<String>? usedAddresses;
|
||||||
|
|
||||||
|
@deprecated
|
||||||
@HiveField(16)
|
@HiveField(16)
|
||||||
DerivationType? derivationType; // no longer used
|
DerivationType? derivationType; // no longer used
|
||||||
|
|
||||||
|
@deprecated
|
||||||
@HiveField(17)
|
@HiveField(17)
|
||||||
String? derivationPath; // no longer used
|
String? derivationPath; // no longer used
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,7 @@ class RootState extends State<Root> with WidgetsBindingObserver {
|
||||||
|
|
||||||
StreamSubscription<Uri?>? stream;
|
StreamSubscription<Uri?>? stream;
|
||||||
ReactionDisposer? _walletReactionDisposer;
|
ReactionDisposer? _walletReactionDisposer;
|
||||||
|
ReactionDisposer? _deepLinksReactionDisposer;
|
||||||
Uri? launchUri;
|
Uri? launchUri;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -76,6 +77,7 @@ class RootState extends State<Root> with WidgetsBindingObserver {
|
||||||
void dispose() {
|
void dispose() {
|
||||||
stream?.cancel();
|
stream?.cancel();
|
||||||
_walletReactionDisposer?.call();
|
_walletReactionDisposer?.call();
|
||||||
|
_deepLinksReactionDisposer?.call();
|
||||||
super.dispose();
|
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;
|
if (uri == null || !mounted) return;
|
||||||
|
|
||||||
launchUri = uri;
|
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
|
@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(
|
return WillPopScope(
|
||||||
onWillPop: () async => false,
|
onWillPop: () async => false,
|
||||||
child: widget.child,
|
child: widget.child,
|
||||||
|
@ -252,13 +249,10 @@ class RootState extends State<Root> with WidgetsBindingObserver {
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
_walletReactionDisposer = reaction(
|
_walletReactionDisposer = reaction(
|
||||||
(_) => widget.appStore.wallet,
|
(_) => widget.appStore.wallet,
|
||||||
(WalletBase? wallet) {
|
(WalletBase? wallet) {
|
||||||
if (wallet != null) {
|
if (wallet != null) {
|
||||||
widget.navigatorKey.currentState?.pushNamed(
|
_navigateToDeepLinkScreen();
|
||||||
Routes.send,
|
|
||||||
arguments: PaymentRequest.fromUri(tempLaunchUri),
|
|
||||||
);
|
|
||||||
_walletReactionDisposer?.call();
|
_walletReactionDisposer?.call();
|
||||||
_walletReactionDisposer = null;
|
_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