diff --git a/lib/di.dart b/lib/di.dart index bd911335d..bc02b3466 100644 --- a/lib/di.dart +++ b/lib/di.dart @@ -5,6 +5,7 @@ import 'package:cake_wallet/ionia/ionia_anypay.dart'; import 'package:cake_wallet/ionia/ionia_category.dart'; import 'package:cake_wallet/ionia/ionia_gift_card.dart'; import 'package:cake_wallet/src/screens/ionia/cards/ionia_gift_card_detail_page.dart'; +import 'package:cake_wallet/utils/payment_request.dart'; import 'package:cake_wallet/view_model/ionia/ionia_auth_view_model.dart'; import 'package:cake_wallet/view_model/ionia/ionia_buy_card_view_model.dart'; import 'package:cake_wallet/view_model/ionia/ionia_filter_view_model.dart'; @@ -372,9 +373,12 @@ Future setup( getIt.get(), _transactionDescriptionBox)); - getIt.registerFactory( - () => SendPage(sendViewModel: getIt.get(), - settingsViewModel: getIt.get())); + getIt.registerFactoryParam( + (PaymentRequest initialPaymentRequest, _) => SendPage( + sendViewModel: getIt.get(), + settingsViewModel: getIt.get(), + initialPaymentRequest: initialPaymentRequest, + )); getIt.registerFactory(() => SendTemplatePage( sendTemplateViewModel: getIt.get())); diff --git a/lib/main.dart b/lib/main.dart index 901773072..cfd242dbf 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -5,6 +5,7 @@ import 'package:cake_wallet/buy/order.dart'; import 'package:cake_wallet/ionia/ionia_category.dart'; import 'package:cake_wallet/ionia/ionia_merchant.dart'; import 'package:cake_wallet/store/yat/yat_store.dart'; +import 'package:cake_wallet/utils/payment_request.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -216,34 +217,32 @@ class AppState extends State with SingleTickerProviderStateMixin { /// the foreground or in the background. Future initUniLinks() async { try { - stream = getLinksStream().listen((String link) { - handleDeepLinking(link); + stream = getUriLinksStream().listen((Uri uri) { + handleDeepLinking(uri); }); - final String initialLink = await getInitialLink(); + final Uri initialUri = await getInitialUri(); - handleDeepLinking(initialLink); + handleDeepLinking(initialUri); } catch (e) { print(e); } } - void handleDeepLinking(String link) async { - if (link == null || !mounted) return; + void handleDeepLinking(Uri uri) { + if (uri == null || !mounted) return; - final List urlComponents = link.split(":"); - - switch (urlComponents.first) { + switch (uri.scheme) { case "bitcoin": - print("@@@@@@@@@@@@@@@@@@@@@@@@@@"); - print("Bitcoin QR Code: \n${link}"); - break; case "litecoin": case "haven": case "monero": default: - print("@@@@@@@@@@@@@@@@@@@@@@@@@@"); - print(link); + Navigator.pushNamed( + navigatorKey.currentContext, + Routes.send, + arguments: PaymentRequest.fromUri(uri), + ); } } diff --git a/lib/router.dart b/lib/router.dart index 1a9c3c2d5..c5079f078 100644 --- a/lib/router.dart +++ b/lib/router.dart @@ -16,6 +16,7 @@ import 'package:cake_wallet/src/screens/seed/pre_seed_page.dart'; import 'package:cake_wallet/src/screens/support/support_page.dart'; import 'package:cake_wallet/src/screens/unspent_coins/unspent_coins_details_page.dart'; import 'package:cake_wallet/src/screens/unspent_coins/unspent_coins_list_page.dart'; +import 'package:cake_wallet/utils/payment_request.dart'; import 'package:cake_wallet/view_model/monero_account_list/account_list_item.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -207,8 +208,12 @@ Route createRoute(RouteSettings settings) { builder: (_) => getIt.get()); case Routes.send: + final initialPaymentRequest = settings.arguments as PaymentRequest; + return CupertinoPageRoute( - fullscreenDialog: true, builder: (_) => getIt.get()); + fullscreenDialog: true, builder: (_) => getIt.get( + param1: initialPaymentRequest, + )); case Routes.sendTemplate: return CupertinoPageRoute( diff --git a/lib/src/screens/send/send_page.dart b/lib/src/screens/send/send_page.dart index 791548f3d..64e564501 100644 --- a/lib/src/screens/send/send_page.dart +++ b/lib/src/screens/send/send_page.dart @@ -5,6 +5,7 @@ import 'package:cake_wallet/src/screens/send/widgets/send_card.dart'; import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart'; import 'package:cake_wallet/src/widgets/picker.dart'; import 'package:cake_wallet/src/widgets/template_tile.dart'; +import 'package:cake_wallet/utils/payment_request.dart'; import 'package:cake_wallet/view_model/send/output.dart'; import 'package:cake_wallet/view_model/settings/settings_view_model.dart'; import 'package:flutter/cupertino.dart'; @@ -28,13 +29,18 @@ import 'package:smooth_page_indicator/smooth_page_indicator.dart'; import 'package:cw_core/crypto_currency.dart'; class SendPage extends BasePage { - SendPage({@required this.sendViewModel,@required this.settingsViewModel }) : _formKey = GlobalKey(),fiatFromSettings = settingsViewModel.fiatCurrency; + SendPage({ + @required this.sendViewModel, + @required this.settingsViewModel, + this.initialPaymentRequest, + }) : _formKey = GlobalKey(),fiatFromSettings = settingsViewModel.fiatCurrency; final SendViewModel sendViewModel; final SettingsViewModel settingsViewModel; final GlobalKey _formKey; final controller = PageController(initialPage: 0); - final FiatCurrency fiatFromSettings ; + final FiatCurrency fiatFromSettings; + final PaymentRequest initialPaymentRequest; bool _effectsInstalled = false; @@ -116,6 +122,7 @@ class SendPage extends BasePage { key: output.key, output: output, sendViewModel: sendViewModel, + initialPaymentRequest: initialPaymentRequest, ); }); }, diff --git a/lib/src/screens/send/widgets/send_card.dart b/lib/src/screens/send/widgets/send_card.dart index 69858a3ac..27b3f49dc 100644 --- a/lib/src/screens/send/widgets/send_card.dart +++ b/lib/src/screens/send/widgets/send_card.dart @@ -19,23 +19,35 @@ import 'package:cake_wallet/generated/i18n.dart'; import 'package:cake_wallet/src/widgets/base_text_form_field.dart'; class SendCard extends StatefulWidget { - SendCard({Key key, @required this.output, @required this.sendViewModel}) : super(key: key); + SendCard({ + Key key, + @required this.output, + @required this.sendViewModel, + this.initialPaymentRequest, + }) : super(key: key); final Output output; final SendViewModel sendViewModel; + final PaymentRequest initialPaymentRequest; @override - SendCardState createState() => SendCardState( + SendCardState createState() { + return SendCardState( output: output, - sendViewModel: sendViewModel + sendViewModel: sendViewModel, + initialPaymentRequest: initialPaymentRequest, ); + } } class SendCardState extends State with AutomaticKeepAliveClientMixin { - SendCardState({@required this.output, @required this.sendViewModel}) - : addressController = TextEditingController(), - cryptoAmountController = TextEditingController(), + SendCardState({ + @required this.output, + @required this.sendViewModel, + PaymentRequest initialPaymentRequest}) + : addressController = TextEditingController(text: initialPaymentRequest?.address), + cryptoAmountController = TextEditingController(text: initialPaymentRequest?.amount), fiatAmountController = TextEditingController(), noteController = TextEditingController(), extractedAddressController = TextEditingController(), @@ -111,6 +123,11 @@ class SendCardState extends State ? sendViewModel.textValidator : sendViewModel.addressValidator; + print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); + print("444444444444444444444444444444"); + print(addressController.text); + print(cryptoAmountController.text); + return AddressTextField( focusNode: addressFocusNode, controller: addressController, @@ -509,8 +526,12 @@ class SendCardState extends State } void _setEffects(BuildContext context) { - addressController.text = output.address; - cryptoAmountController.text = output.cryptoAmount; + if (output.address.isNotEmpty) { + addressController.text = output.address; + } + if (output.cryptoAmount.isNotEmpty) { + cryptoAmountController.text = output.cryptoAmount; + } fiatAmountController.text = output.fiatAmount; noteController.text = output.note; extractedAddressController.text = output.extractedAddress;