forked from MXCzkEVM/datadash-wallet
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from MXCzkEVM/app_links
App links
- Loading branch information
Showing
22 changed files
with
241 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export 'app_links_router.dart'; | ||
export 'moonchain_app_links.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:moonchain_wallet/app/logger.dart'; | ||
import 'package:moonchain_wallet/core/core.dart'; | ||
import 'package:moonchain_wallet/features/dapps/dapps.dart'; | ||
import 'package:moonchain_wallet/features/portfolio/presentation/portfolio_page.dart'; | ||
import 'package:moonchain_wallet/features/wallet/wallet.dart'; | ||
|
||
class AppLinksRouter { | ||
AppLinksRouter(this.navigator); | ||
|
||
NavigatorState? navigator; | ||
|
||
// TODO: | ||
// CHeck login | ||
// What if already in that page | ||
// Check to push and replace or only push | ||
// Link : https://www.mxc1usd.com/app/ | ||
// Routes : dapps - wallet - portfolio (wallet sub page) - openDapp - sendCrypto - | ||
// | ||
// https://www.mxc1usd.com/app/openDapp?url=https://github.com/reasje | ||
Widget openLink(Uri uri) { | ||
final page = getPage(uri); | ||
final params = getParams(uri); | ||
|
||
return getPageWithParams(page, params); | ||
} | ||
|
||
// Get page from uri | ||
String getPage(Uri uri) => uri.pathSegments[1]; | ||
|
||
// Get params | ||
// Note: https://mxc1usd.com/app/openDapp?url=https://testnet.blueberryring.com?invite=p8M6E7b02l has the | ||
// https://testnet.blueberryring.com?invite=p8M6E7b02l as List of params in the first index | ||
Map<String, List<String>>? getParams(Uri uri) => | ||
uri.hasQuery ? uri.queryParametersAll : null; | ||
|
||
// Push to stack | ||
Future pushTo(Widget page) => navigator!.push(route(page)); | ||
// Remove stacks until that page | ||
Future pushAndReplaceUntil(Widget page) => navigator!.pushAndRemoveUntil( | ||
route(page), | ||
(route) => false, | ||
); | ||
|
||
// Combine page with It's params | ||
Widget getPageWithParams(String page, Map<String, List<String>>? params) { | ||
late Widget toPushPage; | ||
|
||
switch ('/$page') { | ||
case '/': | ||
toPushPage = const DAppsPage(); | ||
break; | ||
case '/dapps': | ||
toPushPage = const DAppsPage(); | ||
break; | ||
case '/openDapp': | ||
final url = params!['url']![0]; | ||
toPushPage = OpenDAppPage(url: url,); | ||
break; | ||
case '/wallet': | ||
toPushPage = const WalletPage(); | ||
break; | ||
case '/portfolio': | ||
toPushPage = const PortfolioPage(); | ||
break; | ||
default: | ||
toPushPage = const DAppsPage(); | ||
} | ||
|
||
return toPushPage; | ||
} | ||
|
||
/// This function will do the navigation according to the page widget that | ||
/// includes the params based on how page specific navigation instruction. | ||
void navigateTo(Widget toPushPage){ | ||
late Function() navigationFunc; | ||
|
||
if (toPushPage.runtimeType == OpenDAppPage) { | ||
navigationFunc = () { | ||
pushTo(toPushPage); | ||
}; | ||
} else if (toPushPage.runtimeType == PortfolioPage) { | ||
navigationFunc = () { | ||
pushAndReplaceUntil(const WalletPage()); | ||
pushTo(toPushPage); | ||
}; | ||
} else { | ||
navigationFunc = () { | ||
pushAndReplaceUntil(toPushPage); | ||
}; | ||
} | ||
|
||
navigationFunc(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:app_links/app_links.dart'; | ||
|
||
class MoonchainAppLinks { | ||
late AppLinks _appLinks; | ||
StreamSubscription<Uri>? linkSubscription; | ||
|
||
|
||
Future<Uri?> initAppLinks() async { | ||
_appLinks = AppLinks(); | ||
|
||
// Check initial link if app was in cold state (terminated) | ||
final appLink = await _appLinks.getInitialAppLink(); | ||
|
||
// Handle link when app is in warm state (front or background) | ||
linkSubscription = _appLinks.uriLinkStream.listen((event) { }); | ||
return appLink; | ||
} | ||
|
||
|
||
void cancelAppLinks() { | ||
linkSubscription?.cancel(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:moonchain_wallet/app/app.dart'; | ||
import 'package:moonchain_wallet/core/core.dart'; | ||
import 'package:moonchain_wallet/features/security/security.dart'; | ||
import 'package:mxc_logic/mxc_logic.dart'; | ||
|
||
class MoonchainAppLinksUseCase extends ReactiveUseCase { | ||
MoonchainAppLinksUseCase( | ||
this._authUseCase, | ||
this._passcodeUseCase, | ||
) { | ||
initializeListeners(); | ||
} | ||
|
||
final AuthUseCase _authUseCase; | ||
final PasscodeUseCase _passcodeUseCase; | ||
|
||
BuildContext get currentContext => appNavigatorKey.currentContext!; | ||
NavigatorState? get navigator => appNavigatorKey.currentState; | ||
|
||
AppLinksRouter get _appLinksRouter => AppLinksRouter(navigator); | ||
late final MoonchainAppLinks _moonchainAppLinks = MoonchainAppLinks(); | ||
|
||
late final ValueStream<Stream<dynamic>?> websocketStreamSubscription = | ||
reactive(null); | ||
StreamSubscription<dynamic>? websocketCloseStreamSubscription; | ||
late final ValueStream<Stream<dynamic>> addressStream = | ||
reactive(const Stream.empty()); | ||
bool isPassCodeScreenShown = true; | ||
// This is the widget we need to navigate | ||
|
||
Widget? toNavigateWidget; | ||
Account? account; | ||
|
||
void initializeListeners() { | ||
_passcodeUseCase.passcodeScreenIsShown.listen((event) { | ||
isPassCodeScreenShown = event; | ||
checkNavigationFunction(); | ||
}); | ||
|
||
_moonchainAppLinks.initAppLinks().then((value) { | ||
if (value != null) { | ||
toNavigateWidget = _appLinksRouter.openLink(value); | ||
} | ||
_moonchainAppLinks.linkSubscription!.onData((data) { | ||
toNavigateWidget = _appLinksRouter.openLink(data); | ||
checkNavigationFunction(); | ||
}); | ||
}); | ||
} | ||
|
||
void checkNavigationFunction() { | ||
if (!isPassCodeScreenShown && toNavigateWidget != null) { | ||
_appLinksRouter.navigateTo(toNavigateWidget!); | ||
toNavigateWidget = null; | ||
} | ||
} | ||
|
||
@override | ||
Future<void> dispose() async { | ||
_moonchainAppLinks.cancelAppLinks(); | ||
super.dispose(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
...es/security/presentation/passcode_require/wrapper/passcode_require_wrapper_presenter.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.