mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-20 06:08:34 +02:00
CAKE-356 | applied deep links to the app
This commit is contained in:
+108
-2
@@ -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<NavigatorState>();
|
||||
|
||||
@@ -168,7 +173,108 @@ Future<void> initialSetup(
|
||||
monero_wallet.onStartup();
|
||||
}
|
||||
|
||||
class App extends StatelessWidget {
|
||||
class App extends StatefulWidget {
|
||||
@override
|
||||
AppState createState() => AppState();
|
||||
}
|
||||
|
||||
class AppState extends State<App> with SingleTickerProviderStateMixin {
|
||||
AppState() {
|
||||
yatStore = getIt.get<YatStore>();
|
||||
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<void> _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<AppStore>().settingsStore;
|
||||
final statusBarColor = Colors.transparent;
|
||||
final authenticationStore = getIt.get<AuthenticationStore>();
|
||||
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 {
|
||||
));
|
||||
});
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
@@ -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);
|
||||
})
|
||||
)
|
||||
]
|
||||
),
|
||||
|
||||
@@ -69,7 +69,7 @@ class YatWebViewPageBodyState extends State<YatWebViewPageBody> {
|
||||
super.initState();
|
||||
_webViewkey = GlobalKey();
|
||||
if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
|
||||
_fetchYatInfo();
|
||||
WidgetsBinding.instance.addPostFrameCallback(_afterLayout);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -88,6 +88,10 @@ class YatWebViewPageBodyState extends State<YatWebViewPageBody> {
|
||||
setState(() => _webViewController = controller));
|
||||
}
|
||||
|
||||
void _afterLayout(dynamic _) {
|
||||
_fetchYatInfo();
|
||||
}
|
||||
|
||||
void _fetchYatInfo() {
|
||||
final keyword = 'dashboard';
|
||||
_timer?.cancel();
|
||||
@@ -103,6 +107,7 @@ class YatWebViewPageBodyState extends State<YatWebViewPageBody> {
|
||||
if (url.contains(keyword)) {
|
||||
timer.cancel();
|
||||
await yatViewModel.fetchCartInfo();
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
} catch (e) {
|
||||
print(e);
|
||||
|
||||
Reference in New Issue
Block a user