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,174 +50,241 @@ class BuyWarningPopup extends StatelessWidget {
return SimplexAPI.instance.redirect(order); return SimplexAPI.instance.redirect(order);
} }
@override Future<void> _buyInvoice() async {
Widget build(BuildContext context) { await showDialog<void>(
final isDesktop = Util.isDesktop; context: context,
// useRootNavigator: isDesktop,
Future<void> _buyInvoice() async { builder: (context) {
await showDialog<void>( return isDesktop
context: context, ? DesktopDialog(
// useRootNavigator: isDesktop, maxHeight: 700,
builder: (context) { maxWidth: 580,
return isDesktop child: Column(
? DesktopDialog( children: [
maxHeight: 700, Row(
maxWidth: 580, mainAxisAlignment: MainAxisAlignment.spaceBetween,
child: Column(
children: [ children: [
Row( Padding(
mainAxisAlignment: MainAxisAlignment.spaceBetween, padding: const EdgeInsets.only(
left: 32,
),
child: Text(
"Order details",
style: STextStyles.desktopH3(context),
),
),
const DesktopDialogCloseButton(),
],
),
Expanded(
child: Padding(
padding: const EdgeInsets.only(
left: 32,
right: 32,
bottom: 32,
),
child: Row(
children: [ children: [
Padding( Expanded(
padding: const EdgeInsets.only( child: RoundedWhiteContainer(
left: 32, padding: const EdgeInsets.all(16),
), borderColor: Theme.of(context)
child: Text( .extension<StackColors>()!
"Order details", .background,
style: STextStyles.desktopH3(context), child: BuyOrderDetailsView(
order: order as SimplexOrder,
),
), ),
), ),
const DesktopDialogCloseButton(),
], ],
), ),
),
),
],
),
)
: BuyOrderDetailsView(
order: order as SimplexOrder,
);
},
);
}
Future<void> onContinue() async {
BuyResponse<SimplexOrder> orderResponse = await newOrder(widget.quote);
if (orderResponse.exception == null) {
await redirect(orderResponse.value as SimplexOrder)
.then((_response) async {
order = orderResponse.value as SimplexOrder;
Navigator.of(context, rootNavigator: isDesktop).pop();
Navigator.of(context, rootNavigator: isDesktop).pop();
await _buyInvoice();
});
} else {
await showDialog<dynamic>(
context: context,
barrierDismissible: true,
builder: (context) {
if (isDesktop) {
return DesktopDialog(
maxWidth: 450,
child: Padding(
padding: const EdgeInsets.all(32),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Simplex API error",
style: STextStyles.desktopH3(context),
),
const SizedBox(
height: 24,
),
Text(
"${orderResponse.exception?.errorMessage}",
style: STextStyles.smallMed14(context),
),
const SizedBox(
height: 56,
),
Row(
children: [
const Spacer(),
Expanded( Expanded(
child: Padding( child: PrimaryButton(
padding: const EdgeInsets.only( buttonHeight: ButtonHeight.l,
left: 32, label: "Ok",
right: 32, onPressed: () {
bottom: 32, Navigator.of(context).pop();
), Navigator.of(context).pop();
child: Row( Navigator.of(context).pop(); // weee
children: [ },
Expanded(
child: RoundedWhiteContainer(
padding: const EdgeInsets.all(16),
borderColor: Theme.of(context)
.extension<StackColors>()!
.background,
child: BuyOrderDetailsView(
order: order as SimplexOrder,
),
),
),
],
),
), ),
), ),
], ],
), )
) ],
: BuyOrderDetailsView( ),
order: order as SimplexOrder, ),
); );
});
}
return StackDialog(
title: "Buy ${quote.crypto.ticker}",
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) {
await redirect(orderResponse.value as SimplexOrder)
.then((_response) async {
this.order = orderResponse.value as SimplexOrder;
Navigator.of(context, rootNavigator: isDesktop).pop();
Navigator.of(context, rootNavigator: isDesktop).pop();
await _buyInvoice();
});
} else { } else {
await showDialog<dynamic>( return StackDialog(
context: context, title: "Simplex API error",
barrierDismissible: true, message: "${orderResponse.exception?.errorMessage}",
builder: (context) { // "${quoteResponse.exception?.errorMessage.substring(8, (quoteResponse.exception?.errorMessage?.length ?? 109) - (8 + 6))}",
if (isDesktop) { rightButton: TextButton(
return DesktopDialog( style: Theme.of(context)
maxWidth: 450, .extension<StackColors>()!
child: Padding( .getSecondaryEnabledButtonStyle(context),
padding: const EdgeInsets.all(32), child: Text(
child: Column( "Ok",
mainAxisSize: MainAxisSize.min, style: STextStyles.button(context).copyWith(
crossAxisAlignment: CrossAxisAlignment.start, color: Theme.of(context)
children: [
Text(
"Simplex API error",
style: STextStyles.desktopH3(context),
),
const SizedBox(
height: 24,
),
Text(
"${orderResponse.exception?.errorMessage}",
style: STextStyles.smallMed14(context),
),
const SizedBox(
height: 56,
),
Row(
children: [
const Spacer(),
Expanded(
child: PrimaryButton(
buttonHeight: ButtonHeight.l,
label: "Ok",
onPressed: () {
Navigator.of(context).pop();
Navigator.of(context).pop();
Navigator.of(context).pop(); // weee
},
),
),
],
)
],
),
),
);
} else {
return StackDialog(
title: "Simplex API error",
message: "${orderResponse.exception?.errorMessage}",
// "${quoteResponse.exception?.errorMessage.substring(8, (quoteResponse.exception?.errorMessage?.length ?? 109) - (8 + 6))}",
rightButton: TextButton(
style: Theme.of(context)
.extension<StackColors>()! .extension<StackColors>()!
.getSecondaryEnabledButtonStyle(context), .accentColorDark),
child: Text( ),
"Ok", onPressed: () {
style: STextStyles.button(context).copyWith( Navigator.of(context).pop();
color: Theme.of(context) Navigator.of(context).pop();
.extension<StackColors>()! Navigator.of(context).pop(); // weee
.accentColorDark), },
), ),
onPressed: () {
Navigator.of(context).pop();
Navigator.of(context).pop();
Navigator.of(context).pop(); // weee
},
),
);
}
},
); );
} }
}, },
), );
icon: SizedBox( }
width: 64, }
height: 32,
child: SvgPicture.asset( @override
Assets.buy.simplexLogo(context), 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(
width: 64,
height: 32,
child: SvgPicture.asset(
Assets.buy.simplexLogo(context),
),
),
);
}
} }
} }