CAKE-356 | applied deep links to the app
OleksandrSobol committed
Sep 6, 2021 at 11:19 UTC
39c40255d310079a9c9ded596643c87164b5e53e
7 files changed
+159
-7
android/app/src/main/AndroidManifest.xml
+8
@@ -29,6 +29,14 @@
29
<action android:name="android.intent.action.MAIN"/>
30
<category android:name="android.intent.category.LAUNCHER"/>
31
</intent-filter>
32
+ <intent-filter>
33
+ <action android:name="android.intent.action.VIEW" />
34
+ <category android:name="android.intent.category.DEFAULT" />
35
+ <category android:name="android.intent.category.BROWSABLE" />
36
+ <data
37
+ android:scheme="cakewallet"
38
+ android:host="y.at" />
39
+ </intent-filter>
40
</activity>
41
<meta-data
42
android:name="flutterEmbedding"
ios/Runner/Info.plist
+13
@@ -57,6 +57,19 @@
57
<string>UIInterfaceOrientationLandscapeLeft</string>
58
<string>UIInterfaceOrientationLandscapeRight</string>
59
</array>
60
+ <key>CFBundleURLTypes</key>
61
+ <array>
62
+ <dict>
63
+ <key>CFBundleTypeRole</key>
64
+ <string>Editor</string>
65
+ <key>CFBundleURLName</key>
66
+ <string>y.at</string>
67
+ <key>CFBundleURLSchemes</key>
68
+ <array>
69
+ <string>cakewallet</string>
70
+ </array>
71
+ </dict>
72
+ </array>
73
<key>UIViewControllerBasedStatusBarAppearance</key>
74
<false/>
75
</dict>
lib/main.dart
+108
-2
@@ -1,6 +1,10 @@
1
+import 'dart:async';
2
+
3
import 'package:cake_wallet/bitcoin/unspent_coins_info.dart';
4
import 'package:cake_wallet/entities/language_service.dart';
5
import 'package:cake_wallet/buy/order.dart';
6
+import 'package:cake_wallet/store/yat_store.dart';
7
+import 'package:flutter/foundation.dart';
8
import 'package:flutter/material.dart';
9
import 'package:flutter/services.dart';
10
import 'package:hive/hive.dart';
@@ -29,6 +33,7 @@ import 'package:cake_wallet/entities/template.dart';
33
import 'package:cake_wallet/exchange/trade.dart';
34
import 'package:cake_wallet/exchange/exchange_template.dart';
35
import 'package:cake_wallet/src/screens/root/root.dart';
36
+import 'package:uni_links/uni_links.dart';
37
38
final navigatorKey = GlobalKey<NavigatorState>();
39
@@ -168,7 +173,108 @@ Future<void> initialSetup(
173
monero_wallet.onStartup();
174
}
175
171
-class App extends StatelessWidget {
176
+class App extends StatefulWidget {
177
+ @override
178
+ AppState createState() => AppState();
179
+}
180
+
181
+class AppState extends State<App> with SingleTickerProviderStateMixin {
182
+ AppState() {
183
+ yatStore = getIt.get<YatStore>();
184
+ SystemChrome.setPreferredOrientations(
185
+ [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
186
+ }
187
+
188
+ YatStore yatStore;
189
+ StreamSubscription stream;
190
+
191
+ @override
192
+ void initState() {
193
+ super.initState();
194
+ _handleIncomingLinks(yatStore);
195
+ _handleInitialUri(yatStore);
196
+ }
197
+
198
+ @override
199
+ void dispose() {
200
+ stream?.cancel();
201
+ super.dispose();
202
+ }
203
+
204
+ Future<void> _handleInitialUri(YatStore yatStore) async {
205
+ try {
206
+ final uri = await getInitialUri();
207
+ if (uri == null) {
208
+ print('Error: no initial uri');
209
+ return;
210
+ }
211
+ print('got initial uri: $uri');
212
+ if (!mounted) return;
213
+ yatStore.yatAddress = 'Yat address'; // FIXME
214
+ } catch (e) {
215
+ if (!mounted) return;
216
+ print(e.toString());
217
+ }
218
+ }
219
+
220
+ void _handleIncomingLinks(YatStore yatStore) {
221
+ if (!kIsWeb) {
222
+ stream = getUriLinksStream().listen((Uri uri) {
223
+ if (!mounted) return;
224
+ print('got uri: $uri');
225
+ yatStore.yatAddress = 'Yat address'; // FIXME
226
+ }, onError: (Object error) {
227
+ if (!mounted) return;
228
+ print('Error: $error');
229
+ });
230
+ }
231
+ }
232
+
233
+ @override
234
+ Widget build(BuildContext context) {
235
+ return Observer(builder: (BuildContext context) {
236
+ final settingsStore = getIt.get<AppStore>().settingsStore;
237
+ final statusBarColor = Colors.transparent;
238
+ final authenticationStore = getIt.get<AuthenticationStore>();
239
+ final initialRoute =
240
+ authenticationStore.state == AuthenticationState.denied
241
+ ? Routes.disclaimer
242
+ : Routes.login;
243
+ final currentTheme = settingsStore.currentTheme;
244
+ final statusBarBrightness = currentTheme.type == ThemeType.dark
245
+ ? Brightness.light
246
+ : Brightness.dark;
247
+ final statusBarIconBrightness = currentTheme.type == ThemeType.dark
248
+ ? Brightness.light
249
+ : Brightness.dark;
250
+ SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
251
+ statusBarColor: statusBarColor,
252
+ statusBarBrightness: statusBarBrightness,
253
+ statusBarIconBrightness: statusBarIconBrightness));
254
+
255
+ return Root(
256
+ authenticationStore: authenticationStore,
257
+ navigatorKey: navigatorKey,
258
+ child: MaterialApp(
259
+ navigatorKey: navigatorKey,
260
+ debugShowCheckedModeBanner: false,
261
+ theme: settingsStore.theme,
262
+ localizationsDelegates: [
263
+ S.delegate,
264
+ GlobalCupertinoLocalizations.delegate,
265
+ GlobalMaterialLocalizations.delegate,
266
+ GlobalWidgetsLocalizations.delegate,
267
+ ],
268
+ supportedLocales: S.delegate.supportedLocales,
269
+ locale: Locale(settingsStore.languageCode),
270
+ onGenerateRoute: (settings) => Router.createRoute(settings),
271
+ initialRoute: initialRoute,
272
+ ));
273
+ });
274
+ }
275
+}
276
+
277
+/*class App extends StatelessWidget {
278
App() {
279
SystemChrome.setPreferredOrientations(
280
[DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
@@ -216,4 +322,4 @@ class App extends StatelessWidget {
322
));
323
});
324
}
219
-}
325
+}*/
lib/src/screens/yat/yat_alert.dart
+16
-4
@@ -6,9 +6,13 @@ import 'package:cake_wallet/src/widgets/scollable_with_bottom_section.dart';
6
import 'package:flutter/cupertino.dart';
7
import 'package:flutter/material.dart';
8
import 'package:cake_wallet/palette.dart';
9
+import 'package:url_launcher/url_launcher.dart';
10
11
class YatAlert extends StatelessWidget {
12
static const aspectRatioImage = 1.133;
13
+ static const _baseUrl = 'https://yat.fyi';
14
+ static const _signInSuffix = '/sign-in';
15
+ static const _createSuffix = '/create';
16
final image = Image.asset('assets/images/yat_crypto.png');
17
18
@override
@@ -81,8 +85,12 @@ class YatAlert extends StatelessWidget {
85
iconData: CupertinoIcons
86
.arrow_up_right_square,
87
mainAxisAlignment: MainAxisAlignment.end,
84
- onPressed: () => Navigator.of(context)
85
- .popAndPushNamed(Routes.yat, arguments: YatMode.create)),
88
+ onPressed: () {
89
+ //Navigator.of(context)
90
+ // .popAndPushNamed(Routes.yat, arguments: YatMode.create);
91
+ final url = _baseUrl + _createSuffix;
92
+ launch(url);
93
+ }),
94
Padding(
95
padding: EdgeInsets.only(top: 24),
96
child: PrimaryIconButton(
@@ -95,8 +103,12 @@ class YatAlert extends StatelessWidget {
103
iconData: CupertinoIcons
104
.arrow_up_right_square,
105
mainAxisAlignment: MainAxisAlignment.end,
98
- onPressed: () => Navigator.of(context)
99
- .popAndPushNamed(Routes.yat, arguments: YatMode.connect))
106
+ onPressed: () {
107
+ //Navigator.of(context)
108
+ // .popAndPushNamed(Routes.yat, arguments: YatMode.connect);
109
+ final url = _baseUrl + _signInSuffix;
110
+ launch(url);
111
+ })
112
)
113
]
114
),
lib/src/screens/yat/yat_webview_page.dart
+6
-1
@@ -69,7 +69,7 @@ class YatWebViewPageBodyState extends State<YatWebViewPageBody> {
69
super.initState();
70
_webViewkey = GlobalKey();
71
if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
72
- _fetchYatInfo();
72
+ WidgetsBinding.instance.addPostFrameCallback(_afterLayout);
73
}
74
75
@override
@@ -88,6 +88,10 @@ class YatWebViewPageBodyState extends State<YatWebViewPageBody> {
88
setState(() => _webViewController = controller));
89
}
90
91
+ void _afterLayout(dynamic _) {
92
+ _fetchYatInfo();
93
+ }
94
+
95
void _fetchYatInfo() {
96
final keyword = 'dashboard';
97
_timer?.cancel();
@@ -103,6 +107,7 @@ class YatWebViewPageBodyState extends State<YatWebViewPageBody> {
107
if (url.contains(keyword)) {
108
timer.cancel();
109
await yatViewModel.fetchCartInfo();
110
+ Navigator.of(context).pop();
111
}
112
} catch (e) {
113
print(e);
pubspec.lock
+7
@@ -956,6 +956,13 @@ packages:
956
url: "https://pub.dartlang.org"
957
source: hosted
958
version: "1.3.0"
959
+ uni_links:
960
+ dependency: "direct main"
961
+ description:
962
+ name: uni_links
963
+ url: "https://pub.dartlang.org"
964
+ source: hosted
965
+ version: "0.4.0"
966
unorm_dart:
967
dependency: "direct main"
968
description:
pubspec.yaml
+1
@@ -57,6 +57,7 @@ dependencies:
57
smooth_page_indicator: ^0.2.0
58
webview_flutter: ^2.0.2
59
flutter_spinkit: ^5.0.0
60
+ uni_links: ^0.4.0
61
62
# The following adds the Cupertino Icons font to your application.
63
# Use with the CupertinoIcons class for iOS style icons.