diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index c53d1ea7b..bb901c131 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -29,6 +29,14 @@ + + + + + + UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight + CFBundleURLTypes + + + CFBundleTypeRole + Editor + CFBundleURLName + y.at + CFBundleURLSchemes + + cakewallet + + + UIViewControllerBasedStatusBarAppearance diff --git a/lib/main.dart b/lib/main.dart index 7c4b84de2..58b99bc3e 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,6 +1,10 @@ +import 'dart:async'; + import 'package:cake_wallet/bitcoin/unspent_coins_info.dart'; import 'package:cake_wallet/entities/language_service.dart'; import 'package:cake_wallet/buy/order.dart'; +import 'package:cake_wallet/store/yat_store.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:hive/hive.dart'; @@ -29,6 +33,7 @@ import 'package:cake_wallet/entities/template.dart'; import 'package:cake_wallet/exchange/trade.dart'; import 'package:cake_wallet/exchange/exchange_template.dart'; import 'package:cake_wallet/src/screens/root/root.dart'; +import 'package:uni_links/uni_links.dart'; final navigatorKey = GlobalKey(); @@ -168,7 +173,108 @@ Future initialSetup( monero_wallet.onStartup(); } -class App extends StatelessWidget { +class App extends StatefulWidget { + @override + AppState createState() => AppState(); +} + +class AppState extends State with SingleTickerProviderStateMixin { + AppState() { + yatStore = getIt.get(); + SystemChrome.setPreferredOrientations( + [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]); + } + + YatStore yatStore; + StreamSubscription stream; + + @override + void initState() { + super.initState(); + _handleIncomingLinks(yatStore); + _handleInitialUri(yatStore); + } + + @override + void dispose() { + stream?.cancel(); + super.dispose(); + } + + Future _handleInitialUri(YatStore yatStore) async { + try { + final uri = await getInitialUri(); + if (uri == null) { + print('Error: no initial uri'); + return; + } + print('got initial uri: $uri'); + if (!mounted) return; + yatStore.yatAddress = 'Yat address'; // FIXME + } catch (e) { + if (!mounted) return; + print(e.toString()); + } + } + + void _handleIncomingLinks(YatStore yatStore) { + if (!kIsWeb) { + stream = getUriLinksStream().listen((Uri uri) { + if (!mounted) return; + print('got uri: $uri'); + yatStore.yatAddress = 'Yat address'; // FIXME + }, onError: (Object error) { + if (!mounted) return; + print('Error: $error'); + }); + } + } + + @override + Widget build(BuildContext context) { + return Observer(builder: (BuildContext context) { + final settingsStore = getIt.get().settingsStore; + final statusBarColor = Colors.transparent; + final authenticationStore = getIt.get(); + final initialRoute = + authenticationStore.state == AuthenticationState.denied + ? Routes.disclaimer + : Routes.login; + final currentTheme = settingsStore.currentTheme; + final statusBarBrightness = currentTheme.type == ThemeType.dark + ? Brightness.light + : Brightness.dark; + final statusBarIconBrightness = currentTheme.type == ThemeType.dark + ? Brightness.light + : Brightness.dark; + SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle( + statusBarColor: statusBarColor, + statusBarBrightness: statusBarBrightness, + statusBarIconBrightness: statusBarIconBrightness)); + + return Root( + authenticationStore: authenticationStore, + navigatorKey: navigatorKey, + child: MaterialApp( + navigatorKey: navigatorKey, + debugShowCheckedModeBanner: false, + theme: settingsStore.theme, + localizationsDelegates: [ + S.delegate, + GlobalCupertinoLocalizations.delegate, + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + ], + supportedLocales: S.delegate.supportedLocales, + locale: Locale(settingsStore.languageCode), + onGenerateRoute: (settings) => Router.createRoute(settings), + initialRoute: initialRoute, + )); + }); + } +} + +/*class App extends StatelessWidget { App() { SystemChrome.setPreferredOrientations( [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]); @@ -216,4 +322,4 @@ class App extends StatelessWidget { )); }); } -} +}*/ diff --git a/lib/src/screens/yat/yat_alert.dart b/lib/src/screens/yat/yat_alert.dart index 71b558a27..294dccb75 100644 --- a/lib/src/screens/yat/yat_alert.dart +++ b/lib/src/screens/yat/yat_alert.dart @@ -6,9 +6,13 @@ import 'package:cake_wallet/src/widgets/scollable_with_bottom_section.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:cake_wallet/palette.dart'; +import 'package:url_launcher/url_launcher.dart'; class YatAlert extends StatelessWidget { static const aspectRatioImage = 1.133; + static const _baseUrl = 'https://yat.fyi'; + static const _signInSuffix = '/sign-in'; + static const _createSuffix = '/create'; final image = Image.asset('assets/images/yat_crypto.png'); @override @@ -81,8 +85,12 @@ class YatAlert extends StatelessWidget { iconData: CupertinoIcons .arrow_up_right_square, mainAxisAlignment: MainAxisAlignment.end, - onPressed: () => Navigator.of(context) - .popAndPushNamed(Routes.yat, arguments: YatMode.create)), + onPressed: () { + //Navigator.of(context) + // .popAndPushNamed(Routes.yat, arguments: YatMode.create); + final url = _baseUrl + _createSuffix; + launch(url); + }), Padding( padding: EdgeInsets.only(top: 24), child: PrimaryIconButton( @@ -95,8 +103,12 @@ class YatAlert extends StatelessWidget { iconData: CupertinoIcons .arrow_up_right_square, mainAxisAlignment: MainAxisAlignment.end, - onPressed: () => Navigator.of(context) - .popAndPushNamed(Routes.yat, arguments: YatMode.connect)) + onPressed: () { + //Navigator.of(context) + // .popAndPushNamed(Routes.yat, arguments: YatMode.connect); + final url = _baseUrl + _signInSuffix; + launch(url); + }) ) ] ), diff --git a/lib/src/screens/yat/yat_webview_page.dart b/lib/src/screens/yat/yat_webview_page.dart index 34de2de28..68bc46490 100644 --- a/lib/src/screens/yat/yat_webview_page.dart +++ b/lib/src/screens/yat/yat_webview_page.dart @@ -69,7 +69,7 @@ class YatWebViewPageBodyState extends State { super.initState(); _webViewkey = GlobalKey(); if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView(); - _fetchYatInfo(); + WidgetsBinding.instance.addPostFrameCallback(_afterLayout); } @override @@ -88,6 +88,10 @@ class YatWebViewPageBodyState extends State { setState(() => _webViewController = controller)); } + void _afterLayout(dynamic _) { + _fetchYatInfo(); + } + void _fetchYatInfo() { final keyword = 'dashboard'; _timer?.cancel(); @@ -103,6 +107,7 @@ class YatWebViewPageBodyState extends State { if (url.contains(keyword)) { timer.cancel(); await yatViewModel.fetchCartInfo(); + Navigator.of(context).pop(); } } catch (e) { print(e); diff --git a/pubspec.lock b/pubspec.lock index a520abbe3..e86545cae 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -956,6 +956,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.3.0" + uni_links: + dependency: "direct main" + description: + name: uni_links + url: "https://pub.dartlang.org" + source: hosted + version: "0.4.0" unorm_dart: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index d6b1b377d..c1319ff78 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -57,6 +57,7 @@ dependencies: smooth_page_indicator: ^0.2.0 webview_flutter: ^2.0.2 flutter_spinkit: ^5.0.0 + uni_links: ^0.4.0 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons.