buy warning popup refactor for desktop style/size

This commit is contained in:
julian 2023-02-02 14:07:03 -06:00
parent 80611d1a31
commit 4fbf38fd11

View file

@ -18,16 +18,28 @@ import 'package:stackwallet/widgets/desktop/secondary_button.dart';
import 'package:stackwallet/widgets/rounded_white_container.dart'; import 'package:stackwallet/widgets/rounded_white_container.dart';
import 'package:stackwallet/widgets/stack_dialog.dart'; import 'package:stackwallet/widgets/stack_dialog.dart';
class BuyWarningPopup extends StatelessWidget { class BuyWarningPopup extends StatefulWidget {
BuyWarningPopup({ const BuyWarningPopup({
Key? key, Key? key,
required this.quote, required this.quote,
this.order, this.order,
}) : super(key: key); }) : super(key: key);
final SimplexQuote quote; final SimplexQuote quote;
final SimplexOrder? order;
@override
State<BuyWarningPopup> createState() => _BuyWarningPopupState();
}
class _BuyWarningPopupState extends State<BuyWarningPopup> {
late final bool isDesktop;
SimplexOrder? order; SimplexOrder? order;
String get title => "Buy ${widget.quote.crypto.ticker}";
String get message =>
"This purchase is provided and fulfilled by Simplex by nuvei "
"(a third party). You will be taken to their website. Please follow "
"their instructions.";
Future<BuyResponse<SimplexOrder>> newOrder(SimplexQuote quote) async { Future<BuyResponse<SimplexOrder>> newOrder(SimplexQuote quote) async {
final orderResponse = await SimplexAPI.instance.newOrder(quote); final orderResponse = await SimplexAPI.instance.newOrder(quote);
@ -38,10 +50,6 @@ class BuyWarningPopup extends StatelessWidget {
return SimplexAPI.instance.redirect(order); return SimplexAPI.instance.redirect(order);
} }
@override
Widget build(BuildContext context) {
final isDesktop = Util.isDesktop;
Future<void> _buyInvoice() async { Future<void> _buyInvoice() async {
await showDialog<void>( await showDialog<void>(
context: context, context: context,
@ -98,26 +106,16 @@ class BuyWarningPopup extends StatelessWidget {
: BuyOrderDetailsView( : BuyOrderDetailsView(
order: order as SimplexOrder, order: order as SimplexOrder,
); );
}); },
);
} }
return StackDialog( Future<void> onContinue() async {
title: "Buy ${quote.crypto.ticker}", BuyResponse<SimplexOrder> orderResponse = await newOrder(widget.quote);
message: "This purchase is provided and fulfilled by Simplex by nuvei "
"(a third party). You will be taken to their website. Please follow "
"their instructions.",
leftButton: SecondaryButton(
label: "Cancel",
onPressed: Navigator.of(context, rootNavigator: isDesktop).pop,
),
rightButton: PrimaryButton(
label: "Continue",
onPressed: () async {
BuyResponse<SimplexOrder> orderResponse = await newOrder(quote);
if (orderResponse.exception == null) { if (orderResponse.exception == null) {
await redirect(orderResponse.value as SimplexOrder) await redirect(orderResponse.value as SimplexOrder)
.then((_response) async { .then((_response) async {
this.order = orderResponse.value as SimplexOrder; order = orderResponse.value as SimplexOrder;
Navigator.of(context, rootNavigator: isDesktop).pop(); Navigator.of(context, rootNavigator: isDesktop).pop();
Navigator.of(context, rootNavigator: isDesktop).pop(); Navigator.of(context, rootNavigator: isDesktop).pop();
await _buyInvoice(); await _buyInvoice();
@ -197,7 +195,87 @@ class BuyWarningPopup extends StatelessWidget {
}, },
); );
} }
}, }
@override
void initState() {
order = widget.order;
isDesktop = Util.isDesktop;
super.initState();
}
@override
Widget build(BuildContext context) {
if (isDesktop) {
return DesktopDialog(
maxWidth: 580,
maxHeight: 350,
child: Padding(
padding: const EdgeInsets.all(32),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
title,
style: STextStyles.desktopH3(context),
),
SizedBox(
width: 64,
height: 32,
child: SvgPicture.asset(
Assets.buy.simplexLogo(context),
),
),
],
),
const Spacer(),
Text(
message,
style: STextStyles.desktopTextSmall(context),
),
const Spacer(
flex: 2,
),
Row(
children: [
Expanded(
child: SecondaryButton(
label: "Cancel",
buttonHeight: ButtonHeight.l,
onPressed:
Navigator.of(context, rootNavigator: isDesktop).pop,
),
),
const SizedBox(
width: 16,
),
Expanded(
child: PrimaryButton(
buttonHeight: ButtonHeight.l,
label: "Continue",
onPressed: onContinue,
),
),
],
)
],
),
),
);
} else {
return StackDialog(
title: title,
message: message,
leftButton: SecondaryButton(
label: "Cancel",
onPressed: Navigator.of(context, rootNavigator: isDesktop).pop,
),
rightButton: PrimaryButton(
label: "Continue",
onPressed: onContinue,
), ),
icon: SizedBox( icon: SizedBox(
width: 64, width: 64,
@ -208,4 +286,5 @@ class BuyWarningPopup extends StatelessWidget {
), ),
); );
} }
}
} }