diff --git a/lib/pages/buy_view/buy_order_invoice.dart b/lib/pages/buy_view/buy_order_invoice.dart new file mode 100644 index 000000000..66be608bf --- /dev/null +++ b/lib/pages/buy_view/buy_order_invoice.dart @@ -0,0 +1,267 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_svg/svg.dart'; +import 'package:stackwallet/models/buy/response_objects/order.dart'; +import 'package:stackwallet/utilities/assets.dart'; +import 'package:stackwallet/utilities/text_styles.dart'; +import 'package:stackwallet/utilities/theme/stack_colors.dart'; +import 'package:stackwallet/utilities/util.dart'; +import 'package:stackwallet/widgets/background.dart'; +import 'package:stackwallet/widgets/conditional_parent.dart'; +import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart'; +import 'package:stackwallet/widgets/desktop/primary_button.dart'; +import 'package:stackwallet/widgets/rounded_white_container.dart'; + +class BuyOrderInvoiceView extends StatefulWidget { + const BuyOrderInvoiceView({ + Key? key, + required this.order, + }) : super(key: key); + + final SimplexOrder order; + + static const String routeName = "/buyOrderInvoice"; + + @override + State createState() => _BuyOrderInvoiceViewState(); +} + +class _BuyOrderInvoiceViewState extends State { + final isDesktop = Util.isDesktop; + + @override + Widget build(BuildContext context) { + return ConditionalParent( + condition: !isDesktop, + builder: (child) { + return Background( + child: Scaffold( + backgroundColor: + Theme.of(context).extension()!.background, + appBar: AppBar( + backgroundColor: + Theme.of(context).extension()!.backgroundAppBar, + leading: const AppBarBackButton(), + title: Text( + "Order invoice", + style: STextStyles.navBarTitle(context), + ), + ), + body: LayoutBuilder( + builder: (builderContext, constraints) { + return Padding( + padding: const EdgeInsets.only( + left: 12, + top: 12, + right: 12, + ), + child: SingleChildScrollView( + child: ConstrainedBox( + constraints: BoxConstraints( + minHeight: constraints.maxHeight - 24, + ), + child: IntrinsicHeight( + child: Padding( + padding: const EdgeInsets.all(4), + child: child, + ), + ), + ), + ), + ); + }, + ), + ), + ); + }, + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + Text( + "Simplex Order", + style: STextStyles.pageTitleH1(context), + ), + const SizedBox( + height: 16, + ), + RoundedWhiteContainer( + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + "Quoted cost", + style: STextStyles.label(context), + ), + Text( + "${widget.order.quote.youPayFiatPrice.toStringAsFixed(2)} ${widget.order.quote.fiat.ticker.toUpperCase()}", + style: STextStyles.label(context).copyWith( + color: Theme.of(context).extension()!.textDark, + ), + ), + ], + ), + ), + const SizedBox( + height: 8, + ), + // RoundedWhiteContainer( + // child: Row( + // mainAxisAlignment: MainAxisAlignment.spaceBetween, + // children: [ + // Text( + // "You pay with", + // style: STextStyles.label(context), + // ), + // Text( + // widget.quote.fiat.name, + // style: STextStyles.label(context).copyWith( + // color: Theme.of(context).extension()!.textDark, + // ), + // ), + // ], + // ), + // ), + // const SizedBox( + // height: 8, + // ), + RoundedWhiteContainer( + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + "Quoted amount", + style: STextStyles.label(context), + ), + Text( + "${widget.order.quote.youReceiveCryptoAmount} ${widget.order.quote.crypto.ticker.toUpperCase()}", + style: STextStyles.label(context).copyWith( + color: Theme.of(context).extension()!.textDark, + ), + ), + ], + ), + ), + const SizedBox( + height: 8, + ), + RoundedWhiteContainer( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + "Receiving ${widget.order.quote.crypto.ticker.toUpperCase()} address", + style: STextStyles.label(context), + ), + Text( + "${widget.order.quote.receivingAddress} ", + style: STextStyles.label(context).copyWith( + color: Theme.of(context).extension()!.textDark, + ), + ), + ], + ), + ), + const SizedBox( + height: 8, + ), + RoundedWhiteContainer( + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + "Quote ID", + style: STextStyles.label(context), + ), + Text( + widget.order.quote.id, + style: STextStyles.label(context).copyWith( + color: Theme.of(context).extension()!.textDark, + ), + ), + ], + ), + ), + const SizedBox( + height: 8, + ), + RoundedWhiteContainer( + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + "Purchase ID", + style: STextStyles.label(context), + ), + Text( + widget.order.paymentId, + style: STextStyles.label(context).copyWith( + color: Theme.of(context).extension()!.textDark, + ), + ), + ], + ), + ), + const SizedBox( + height: 8, + ), + RoundedWhiteContainer( + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + "User ID", + style: STextStyles.label(context), + ), + Text( + widget.order.userId, + style: STextStyles.label(context).copyWith( + color: Theme.of(context).extension()!.textDark, + ), + ), + ], + ), + ), + const SizedBox( + height: 8, + ), + RoundedWhiteContainer( + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + "Provider", + style: STextStyles.label(context), + ), + SizedBox( + width: 64, + height: 32, + child: SvgPicture.asset( + Assets.buy.simplexLogo(context), + ), + ), + ], + ), + ), + const SizedBox( + height: 24, + ), + Row(mainAxisAlignment: MainAxisAlignment.center, children: [ + Text( + "This information is not saved,\nscreenshot it now for your records", + style: STextStyles.label(context).copyWith( + color: Theme.of(context).extension()!.textDark, + ), + textAlign: TextAlign.center, + ), + ]), + const Spacer(), + PrimaryButton( + label: "Dismiss", + onPressed: () { + Navigator.of(context, rootNavigator: isDesktop).pop(); + }, + ) + ], + ), + ); + } +} diff --git a/lib/pages/buy_view/sub_widgets/buy_warning_popup.dart b/lib/pages/buy_view/sub_widgets/buy_warning_popup.dart index 693c12ce8..069a93572 100644 --- a/lib/pages/buy_view/sub_widgets/buy_warning_popup.dart +++ b/lib/pages/buy_view/sub_widgets/buy_warning_popup.dart @@ -1,10 +1,10 @@ import 'dart:async'; -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_svg/svg.dart'; import 'package:stackwallet/models/buy/response_objects/order.dart'; import 'package:stackwallet/models/buy/response_objects/quote.dart'; +import 'package:stackwallet/pages/buy_view/buy_order_invoice.dart'; import 'package:stackwallet/services/buy/buy_response.dart'; import 'package:stackwallet/services/buy/simplex/simplex_api.dart'; import 'package:stackwallet/utilities/assets.dart'; @@ -14,12 +14,14 @@ import 'package:stackwallet/widgets/desktop/secondary_button.dart'; import 'package:stackwallet/widgets/stack_dialog.dart'; class BuyWarningPopup extends StatelessWidget { - const BuyWarningPopup({ + BuyWarningPopup({ Key? key, required this.quote, + this.order, }) : super(key: key); final SimplexQuote quote; + SimplexOrder? order; Future> newOrder(SimplexQuote quote) async { return SimplexAPI.instance.newOrder(quote); @@ -33,6 +35,15 @@ class BuyWarningPopup extends StatelessWidget { Widget build(BuildContext context) { final isDesktop = Util.isDesktop; + Future _buyInvoice() async { + await showDialog( + context: context, + builder: (context) => BuyOrderInvoiceView( + order: order as SimplexOrder, + ), + ); + } + return StackDialog( title: "Buy ${quote.crypto.ticker}", message: "This purchase is provided and fulfilled by Simplex by nuvei " @@ -46,15 +57,19 @@ class BuyWarningPopup extends StatelessWidget { label: "Continue", onPressed: () async { BuyResponse order = await newOrder(quote); - BuyResponse response = - await redirect(order.value as SimplexOrder).then((order) { + await redirect(order.value as SimplexOrder).then((_response) async { + this.order = order.value as SimplexOrder; Navigator.of(context, rootNavigator: isDesktop).pop(); Navigator.of(context, rootNavigator: isDesktop).pop(); - // How would I correctly popUntil here? - // TODO save order - // TODO show order confirmation page - return order; + await _buyInvoice(); }); + // BuyResponse response = + // await redirect(order.value as SimplexOrder).then((order) { + // // How would I correctly popUntil here? + // // TODO save order + // // TODO show order confirmation page + // return order; + // }); }, ), icon: SizedBox(