Update Branch to null safety Add deep linking to iOS

Update Branch to null safety Add deep linking to iOS

OmarHatem committed Nov 8, 2022 at 16:56 UTC f078457c7b6eab9cb8977b777727e366e090f636
8 files changed +74 -36
android/app/src/main/AndroidManifestBase.xml
+1 -1
@@ -38,7 +38,7 @@
38 android:scheme="cakewallet"
39 android:host="y.at" />
40 </intent-filter>
41 - <!-- bitcoin qr code scheme -->
41 + <!-- currencies qr code scheme -->
42 <intent-filter android:autoVerify="true">
43 <action android:name="android.intent.action.VIEW" />
44 <category android:name="android.intent.category.DEFAULT" />
ios/Runner/InfoBase.plist
+42 -12
@@ -21,18 +21,48 @@
21 <key>CFBundleSignature</key>
22 <string>????</string>
23 <key>CFBundleURLTypes</key>
24 - <array>
25 - <dict>
26 - <key>CFBundleTypeRole</key>
27 - <string>Editor</string>
28 - <key>CFBundleURLName</key>
29 - <string>y.at</string>
30 - <key>CFBundleURLSchemes</key>
31 - <array>
32 - <string>cakewallet</string>
33 - </array>
34 - </dict>
35 - </array>
24 + <array>
25 + <dict>
26 + <key>CFBundleTypeRole</key>
27 + <string>Editor</string>
28 + <key>CFBundleURLName</key>
29 + <string>y.at</string>
30 + <key>CFBundleURLSchemes</key>
31 + <array>
32 + <string>cakewallet</string>
33 + </array>
34 + </dict>
35 + <dict>
36 + <key>CFBundleTypeRole</key>
37 + <string>Editor</string>
38 + <key>CFBundleURLName</key>
39 + <string>bitcoin</string>
40 + <key>CFBundleURLSchemes</key>
41 + <array>
42 + <string>bitcoin</string>
43 + </array>
44 + </dict>
45 + <dict>
46 + <key>CFBundleTypeRole</key>
47 + <string>Editor</string>
48 + <key>CFBundleURLName</key>
49 + <string>monero</string>
50 + <key>CFBundleURLSchemes</key>
51 + <array>
52 + <string>monero</string>
53 + </array>
54 + </dict>
55 + <dict>
56 + <key>CFBundleTypeRole</key>
57 + <string>Editor</string>
58 + <key>CFBundleURLName</key>
59 + <string>litecoin</string>
60 + <key>CFBundleURLSchemes</key>
61 + <array>
62 + <string>litecoin</string>
63 + </array>
64 + </dict>
65 + </array>
66 <key>CFBundleVersion</key>
67 <string>$(CURRENT_PROJECT_VERSION)</string>
68 <key>LSRequiresIPhoneOS</key>
lib/di.dart
+2 -2
@@ -377,8 +377,8 @@ Future setup(
377 getIt.get<BalanceViewModel>(),
378 _transactionDescriptionBox));
379
380 - getIt.registerFactoryParam<SendPage, PaymentRequest, void>(
381 - (PaymentRequest initialPaymentRequest, _) => SendPage(
380 + getIt.registerFactoryParam<SendPage, PaymentRequest?, void>(
381 + (PaymentRequest? initialPaymentRequest, _) => SendPage(
382 sendViewModel: getIt.get<SendViewModel>(),
383 settingsViewModel: getIt.get<SettingsViewModel>(),
384 initialPaymentRequest: initialPaymentRequest,
lib/main.dart
+19 -10
@@ -39,6 +39,8 @@ import 'package:cw_core/unspent_coins_info.dart';
39 import 'package:cake_wallet/monero/monero.dart';
40 import 'package:cake_wallet/wallet_type_utils.dart';
41
42 +import 'src/screens/auth/auth_page.dart';
43 +
44 final navigatorKey = GlobalKey<NavigatorState>();
45 final rootKey = GlobalKey<RootState>();
46
@@ -213,15 +215,15 @@ class AppState extends State<App> with SingleTickerProviderStateMixin {
215 super.dispose();
216 }
217
216 - /// handle app links while the app is already started - be it in
217 - /// the foreground or in the background.
218 + /// handle app links while the app is already started
219 + /// whether its in the foreground or in the background.
220 Future<void> initUniLinks() async {
221 try {
220 - stream = getUriLinksStream().listen((Uri uri) {
222 + stream = uriLinkStream.listen((Uri? uri) {
223 handleDeepLinking(uri);
224 });
225
224 - final Uri initialUri = await getInitialUri();
226 + final Uri? initialUri = await getInitialUri();
227
228 handleDeepLinking(initialUri);
229 } catch (e) {
@@ -229,14 +231,21 @@ class AppState extends State<App> with SingleTickerProviderStateMixin {
231 }
232 }
233
232 - void handleDeepLinking(Uri uri) {
234 + void handleDeepLinking(Uri? uri) {
235 if (uri == null || !mounted) return;
236
235 - Navigator.pushNamed(
236 - navigatorKey.currentContext,
237 - Routes.send,
238 - arguments: PaymentRequest.fromUri(uri),
239 - );
237 + Navigator.of(navigatorKey.currentContext!).pushNamed(Routes.auth,
238 + arguments: (bool isAuthenticatedSuccessfully, AuthPageState auth) {
239 + if (isAuthenticatedSuccessfully) {
240 + auth.close(route: Routes.send, arguments: PaymentRequest.fromUri(uri));
241 + }
242 + });
243 +
244 + // Navigator.pushNamed(
245 + // navigatorKey.currentContext!,
246 + // Routes.send,
247 + // arguments: PaymentRequest.fromUri(uri),
248 + // );
249 }
250
251 Future<void> _handleInitialUri() async {
lib/router.dart
+1 -1
@@ -210,7 +210,7 @@ Route<dynamic> createRoute(RouteSettings settings) {
210 builder: (_) => getIt.get<DashboardPage>());
211
212 case Routes.send:
213 - final initialPaymentRequest = settings.arguments as PaymentRequest;
213 + final initialPaymentRequest = settings.arguments as PaymentRequest?;
214
215 return CupertinoPageRoute<void>(
216 fullscreenDialog: true, builder: (_) => getIt.get<SendPage>(
lib/src/screens/send/widgets/send_card.dart
+4 -5
@@ -1,4 +1,3 @@
1 -import 'dart:ui';
1 import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
2 import 'package:cake_wallet/utils/payment_request.dart';
3 import 'package:cw_core/transaction_priority.dart';
@@ -44,7 +43,7 @@ class SendCardState extends State<SendCard>
43 required this.output,
44 required this.sendViewModel,
45 this.initialPaymentRequest})
47 - : addressController = TextEditingController(text: initialPaymentRequest?.address?.toLowerCase()),
46 + : addressController = TextEditingController(text: initialPaymentRequest?.address.toLowerCase()),
47 cryptoAmountController = TextEditingController(text: initialPaymentRequest?.amount),
48 fiatAmountController = TextEditingController(),
49 noteController = TextEditingController(),
@@ -77,8 +76,8 @@ class SendCardState extends State<SendCard>
76
77 /// if the current wallet doesn't match the one in the qr code
78 if (initialPaymentRequest != null &&
80 - sendViewModel.walletCurrencyName != initialPaymentRequest.scheme?.toLowerCase()) {
81 - WidgetsBinding.instance?.addPostFrameCallback((timeStamp) {
79 + sendViewModel.walletCurrencyName != initialPaymentRequest!.scheme.toLowerCase()) {
80 + WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
81 showPopUp<void>(
82 context: context,
83 builder: (BuildContext context) {
@@ -544,7 +543,7 @@ class SendCardState extends State<SendCard>
543 addressController.text = output.address;
544 }
545 if (output.cryptoAmount.isNotEmpty ||
547 - sendViewModel.walletCurrencyName != initialPaymentRequest?.scheme?.toLowerCase()) {
546 + sendViewModel.walletCurrencyName != initialPaymentRequest?.scheme.toLowerCase()) {
547 cryptoAmountController.text = output.cryptoAmount;
548 }
549 fiatAmountController.text = output.fiatAmount;
lib/utils/payment_request.dart
+3 -3
@@ -1,7 +1,7 @@
1 class PaymentRequest {
2 - PaymentRequest(this.address, this.amount, this.note, {this.scheme});
2 + PaymentRequest(this.address, this.amount, this.note, this.scheme);
3
4 - factory PaymentRequest.fromUri(Uri uri) {
4 + factory PaymentRequest.fromUri(Uri? uri) {
5 var address = "";
6 var amount = "";
7 var note = "";
@@ -15,7 +15,7 @@ class PaymentRequest {
15 scheme = uri.scheme;
16 }
17
18 - return PaymentRequest(address, amount, note, scheme: scheme);
18 + return PaymentRequest(address, amount, note, scheme);
19 }
20
21 final String address;
lib/view_model/send/send_view_model.dart
+2 -2
@@ -137,7 +137,7 @@ abstract class SendViewModelBase with Store {
137 PendingTransaction? pendingTransaction;
138
139 @computed
140 - String get balance => balanceViewModel.availableBalance ?? '0.0';
140 + String get balance => balanceViewModel.availableBalance;
141
142 @computed
143 bool get isReadyForSend => _wallet.syncStatus is SyncedSyncStatus;
@@ -164,7 +164,7 @@ abstract class SendViewModelBase with Store {
164
165 WalletType get walletType => _wallet.type;
166
167 - String get walletCurrencyName => _wallet.currency.name.toLowerCase();
167 + String? get walletCurrencyName => _wallet.currency.name?.toLowerCase();
168
169 bool get hasCurrecyChanger => walletType == WalletType.haven;
170