feat(cakepay): add CakePay mobile and desktop UI pages
What changed, and why it matters
This commit adds new user-interface screens for buying gift cards through a third-party service called CakePay inside the Stack Wallet app. It lets users browse cards, enter an email, agree to terms, create an order, choose a cryptocurrency to pay with, and send the payment from one of their wallets. The changes are mostly UI wiring; they do not obviously fix or introduce a security vulnerability on their own, but they do handle money, email addresses, and external web links, so the implementation quality matters.
Treat this as a feature commit requiring security review of the full CakePay integration, not as a confirmed vulnerability. Review the CakePayService client for TLS/certificate pinning, API authentication, response validation, and tamper resistance. Verify that ticker resolution (especially BTC_LN and LTC_MWEB fallbacks) cannot route payments to unintended wallet types. Confirm order ID storage is encrypted at rest. Ensure the terms URL cannot be manipulated and that email/amount fields are validated server-side. Consider adding a second email confirmation field as the commit message suggests.
Security signals we found
New payment flow sends user funds to addresses supplied by a third-party API (CakePay)
External URL launched via url_launcher after a user-facing confirmation dialog (cakepay.com/terms)
Email address collected and passed to third-party API in createOrder
Order IDs stored locally and fetched individually to avoid Knox user auth requirement
API ticker resolution falls back to base ticker before underscore, which could map a variant to a different wallet type
No input validation visible for custom amount beyond parse/min/max checks
Terms acceptance checkbox is UI-only; purchase call hard-codes confirmsTermsAgreed=true, confirmsNoVpn=true, confirmsVoidedRefund=true
Evidence from the diff
A large feature commit introducing six new CakePay-related Flutter views (vendors, card detail, order, orders list, send-from, confirm-send) and updating wallet/routing plumbing. Key behaviors: fetches vendor/card/order data via CakePayService; stores order IDs locally so the orders list can call getOrder() without user auth; resolves API tickers like BTC_LN/LTC_MWEB to Stack Wallet coins; builds a TxData recipient and prepares/confirms a wallet send; opens https://cakepay.com/terms/ in an external browser after a confirmation dialog; and deduplicates country codes for a dropdown. No explicit security bug is visible in the diff, but the code touches payment flow, external URL launching, email input, clipboard, and third-party API integration.
Changed components
lib/pages/cakepay/cakepay_card_detail_view.dartlib/pages/cakepay/cakepay_confirm_send_view.dartlib/pages/cakepay/cakepay_order_view.dartlib/pages/cakepay/cakepay_orders_view.dartlib/pages/cakepay/cakepay_send_from_view.dartlib/pages/cakepay/cakepay_vendors_view.dartlib/pages/wallet_view/wallet_view.dartlib/route_generator.dartInspect captured patch +3561 / −1
diff --git a/lib/pages/cakepay/cakepay_card_detail_view.dart b/lib/pages/cakepay/cakepay_card_detail_view.dart
new file mode 100644
index 0000000..bd061b4
--- /dev/null
+++ b/lib/pages/cakepay/cakepay_card_detail_view.dart
@@ -0,0 +1,697 @@
+import 'package:flutter/gestures.dart';
+import 'package:flutter/material.dart';
+import 'package:url_launcher/url_launcher.dart';
+
+import '../../services/cakepay/cakepay_service.dart';
+import '../../services/cakepay/src/models/card.dart';
+import '../../themes/stack_colors.dart';
+import '../../utilities/constants.dart';
+import '../../utilities/text_styles.dart';
+import '../../utilities/util.dart';
+import '../../widgets/background.dart';
+import '../../widgets/conditional_parent.dart';
+import '../../widgets/custom_buttons/app_bar_icon_button.dart';
+import '../../widgets/desktop/desktop_dialog.dart';
+import '../../widgets/desktop/desktop_dialog_close_button.dart';
+import '../../widgets/desktop/primary_button.dart';
+import '../../widgets/desktop/secondary_button.dart';
+import '../../widgets/rounded_white_container.dart';
+import '../../widgets/stack_dialog.dart';
+import '../../widgets/stack_text_field.dart';
+import 'cakepay_order_view.dart';
+
+class CakePayCardDetailView extends StatefulWidget {
+ const CakePayCardDetailView({super.key, required this.cardId});
+
+ static const String routeName = "/cakePayCardDetail";
+
+ final int cardId;
+
+ @override
+ State<CakePayCardDetailView> createState() => _CakePayCardDetailViewState();
+}
+
+class _CakePayCardDetailViewState extends State<CakePayCardDetailView> {
+ CakePayCard? _card;
+ bool _loading = true;
+ bool _purchasing = false;
+ double? _selectedDenomination;
+ int _quantity = 1;
+ bool _termsAccepted = false;
+ final _customAmountController = TextEditingController();
+ final _customAmountFocusNode = FocusNode();
+ final _emailController = TextEditingController();
+ final _emailFocusNode = FocusNode();
+
+ @override
+ void initState() {
+ super.initState();
+ _emailFocusNode.addListener(() {
+ setState(() {});
+ });
+ _loadCard();
+ }
+
+ @override
+ void dispose() {
+ _customAmountController.dispose();
+ _customAmountFocusNode.dispose();
+ _emailController.dispose();
+ _emailFocusNode.dispose();
+ super.dispose();
+ }
+
+ Future<void> _loadCard() async {
+ final resp = await CakePayService.instance.client.getCard(widget.cardId);
+ if (mounted) {
+ setState(() {
+ _loading = false;
+ if (!resp.hasError && resp.value != null) {
+ _card = resp.value;
+ if (_card!.isFixedDenomination && _card!.denominations.isNotEmpty) {
+ _selectedDenomination = _card!.denominations.first;
+ }
+ }
+ });
+ }
+ }
+
+ String get _priceString {
+ if (_card == null) return '';
+ if (_card!.isFixedDenomination && _selectedDenomination != null) {
+ return _selectedDenomination!.toStringAsFixed(2);
+ }
+ return _customAmountController.text.trim();
+ }
+
+ bool get _canPurchase {
+ if (_card == null || !_termsAccepted || _purchasing) return false;
+ if (_emailController.text.trim().isEmpty) return false;
+ final price = _priceString;
+ if (price.isEmpty) return false;
+ final parsed = double.tryParse(price);
+ if (parsed == null || parsed <= 0) return false;
+ if (_card!.isRangeDenomination) {
+ if (_card!.minValue != null && parsed < _card!.minValue!) return false;
+ if (_card!.maxValue != null && parsed > _card!.maxValue!) return false;
+ }
+ return true;
+ }
+
+ Future<bool> _showOpenBrowserWarning(String url) async {
+ final uri = Uri.parse(url);
+ final shouldContinue = await showDialog<bool>(
+ context: context,
+ barrierDismissible: false,
+ builder: (_) => Util.isDesktop
+ ? DesktopDialog(
+ maxWidth: 550,
+ maxHeight: 250,
+ child: Padding(
+ padding: const EdgeInsets.symmetric(
+ horizontal: 32,
+ vertical: 20,
+ ),
+ child: Column(
+ children: [
+ Text(
+ "Attention",
+ style: STextStyles.desktopH2(context),
+ ),
+ const SizedBox(height: 16),
+ Text(
+ "You are about to open "
+ "${uri.scheme}://${uri.host} "
+ "in your browser.",
+ style: STextStyles.desktopTextSmall(
+ context,
+ ),
+ ),
+ const SizedBox(height: 35),
+ Row(
+ mainAxisAlignment:
+ MainAxisAlignment.center,
+ children: [
+ SecondaryButton(
+ width: 200,
+ buttonHeight: ButtonHeight.l,
+ label: "Cancel",
+ onPressed: () {
+ Navigator.of(
+ context,
+ rootNavigator: true,
+ ).pop(false);
+ },
+ ),
+ const SizedBox(width: 20),
+ PrimaryButton(
+ width: 200,
+ buttonHeight: ButtonHeight.l,
+ label: "Continue",
+ onPressed: () {
+ Navigator.of(
+ context,
+ rootNavigator: true,
+ ).pop(true);
+ },
+ ),
+ ],
+ ),
+ ],
+ ),
+ ),
+ )
+ : StackDialog(
+ title: "Attention",
+ message:
+ "You are about to open "
+ "${uri.scheme}://${uri.host} "
+ "in your browser.",
+ leftButton: TextButton(
+ onPressed: () {
+ Navigator.of(context).pop(false);
+ },
+ child: Text(
+ "Cancel",
+ style: STextStyles.button(context).copyWith(
+ color: Theme.of(context)
+ .extension<StackColors>()!
+ .accentColorDark,
+ ),
+ ),
+ ),
+ rightButton: TextButton(
+ style: Theme.of(context)
+ .extension<StackColors>()!
+ .getPrimaryEnabledButtonStyle(context),
+ onPressed: () {
+ Navigator.of(context).pop(true);
+ },
+ child: Text(
+ "Continue",
+ style: STextStyles.button(context),
+ ),
+ ),
+ ),
+ );
+ return shouldContinue ?? false;
+ }
+
+ Future<void> _openTerms() async {
+ const url = "https://cakepay.com/terms/";
+ if (await _showOpenBrowserWarning(url)) {
+ await launchUrl(
+ Uri.parse(url),
+ mode: LaunchMode.externalApplication,
+ );
+ }
+ }
+
+ Future<void> _purchase() async {
+ if (!_canPurchase) return;
+ setState(() => _purchasing = true);
+
+ final resp = await CakePayService.instance.client.createOrder(
+ cardId: _card!.id,
+ price: _priceString,
+ quantity: _quantity > 1 ? _quantity : null,
+ userEmail: _emailController.text.trim(),
+ confirmsNoVpn: true,
+ confirmsVoidedRefund: true,
+ confirmsTermsAgreed: true,
+ );
+
+ if (mounted) {
+ setState(() => _purchasing = false);
+ if (!resp.hasError && resp.value != null) {
+ final order = resp.value!;
+
+ // Track order ID locally so the orders list view can fetch it
+ // via getOrder() without requiring Knox user auth.
+ CakePayService.instance.addOrderId(order.orderId);
+
+ if (Util.isDesktop) {
+ Navigator.of(context, rootNavigator: true).pop();
+ await showDialog<void>(
+ context: context,
+ builder: (_) => CakePayOrderView(orderId: order.orderId),
+ );
+ } else {
+ await Navigator.of(context).pushReplacementNamed(
+ CakePayOrderView.routeName,
+ arguments: order.orderId,
+ );
+ }
+ } else {
+ await showDialog<dynamic>(
+ context: context,
+ useSafeArea: false,
+ barrierDismissible: true,
+ builder: (context) {
+ return StackDialog(
+ title: "Purchase failed",
+ message: resp.exception?.message ?? "Failed to create order",
+ rightButton: TextButton(
+ style: Theme.of(context)
+ .extension<StackColors>()!
+ .getSecondaryEnabledButtonStyle(context),
+ child: Text(
+ "Ok",
+ style: STextStyles.button(context).copyWith(
+ color: Theme.of(
+ context,
+ ).extension<StackColors>()!.buttonTextSecondary,
+ ),
+ ),
+ onPressed: () => Navigator.of(context).pop(),
+ ),
+ );
+ },
+ );
+ }
+ }
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final isDesktop = Util.isDesktop;
+
+ if (_loading) {
+ return _scaffold(
+ isDesktop: isDesktop,
+ child: const Center(
+ child: SizedBox(
+ width: 24,
+ height: 24,
+ child: CircularProgressIndicator(strokeWidth: 2),
+ ),
+ ),
+ );
+ }
+
+ if (_card == null) {
+ return _scaffold(
+ isDesktop: isDesktop,
+ child: Center(
+ child: Text(
+ "Failed to load card",
+ style: isDesktop
+ ? STextStyles.desktopTextSmall(context)
+ : STextStyles.itemSubtitle(context),
+ ),
+ ),
+ );
+ }
+
+ final card = _card!;
+
+ final denominationSelector = card.isFixedDenomination
+ ? Wrap(
+ spacing: 8,
+ runSpacing: 8,
+ children: card.denominations.map((d) {
+ final selected = d == _selectedDenomination;
+ return ChoiceChip(
+ label: Text(
+ "${d.toStringAsFixed(0)} ${card.currencyCode ?? ''}",
+ style:
+ (isDesktop
+ ? STextStyles.desktopTextExtraExtraSmall(context)
+ : STextStyles.itemSubtitle12(context))
+ .copyWith(
+ color: selected
+ ? Theme.of(
+ context,
+ ).extension<StackColors>()!.textDark
+ : null,
+ ),
+ ),
+ selected: selected,
+ onSelected: (val) {
+ if (val) setState(() => _selectedDenomination = d);
+ },
+ );
+ }).toList(),
+ )
+ : card.isRangeDenomination
+ ? Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ "Enter amount (${card.minValue?.toStringAsFixed(0) ?? '?'} - "
+ "${card.maxValue?.toStringAsFixed(0) ?? '?'} "
+ "${card.currencyCode ?? ''})",
+ style: isDesktop
+ ? STextStyles.desktopTextExtraExtraSmall(context)
+ : STextStyles.itemSubtitle12(context),
+ ),
+ const SizedBox(height: 8),
+ ClipRRect(
+ borderRadius: BorderRadius.circular(
+ Constants.size.circularBorderRadius,
+ ),
+ child: TextField(
+ controller: _customAmountController,
+ focusNode: _customAmountFocusNode,
+ keyboardType: const TextInputType.numberWithOptions(
+ decimal: true,
+ ),
+ onChanged: (_) => setState(() {}),
+ style: isDesktop
+ ? STextStyles.desktopTextExtraSmall(context)
+ .copyWith(
+ color: Theme.of(context)
+ .extension<StackColors>()!
+ .textFieldActiveText,
+ height: 1.8,
+ )
+ : STextStyles.field(context).copyWith(
+ color: Theme.of(context)
+ .extension<StackColors>()!
+ .textFieldActiveText,
+ ),
+ decoration: standardInputDecoration(
+ "Amount",
+ _customAmountFocusNode,
+ context,
+ desktopMed: isDesktop,
+ ).copyWith(
+ filled: true,
+ contentPadding: const EdgeInsets.symmetric(
+ horizontal: 16,
+ vertical: 12,
+ ),
+ ),
+ ),
+ ),
+ ],
+ )
+ : const SizedBox.shrink();
+
+ final quantityRow = Row(
+ children: [
+ Text(
+ "Quantity",
+ style: isDesktop
+ ? STextStyles.desktopTextExtraExtraSmall(context)
+ : STextStyles.itemSubtitle12(context),
+ ),
+ const Spacer(),
+ IconButton(
+ icon: const Icon(Icons.remove_circle_outline, size: 20),
+ onPressed: _quantity > 1 ? () => setState(() => _quantity--) : null,
+ ),
+ Text(
+ "$_quantity",
+ style: isDesktop
+ ? STextStyles.desktopTextSmall(context)
+ : STextStyles.titleBold12(context),
+ ),
+ IconButton(
+ icon: const Icon(Icons.add_circle_outline, size: 20),
+ onPressed: () => setState(() => _quantity++),
+ ),
+ ],
+ );
+
+ final termsCheckbox = GestureDetector(
+ onTap: () => setState(() => _termsAccepted = !_termsAccepted),
+ child: Container(
+ color: Colors.transparent,
+ child: Row(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ SizedBox(
+ width: 20,
+ height: 26,
+ child: IgnorePointer(
+ child: Checkbox(
+ materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
+ value: _termsAccepted,
+ onChanged: (_) {},
+ ),
+ ),
+ ),
+ const SizedBox(width: 12),
+ Expanded(
+ child: RichText(
+ text: TextSpan(
+ style: isDesktop
+ ? STextStyles.desktopTextExtraExtraSmall(
+ context,
+ )
+ : STextStyles.w500_14(context),
+ children: [
+ const TextSpan(text: "I agree to the "),
+ TextSpan(
+ text: "terms and conditions",
+ style: STextStyles.richLink(context)
+ .copyWith(
+ fontSize: isDesktop ? null : 14,
+ ),
+ recognizer: TapGestureRecognizer()
+ ..onTap = _openTerms,
+ ),
+ const TextSpan(
+ text: ", confirm I am not using a VPN, "
+ "and understand refunds are voided. "
+ "I understand that the gift card "
+ "will be delivered to the listed "
+ "email.",
+ ),
+ ],
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ );
+
+ final content = SingleChildScrollView(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ if (card.cardImageUrl != null)
+ Center(
+ child: ClipRRect(
+ borderRadius: BorderRadius.circular(8),
+ child: Image.network(
+ card.cardImageUrl!,
+ width: isDesktop ? 200 : 150,
+ fit: BoxFit.contain,
+ errorBuilder: (_, __, ___) =>
+ Icon(Icons.card_giftcard, size: isDesktop ? 80 : 60),
+ ),
+ ),
+ ),
+ SizedBox(height: isDesktop ? 16 : 12),
+ Text(
+ card.name,
+ style: isDesktop
+ ? STextStyles.desktopH2(context)
+ : STextStyles.pageTitleH1(context),
+ ),
+ if (card.description != null && card.description!.isNotEmpty) ...[
+ SizedBox(height: isDesktop ? 16 : 12),
+ RoundedWhiteContainer(
+ child: Text(
+ card.description!,
+ style: isDesktop
+ ? STextStyles.desktopTextExtraExtraSmall(context)
+ : STextStyles.itemSubtitle12(context),
+ ),
+ ),
+ ],
+ if (card.howToUse != null && card.howToUse!.isNotEmpty) ...[
+ SizedBox(height: isDesktop ? 16 : 12),
+ RoundedWhiteContainer(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ "How to use",
+ style: isDesktop
+ ? STextStyles.desktopTextSmall(context)
+ : STextStyles.titleBold12(context),
+ ),
+ const SizedBox(height: 8),
+ Text(
+ card.howToUse!,
+ style: isDesktop
+ ? STextStyles.desktopTextExtraExtraSmall(context)
+ : STextStyles.itemSubtitle12(context),
+ ),
+ ],
+ ),
+ ),
+ ],
+ if (card.termsAndConditions != null &&
+ card.termsAndConditions!.isNotEmpty) ...[
+ SizedBox(height: isDesktop ? 16 : 12),
+ RoundedWhiteContainer(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ "Terms & conditions",
+ style: isDesktop
+ ? STextStyles.desktopTextSmall(context)
+ : STextStyles.titleBold12(context),
+ ),
+ const SizedBox(height: 8),
+ Text(
+ card.termsAndConditions!,
+ style: isDesktop
+ ? STextStyles.desktopTextExtraExtraSmall(context)
+ : STextStyles.itemSubtitle12(context),
+ ),
+ ],
+ ),
+ ),
+ ],
+ if (card.expiryAndValidity != null &&
+ card.expiryAndValidity!.isNotEmpty) ...[
+ SizedBox(height: isDesktop ? 16 : 12),
+ RoundedWhiteContainer(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ "Expiry & validity",
+ style: isDesktop
+ ? STextStyles.desktopTextSmall(context)
+ : STextStyles.titleBold12(context),
+ ),
+ const SizedBox(height: 8),
+ Text(
+ card.expiryAndValidity!,
+ style: isDesktop
+ ? STextStyles.desktopTextExtraExtraSmall(context)
+ : STextStyles.itemSubtitle12(context),
+ ),
+ ],
+ ),
+ ),
+ ],
+ SizedBox(height: isDesktop ? 24 : 16),
+ denominationSelector,
+ SizedBox(height: isDesktop ? 16 : 12),
+ quantityRow,
+ SizedBox(height: isDesktop ? 16 : 12),
+ termsCheckbox,
+ SizedBox(height: isDesktop ? 16 : 12),
+ Text(
+ "Email for receipt and delivery",
+ style: isDesktop
+ ? STextStyles.desktopTextExtraExtraSmall(context)
+ : STextStyles.itemSubtitle12(context),
+ ),
+ const SizedBox(height: 8),
+ ClipRRect(
+ borderRadius: BorderRadius.circular(
+ Constants.size.circularBorderRadius,
+ ),
+ child: TextField(
+ controller: _emailController,
+ focusNode: _emailFocusNode,
+ autocorrect: false,
+ enableSuggestions: false,
+ keyboardType: TextInputType.emailAddress,
+ onChanged: (_) => setState(() {}),
+ style: isDesktop
+ ? STextStyles.desktopTextExtraSmall(context).copyWith(
+ color: Theme.of(
+ context,
+ ).extension<StackColors>()!.textFieldActiveText,
+ height: 1.8,
+ )
+ : STextStyles.field(context).copyWith(
+ color: Theme.of(
+ context,
+ ).extension<StackColors>()!.textFieldActiveText,
+ ),
+ decoration:
+ standardInputDecoration(
+ "Email",
+ _emailFocusNode,
+ context,
+ desktopMed: isDesktop,
+ ).copyWith(
+ filled: true,
+ contentPadding: const EdgeInsets.symmetric(
+ horizontal: 16,
+ vertical: 12,
+ ),
+ ),
+ ),
+ ),
+ SizedBox(height: isDesktop ? 24 : 16),
+ PrimaryButton(
+ label: _purchasing ? "Processing..." : "Purchase",
+ enabled: _canPurchase,
+ onPressed: _canPurchase ? _purchase : null,
+ ),
+ ],
+ ),
+ );
+
+ return _scaffold(isDesktop: isDesktop, child: content);
+ }
+
+ Widget _scaffold({required bool isDesktop, required Widget child}) {
+ return ConditionalParent(
+ condition: isDesktop,
+ builder: (child) => DesktopDialog(
+ maxWidth: 580,
+ maxHeight: 700,
+ child: Column(
+ children: [
+ Row(
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ children: [
+ Padding(
+ padding: const EdgeInsets.only(left: 32),
+ child: Text(
+ "Gift Card",
+ style: STextStyles.desktopH3(context),
+ ),
+ ),
+ const DesktopDialogCloseButton(),
+ ],
+ ),
+ Expanded(
+ child: Padding(
+ padding: const EdgeInsets.symmetric(
+ horizontal: 32,
+ vertical: 8,
+ ),
+ child: child,
+ ),
+ ),
+ ],
+ ),
+ ),
+ child: ConditionalParent(
+ condition: !isDesktop,
+ builder: (child) => Background(
+ child: Scaffold(
+ backgroundColor: Theme.of(
+ context,
+ ).extension<StackColors>()!.background,
+ appBar: AppBar(
+ leading: AppBarBackButton(
+ onPressed: () => Navigator.of(context).pop(),
+ ),
+ title: Text("Gift Card", style: STextStyles.navBarTitle(context)),
+ ),
+ body: SafeArea(
+ child: Padding(padding: const EdgeInsets.all(16), child: child),
+ ),
+ ),
+ ),
+ child: child,
+ ),
+ );
+ }
+}
diff --git a/lib/pages/cakepay/cakepay_confirm_send_view.dart b/lib/pages/cakepay/cakepay_confirm_send_view.dart
new file mode 100644
index 0000000..41ea7a1
--- /dev/null
+++ b/lib/pages/cakepay/cakepay_confirm_send_view.dart
@@ -0,0 +1,625 @@
+import 'dart:async';
+
+import 'package:flutter/material.dart';
+import 'package:flutter_riverpod/flutter_riverpod.dart';
+
+import '../../models/isar/models/isar_models.dart';
+import '../../notifications/show_flush_bar.dart';
+import '../../pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_auth_send.dart';
+import '../../providers/providers.dart';
+import '../../route_generator.dart';
+import '../../themes/stack_colors.dart';
+import '../../utilities/amount/amount_formatter.dart';
+import '../../utilities/constants.dart';
+import '../../utilities/logger.dart';
+import '../../utilities/text_styles.dart';
+import '../../utilities/util.dart';
+import '../../wallets/isar/providers/wallet_info_provider.dart';
+import '../../wallets/models/tx_data.dart';
+import '../../widgets/background.dart';
+import '../../widgets/conditional_parent.dart';
+import '../../widgets/custom_buttons/app_bar_icon_button.dart';
+import '../../widgets/desktop/desktop_dialog.dart';
+import '../../widgets/desktop/desktop_dialog_close_button.dart';
+import '../../widgets/desktop/primary_button.dart';
+import '../../widgets/desktop/secondary_button.dart';
+import '../../widgets/rounded_container.dart';
+import '../../widgets/rounded_white_container.dart';
+import '../../widgets/stack_dialog.dart';
+import '../pinpad_views/lock_screen_view.dart';
+import '../send_view/sub_widgets/sending_transaction_dialog.dart';
+import '../wallet_view/wallet_view.dart';
+
+class CakePayConfirmSendView extends ConsumerStatefulWidget {
+ const CakePayConfirmSendView({
+ super.key,
+ required this.txData,
+ required this.walletId,
+ this.routeOnSuccessName = WalletView.routeName,
+ required this.orderId,
+ });
+
+ static const String routeName = "/cakePayConfirmSend";
+
+ final TxData txData;
+ final String walletId;
+ final String routeOnSuccessName;
+ final String orderId;
+
+ @override
+ ConsumerState<CakePayConfirmSendView> createState() =>
+ _CakePayConfirmSendViewState();
+}
+
+class _CakePayConfirmSendViewState
+ extends ConsumerState<CakePayConfirmSendView> {
+ late final String walletId;
+ late final String routeOnSuccessName;
+
+ final isDesktop = Util.isDesktop;
+
+ Future<void> _attemptSend(BuildContext context) async {
+ final parentWallet = ref.read(pWallets).getWallet(walletId);
+ final coin = parentWallet.info.coin;
+
+ final sendProgressController = ProgressAndSuccessController();
+
+ unawaited(
+ showDialog<void>(
+ context: context,
+ useSafeArea: false,
+ barrierDismissible: false,
+ builder: (context) {
+ return SendingTransactionDialog(
+ coin: coin,
+ controller: sendProgressController,
+ );
+ },
+ ),
+ );
+
+ final time = Future<dynamic>.delayed(const Duration(milliseconds: 2500));
+
+ late String txid;
+ final String note = widget.txData.note ?? "";
+
+ try {
+ final txidFuture = parentWallet.confirmSend(txData: widget.txData);
+
+ unawaited(parentWallet.refresh());
+
+ final results = await Future.wait([txidFuture, time]);
+
+ sendProgressController.triggerSuccess?.call();
+ await Future<void>.delayed(const Duration(seconds: 5));
+
+ txid = (results.first as TxData).txid!;
+
+ await ref
+ .read(mainDBProvider)
+ .putTransactionNote(
+ TransactionNote(walletId: walletId, txid: txid, value: note),
+ );
+
+ if (context.mounted) {
+ // pop sending dialog (pushed via showDialog which uses root navigator)
+ Navigator.of(context, rootNavigator: true).pop();
+
+ if (Util.isDesktop) {
+ // pop the confirm send desktop dialog
+ Navigator.of(context, rootNavigator: true).pop();
+ }
+
+ Navigator.of(context).popUntil(ModalRoute.withName(routeOnSuccessName));
+
+ if (context.mounted) {
+ unawaited(
+ showFloatingFlushBar(
+ type: FlushBarType.success,
+ message: "Payment sent! Check order status for updates.",
+ context: context,
+ ),
+ );
+ }
+ }
+ } catch (e, s) {
+ Logging.instance.e(
+ "Broadcast transaction failed: ",
+ error: e,
+ stackTrace: s,
+ );
+
+ if (context.mounted) {
+ Navigator.of(context, rootNavigator: true).pop();
+
+ await showDialog<dynamic>(
+ context: context,
+ useSafeArea: false,
+ barrierDismissible: true,
+ builder: (context) {
+ return StackDialog(
+ title: "Broadcast transaction failed",
+ message: e.toString(),
+ rightButton: TextButton(
+ style: Theme.of(context)
+ .extension<StackColors>()!
+ .getSecondaryEnabledButtonStyle(context),
+ child: Text(
+ "Ok",
+ style: STextStyles.button(context).copyWith(
+ color: Theme.of(
+ context,
+ ).extension<StackColors>()!.buttonTextSecondary,
+ ),
+ ),
+ onPressed: () {
+ Navigator.of(context).pop();
+ },
+ ),
+ );
+ },
+ );
+ }
+ }
+ }
+
+ Future<void> _confirmSend() async {
+ final dynamic unlocked;
+
+ final coin = ref.read(pWalletCoin(walletId));
+
+ if (Util.isDesktop) {
+ unlocked = await showDialog<bool?>(
+ context: context,
+ builder: (context) => DesktopDialog(
+ maxWidth: 580,
+ maxHeight: double.infinity,
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ const Row(
+ mainAxisAlignment: MainAxisAlignment.end,
+ children: [DesktopDialogCloseButton()],
+ ),
+ Padding(
+ padding: const EdgeInsets.only(left: 32, right: 32, bottom: 32),
+ child: DesktopAuthSend(coin: coin),
+ ),
+ ],
+ ),
+ ),
+ );
+ } else {
+ unlocked = await Navigator.push(
+ context,
+ RouteGenerator.getRoute<dynamic>(
+ shouldUseMaterialRoute: RouteGenerator.useMaterialPageRoute,
+ builder: (_) => const LockscreenView(
+ showBackButton: true,
+ popOnSuccess: true,
+ routeOnSuccessArguments: true,
+ routeOnSuccess: "",
+ biometricsCancelButtonString: "CANCEL",
+ biometricsLocalizedReason: "Authenticate to send transaction",
+ biometricsAuthenticationTitle: "Confirm Transaction",
+ ),
+ settings: const RouteSettings(name: "/confirmsendlockscreen"),
+ ),
+ );
+ }
+
+ if (unlocked is bool && mounted) {
+ if (unlocked) {
+ await _attemptSend(context);
+ } else {
+ unawaited(
+ showFloatingFlushBar(
+ type: FlushBarType.warning,
+ message: "Invalid passphrase",
+ context: context,
+ ),
+ );
+ }
+ }
+ }
+
+ @override
+ void initState() {
+ walletId = widget.walletId;
+ routeOnSuccessName = widget.routeOnSuccessName;
+ super.initState();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final coin = ref.watch(pWalletCoin(walletId));
+
+ return ConditionalParent(
+ condition: !isDesktop,
+ builder: (child) {
+ return Background(
+ child: Scaffold(
+ backgroundColor: Theme.of(
+ context,
+ ).extension<StackColors>()!.background,
+ appBar: AppBar(
+ backgroundColor: Theme.of(
+ context,
+ ).extension<StackColors>()!.backgroundAppBar,
+ leading: AppBarBackButton(
+ onPressed: () async {
+ Navigator.of(context).pop();
+ },
+ ),
+ title: Text(
+ "Confirm transaction",
+ style: STextStyles.navBarTitle(context),
+ ),
+ ),
+ body: SafeArea(
+ child: 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: ConditionalParent(
+ condition: isDesktop,
+ builder: (child) => DesktopDialog(
+ maxHeight: double.infinity,
+ maxWidth: 580,
+ child: Column(
+ children: [
+ Row(
+ children: [
+ const SizedBox(width: 6),
+ const AppBarBackButton(isCompact: true, iconSize: 23),
+ const SizedBox(width: 12),
+ Text(
+ "Confirm ${coin.ticker} transaction",
+ style: STextStyles.desktopH3(context),
+ ),
+ ],
+ ),
+ Padding(
+ padding: const EdgeInsets.only(left: 32, right: 32, bottom: 32),
+ child: Column(
+ children: [
+ RoundedWhiteContainer(
+ padding: const EdgeInsets.all(0),
+ borderColor: Theme.of(
+ context,
+ ).extension<StackColors>()!.background,
+ child: child,
+ ),
+ const SizedBox(height: 16),
+ Row(
+ children: [
+ Text(
+ "Transaction fee",
+ style: STextStyles.desktopTextExtraExtraSmall(
+ context,
+ ),
+ ),
+ ],
+ ),
+ const SizedBox(height: 10),
+ RoundedContainer(
+ color: Theme.of(
+ context,
+ ).extension<StackColors>()!.textFieldDefaultBG,
+ child: Row(
+ mainAxisAlignment: MainAxisAlignment.end,
+ children: [
+ Text(
+ ref
+ .watch(pAmountFormatter(coin))
+ .format(widget.txData.fee!),
+ style:
+ STextStyles.desktopTextExtraExtraSmall(
+ context,
+ ).copyWith(
+ color: Theme.of(
+ context,
+ ).extension<StackColors>()!.textDark,
+ ),
+ ),
+ ],
+ ),
+ ),
+ const SizedBox(height: 16),
+ RoundedContainer(
+ color: Theme.of(
+ context,
+ ).extension<StackColors>()!.snackBarBackSuccess,
+ child: Row(
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ children: [
+ Text(
+ "Total amount",
+ style: STextStyles.titleBold12(context).copyWith(
+ color: Theme.of(context)
+ .extension<StackColors>()!
+ .textConfirmTotalAmount,
+ ),
+ ),
+ Builder(
+ builder: (context) {
+ final fee = widget.txData.fee!;
+ final amount = widget.txData.amountWithoutChange!;
+ final total = amount + fee;
+ return Text(
+ ref.watch(pAmountFormatter(coin)).format(total),
+ style: STextStyles.itemSubtitle12(context)
+ .copyWith(
+ color: Theme.of(context)
+ .extension<StackColors>()!
+ .textConfirmTotalAmount,
+ ),
+ textAlign: TextAlign.right,
+ );
+ },
+ ),
+ ],
+ ),
+ ),
+ const SizedBox(height: 16),
+ Row(
+ children: [
+ Expanded(
+ child: SecondaryButton(
+ label: "Cancel",
+ buttonHeight: ButtonHeight.l,
+ onPressed: Navigator.of(context).pop,
+ ),
+ ),
+ const SizedBox(width: 16),
+ Expanded(
+ child: PrimaryButton(
+ label: "Send",
+ buttonHeight: isDesktop ? ButtonHeight.l : null,
+ onPressed: _confirmSend,
+ ),
+ ),
+ ],
+ ),
+ ],
+ ),
+ ),
+ ],
+ ),
+ ),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ ConditionalParent(
+ condition: isDesktop,
+ builder: (child) => Container(
+ decoration: BoxDecoration(
+ color: Theme.of(context).extension<StackColors>()!.background,
+ borderRadius: BorderRadius.vertical(
+ top: Radius.circular(Constants.size.circularBorderRadius),
+ ),
+ ),
+ child: Padding(
+ padding: const EdgeInsets.all(12),
+ child: Row(children: [child]),
+ ),
+ ),
+ child: Text(
+ "Send ${coin.ticker}",
+ style: isDesktop
+ ? STextStyles.desktopTextMedium(context)
+ : STextStyles.pageTitleH1(context),
+ ),
+ ),
+ isDesktop
+ ? Container(
+ color: Theme.of(
+ context,
+ ).extension<StackColors>()!.background,
+ height: 1,
+ )
+ : const SizedBox(height: 12),
+ RoundedWhiteContainer(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ Text("Send from", style: STextStyles.smallMed12(context)),
+ const SizedBox(height: 4),
+ Text(
+ ref.watch(pWalletName(walletId)),
+ style: STextStyles.itemSubtitle12(context),
+ ),
+ ],
+ ),
+ ),
+ isDesktop
+ ? Container(
+ color: Theme.of(
+ context,
+ ).extension<StackColors>()!.background,
+ height: 1,
+ )
+ : const SizedBox(height: 12),
+ RoundedWhiteContainer(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ Text(
+ "CakePay address",
+ style: STextStyles.smallMed12(context),
+ ),
+ const SizedBox(height: 4),
+ Text(
+ widget.txData.recipients!.first.address,
+ style: STextStyles.itemSubtitle12(context),
+ ),
+ ],
+ ),
+ ),
+ isDesktop
+ ? Container(
+ color: Theme.of(
+ context,
+ ).extension<StackColors>()!.background,
+ height: 1,
+ )
+ : const SizedBox(height: 12),
+ RoundedWhiteContainer(
+ child: Row(
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ children: [
+ Text("Amount", style: STextStyles.smallMed12(context)),
+ Text(
+ ref
+ .watch(pAmountFormatter(coin))
+ .format(widget.txData.amountWithoutChange!),
+ style: STextStyles.itemSubtitle12(context),
+ textAlign: TextAlign.right,
+ ),
+ ],
+ ),
+ ),
+ isDesktop
+ ? Container(
+ color: Theme.of(
+ context,
+ ).extension<StackColors>()!.background,
+ height: 1,
+ )
+ : const SizedBox(height: 12),
+ RoundedWhiteContainer(
+ child: Row(
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ children: [
+ Text(
+ "Transaction fee",
+ style: STextStyles.smallMed12(context),
+ ),
+ Text(
+ ref
+ .watch(pAmountFormatter(coin))
+ .format(widget.txData.fee!),
+ style: STextStyles.itemSubtitle12(context),
+ textAlign: TextAlign.right,
+ ),
+ ],
+ ),
+ ),
+ isDesktop
+ ? Container(
+ color: Theme.of(
+ context,
+ ).extension<StackColors>()!.background,
+ height: 1,
+ )
+ : const SizedBox(height: 12),
+ RoundedWhiteContainer(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ Text("Note", style: STextStyles.smallMed12(context)),
+ const SizedBox(height: 4),
+ Text(
+ widget.txData.note ?? "",
+ style: STextStyles.itemSubtitle12(context),
+ ),
+ ],
+ ),
+ ),
+ isDesktop
+ ? Container(
+ color: Theme.of(
+ context,
+ ).extension<StackColors>()!.background,
+ height: 1,
+ )
+ : const SizedBox(height: 12),
+ RoundedWhiteContainer(
+ child: Row(
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ children: [
+ Text("Order ID", style: STextStyles.smallMed12(context)),
+ Text(
+ widget.orderId.length > 8
+ ? "${widget.orderId.substring(0, 8)}..."
+ : widget.orderId,
+ style: STextStyles.itemSubtitle12(context),
+ textAlign: TextAlign.right,
+ ),
+ ],
+ ),
+ ),
+ if (!isDesktop) const SizedBox(height: 12),
+ if (!isDesktop)
+ RoundedContainer(
+ color: Theme.of(
+ context,
+ ).extension<StackColors>()!.snackBarBackSuccess,
+ child: Row(
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ children: [
+ Text(
+ "Total amount",
+ style: STextStyles.titleBold12(context).copyWith(
+ color: Theme.of(
+ context,
+ ).extension<StackColors>()!.textConfirmTotalAmount,
+ ),
+ ),
+ Builder(
+ builder: (context) {
+ final fee = widget.txData.fee!;
+ final amount = widget.txData.amountWithoutChange!;
+ final total = amount + fee;
+ return Text(
+ ref.watch(pAmountFormatter(coin)).format(total),
+ style: STextStyles.itemSubtitle12(context).copyWith(
+ color: Theme.of(
+ context,
+ ).extension<StackColors>()!.textConfirmTotalAmount,
+ ),
+ textAlign: TextAlign.right,
+ );
+ },
+ ),
+ ],
+ ),
+ ),
+ if (!isDesktop) const SizedBox(height: 16),
+ if (!isDesktop) const Spacer(),
+ if (!isDesktop)
+ PrimaryButton(
+ label: "Send",
+ buttonHeight: isDesktop ? ButtonHeight.l : null,
+ onPressed: _confirmSend,
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+}
diff --git a/lib/pages/cakepay/cakepay_order_view.dart b/lib/pages/cakepay/cakepay_order_view.dart
new file mode 100644
index 0000000..ce4d2b0
--- /dev/null
+++ b/lib/pages/cakepay/cakepay_order_view.dart
@@ -0,0 +1,999 @@
+import 'dart:async';
+
+import 'package:decimal/decimal.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
+import 'package:flutter_riverpod/flutter_riverpod.dart';
+
+import '../../app_config.dart';
+import '../../notifications/show_flush_bar.dart';
+import '../../providers/providers.dart';
+import '../../route_generator.dart';
+import '../../services/cakepay/cakepay_service.dart';
+import '../../services/cakepay/src/models/order.dart';
+import '../../themes/stack_colors.dart';
+import '../../utilities/amount/amount.dart';
+import '../../utilities/assets.dart';
+import '../../utilities/text_styles.dart';
+import '../../utilities/util.dart';
+import '../../wallets/crypto_currency/crypto_currency.dart';
+import '../../widgets/background.dart';
+import '../../widgets/conditional_parent.dart';
+import '../../widgets/custom_buttons/app_bar_icon_button.dart';
+import '../../widgets/desktop/desktop_dialog.dart';
+import '../../widgets/desktop/desktop_dialog_close_button.dart';
+import '../../widgets/desktop/primary_button.dart';
+import '../../widgets/qr.dart';
+import '../../widgets/rounded_white_container.dart';
+import 'cakepay_send_from_view.dart';
+
+class CakePayOrderView extends ConsumerStatefulWidget {
+ const CakePayOrderView({super.key, required this.orderId});
+
+ static const String routeName = "/cakePayOrder";
+
+ final String orderId;
+
+ @override
+ ConsumerState<CakePayOrderView> createState() => _CakePayOrderViewState();
+}
+
+class _CakePayOrderViewState extends ConsumerState<CakePayOrderView> {
+ CakePayOrder? _order;
+ bool _loading = true;
+ Timer? _pollTimer;
+ Timer? _countdownTimer;
+ Duration _timeRemaining = Duration.zero;
+ int _selectedPaymentMethod = 0;
+
+ @override
+ void initState() {
+ super.initState();
+ _loadOrder();
+ _pollTimer = Timer.periodic(
+ const Duration(seconds: 15),
+ (_) => _loadOrder(),
+ );
+ }
+
+ @override
+ void dispose() {
+ _pollTimer?.cancel();
+ _countdownTimer?.cancel();
+ super.dispose();
+ }
+
+ void _startCountdown() {
+ _countdownTimer?.cancel();
+ _updateTimeRemaining();
+ _countdownTimer = Timer.periodic(
+ const Duration(seconds: 1),
+ (_) => _updateTimeRemaining(),
+ );
+ }
+
+ void _updateTimeRemaining() {
+ if (_order?.expirationTime == null) return;
+ final expiresAt = DateTime.fromMillisecondsSinceEpoch(
+ _order!.expirationTime!,
+ );
+ final remaining = expiresAt.difference(DateTime.now());
+ if (mounted) {
+ setState(() {
+ _timeRemaining = remaining.isNegative ? Duration.zero : remaining;
+ });
+ }
+ if (remaining.isNegative) {
+ _countdownTimer?.cancel();
+ }
+ }
+
+ String _formatDuration(Duration d) {
+ if (d.isNegative || d == Duration.zero) return "Expired";
+ final minutes = d.inMinutes;
+ final seconds = d.inSeconds % 60;
+ if (d.inHours > 0) {
+ return "${d.inHours}h ${minutes % 60}m ${seconds}s";
+ }
+ return "${minutes}m ${seconds}s";
+ }
+
+ void _navigateToSendFrom({
+ required CryptoCurrency coin,
+ required Amount? amount,
+ required String address,
+ required String orderId,
+ }) {
+ final isDesktop = Util.isDesktop;
+ if (isDesktop) {
+ Navigator.of(context, rootNavigator: true).pop();
+ showDialog<void>(
+ context: context,
+ builder: (_) => CakePaySendFromView(
+ coin: coin,
+ amount: amount,
+ address: address,
+ orderId: orderId,
+ shouldPopRoot: true,
+ ),
+ );
+ } else {
+ Navigator.of(context).push(
+ RouteGenerator.getRoute<dynamic>(
+ shouldUseMaterialRoute: RouteGenerator.useMaterialPageRoute,
+ builder: (_) => CakePaySendFromView(
+ coin: coin,
+ amount: amount,
+ address: address,
+ orderId: orderId,
+ ),
+ settings: const RouteSettings(name: CakePaySendFromView.routeName),
+ ),
+ );
+ }
+ }
+
+ /// Resolve an API ticker (e.g. "LTC_MWEB") to a Stack Wallet coin,
+ /// falling back to the base ticker before "_" if the full one isn't
+ /// recognised.
+ CryptoCurrency? _resolveCoin(String apiTicker) {
+ final ticker = apiTicker.toUpperCase();
+ var coin = AppConfig.getCryptoCurrencyForTicker(ticker);
+ if (coin == null &&
+ ticker.contains('_') &&
+ !ticker.endsWith('_LN')) {
+ coin = AppConfig.getCryptoCurrencyForTicker(
+ ticker.split('_').first,
+ );
+ }
+ return coin;
+ }
+
+ /// Pretty-print an API ticker for display.
+ String _tickerLabel(String apiTicker) {
+ switch (apiTicker.toUpperCase()) {
+ case 'BTC_LN':
+ return 'BTC (LN)';
+ case 'LTC_MWEB':
+ return 'LTC (MWEB)';
+ default:
+ return apiTicker.toUpperCase();
+ }
+ }
+
+ void _payWithOption(CakePayPaymentOption option, String orderId) {
+ final label = _tickerLabel(option.ticker);
+ final coin = _resolveCoin(option.ticker);
+
+ if (coin == null) {
+ showFloatingFlushBar(
+ type: FlushBarType.warning,
+ message: "No wallet support for $label",
+ context: context,
+ );
+ return;
+ }
+
+ final hasWallet = ref
+ .read(pWallets)
+ .wallets
+ .any((w) => w.info.coin == coin);
+
+ if (!hasWallet) {
+ showFloatingFlushBar(
+ type: FlushBarType.warning,
+ message: "No $label wallet found. Create one first.",
+ context: context,
+ );
+ return;
+ }
+
+ Amount? amount;
+ try {
+ amount = Amount.fromDecimal(
+ Decimal.parse(option.amountFrom.toString()),
+ fractionDigits: coin.fractionDigits,
+ );
+ } catch (_) {}
+
+ _navigateToSendFrom(
+ coin: coin,
+ amount: amount,
+ address: option.address,
+ orderId: orderId,
+ );
+ }
+
+ Future<void> _loadOrder() async {
+ final resp = await CakePayService.instance.client.getOrder(widget.orderId);
+ if (mounted) {
+ setState(() {
+ _loading = false;
+ if (!resp.hasError && resp.value != null) {
+ _order = resp.value;
+ if (_isTerminal(_order!.status)) {
+ _pollTimer?.cancel();
+ _countdownTimer?.cancel();
+ } else if (_order!.expirationTime != null) {
+ _startCountdown();
+ }
+ }
+ });
+ }
+ }
+
+ bool _isTerminal(CakePayOrderStatus status) {
+ return status == CakePayOrderStatus.complete ||
+ status == CakePayOrderStatus.expired ||
+ status == CakePayOrderStatus.failed ||
+ status == CakePayOrderStatus.refunded;
+ }
+
+ /// Whether the order has received payment and is being processed or
+ /// is already complete. Payment UI should be hidden for these.
+ bool _isPaidOrBeyond(CakePayOrderStatus status) {
+ return const {
+ CakePayOrderStatus.paid,
+ CakePayOrderStatus.pendingPurchase,
+ CakePayOrderStatus.purchaseProcessing,
+ CakePayOrderStatus.purchased,
+ CakePayOrderStatus.pendingEmail,
+ CakePayOrderStatus.complete,
+ }.contains(status);
+ }
+
+ /// Whether payment UI (tabs, QR, address, pay button) should be shown.
+ bool _showPaymentUI(CakePayOrderStatus status) {
+ return !_isPaidOrBeyond(status) &&
+ status != CakePayOrderStatus.expired &&
+ status != CakePayOrderStatus.failed &&
+ status != CakePayOrderStatus.pendingRefund &&
+ status != CakePayOrderStatus.refunded;
+ }
+
+ /// Copyable order ID and created-at timestamp for terminal state banners.
+ List<Widget> _orderInfoWidgets(CakePayOrder order, bool isDesktop) {
+ final subtitleStyle = isDesktop
+ ? STextStyles.desktopTextExtraExtraSmall(context)
+ : STextStyles.itemSubtitle12(context);
+
+ return [
+ // Copyable order ID.
+ RoundedWhiteContainer(
+ child: GestureDetector(
+ onTap: () {
+ Clipboard.setData(ClipboardData(text: order.orderId));
+ showFloatingFlushBar(
+ type: FlushBarType.info,
+ message: "Order ID copied",
+ iconAsset: Assets.svg.copy,
+ context: context,
+ );
+ },
+ child: Row(
+ children: [
+ Expanded(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text("Order ID", style: subtitleStyle),
+ const SizedBox(height: 4),
+ Text(
+ order.orderId,
+ style: isDesktop
+ ? STextStyles.desktopTextSmall(context)
+ : STextStyles.titleBold12(context),
+ ),
+ ],
+ ),
+ ),
+ Icon(
+ Icons.copy,
+ size: 14,
+ color: Theme.of(context)
+ .extension<StackColors>()!
+ .accentColorBlue,
+ ),
+ ],
+ ),
+ ),
+ ),
+ // Created-at timestamp.
+ if (order.createdAt != null) ...[
+ SizedBox(height: isDesktop ? 8 : 6),
+ RoundedWhiteContainer(
+ child: Row(
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ children: [
+ Text("Created", style: subtitleStyle),
+ Text(order.createdAt!, style: subtitleStyle),
+ ],
+ ),
+ ),
+ ],
+ ];
+ }
+
+ String _statusLabel(CakePayOrderStatus status) {
+ switch (status) {
+ case CakePayOrderStatus.new_:
+ return "New";
+ case CakePayOrderStatus.expiredButStillPending:
+ return "Expired (pending)";
+ case CakePayOrderStatus.expired:
+ return "Expired";
+ case CakePayOrderStatus.failed:
+ return "Failed";
+ case CakePayOrderStatus.paid:
+ return "Paid";
+ case CakePayOrderStatus.paidPartial:
+ return "Partially paid";
+ case CakePayOrderStatus.pendingPurchase:
+ return "Pending purchase";
+ case CakePayOrderStatus.purchaseProcessing:
+ return "Processing";
+ case CakePayOrderStatus.purchased:
+ return "Purchased";
+ case CakePayOrderStatus.pendingEmail:
+ return "Pending email";
+ case CakePayOrderStatus.complete:
+ return "Complete";
+ case CakePayOrderStatus.pendingRefund:
+ return "Pending refund";
+ case CakePayOrderStatus.refunded:
+ return "Refunded";
+ }
+ }
+
+ Color _statusColor(BuildContext context, CakePayOrderStatus status) {
+ final colors = Theme.of(context).extension<StackColors>()!;
+ switch (status) {
+ case CakePayOrderStatus.complete:
+ case CakePayOrderStatus.purchased:
+ return colors.accentColorGreen;
+ case CakePayOrderStatus.new_:
+ case CakePayOrderStatus.paid:
+ case CakePayOrderStatus.paidPartial:
+ return colors.accentColorBlue;
+ case CakePayOrderStatus.pendingPurchase:
+ case CakePayOrderStatus.purchaseProcessing:
+ case CakePayOrderStatus.pendingEmail:
+ case CakePayOrderStatus.expiredButStillPending:
+ return colors.accentColorYellow;
+ case CakePayOrderStatus.expired:
+ case CakePayOrderStatus.failed:
+ case CakePayOrderStatus.pendingRefund:
+ case CakePayOrderStatus.refunded:
+ return colors.textSubtitle1;
+ }
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final isDesktop = Util.isDesktop;
+
+ if (_loading) {
+ return _scaffold(
+ isDesktop: isDesktop,
+ child: const Center(
+ child: SizedBox(
+ width: 24,
+ height: 24,
+ child: CircularProgressIndicator(strokeWidth: 2),
+ ),
+ ),
+ );
+ }
+
+ if (_order == null) {
+ return _scaffold(
+ isDesktop: isDesktop,
+ child: Center(
+ child: Text(
+ "Failed to load order",
+ style: isDesktop
+ ? STextStyles.desktopTextSmall(context)
+ : STextStyles.itemSubtitle(context),
+ ),
+ ),
+ );
+ }
+
+ final order = _order!;
+ final paymentOptions = order.paymentOptions;
+
+ final statusBadge = Container(
+ padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
+ decoration: BoxDecoration(
+ borderRadius: BorderRadius.circular(8),
+ color: _statusColor(context, order.status).withValues(alpha: 0.2),
+ ),
+ child: Text(
+ _statusLabel(order.status),
+ style:
+ (isDesktop
+ ? STextStyles.desktopTextExtraExtraSmall(context)
+ : STextStyles.itemSubtitle12(context))
+ .copyWith(color: _statusColor(context, order.status)),
+ ),
+ );
+
+ final details = <Widget>[
+ Row(
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ children: [
+ Text(
+ "Order ${order.orderId.length > 8 ? "${order.orderId.substring(0, 8)}..." : order.orderId}",
+ style: isDesktop
+ ? STextStyles.desktopH2(context)
+ : STextStyles.pageTitleH1(context),
+ ),
+ statusBadge,
+ ],
+ ),
+ SizedBox(height: isDesktop ? 16 : 12),
+ ];
+
+ if (order.amountUsd != null) {
+ details.add(
+ RoundedWhiteContainer(
+ child: Row(
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ children: [
+ Text(
+ "Amount",
+ style: isDesktop
+ ? STextStyles.desktopTextExtraExtraSmall(context)
+ : STextStyles.itemSubtitle12(context),
+ ),
+ Text(
+ "\$${order.amountUsd} USD",
+ style: isDesktop
+ ? STextStyles.desktopTextSmall(context)
+ : STextStyles.titleBold12(context),
+ ),
+ ],
+ ),
+ ),
+ );
+ details.add(SizedBox(height: isDesktop ? 16 : 12));
+ }
+
+ if (order.cards != null && order.cards!.isNotEmpty) {
+ for (final item in order.cards!) {
+ details.add(
+ RoundedWhiteContainer(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ item.name ?? "Gift Card",
+ style: isDesktop
+ ? STextStyles.desktopTextSmall(context)
+ : STextStyles.titleBold12(context),
+ ),
+ if (item.priceValue != null) ...[
+ const SizedBox(height: 4),
+ Text(
+ "${item.priceValue} ${item.currencyCode ?? ''}".trim(),
+ style: isDesktop
+ ? STextStyles.desktopTextExtraExtraSmall(context)
+ : STextStyles.itemSubtitle12(context),
+ ),
+ ],
+ if (item.priceUsd != null) ...[
+ const SizedBox(height: 2),
+ Text(
+ item.priceUsd!,
+ style:
+ (isDesktop
+ ? STextStyles.desktopTextExtraExtraSmall(
+ context,
+ )
+ : STextStyles.itemSubtitle12(context))
+ .copyWith(
+ color: Theme.of(
+ context,
+ ).extension<StackColors>()!.textSubtitle1,
+ ),
+ ),
+ ],
+ ],
+ ),
+ ),
+ );
+ details.add(SizedBox(height: isDesktop ? 8 : 6));
+ }
+ }
+
+ // Commission / markup info.
+ if (order.commission != null || order.markupPercent != null) {
+ details.add(
+ RoundedWhiteContainer(
+ child: Column(
+ children: [
+ if (order.commission != null)
+ Row(
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ children: [
+ Text(
+ "Commission",
+ style: isDesktop
+ ? STextStyles.desktopTextExtraExtraSmall(context)
+ : STextStyles.itemSubtitle12(context),
+ ),
+ Text(
+ order.commission!,
+ style: isDesktop
+ ? STextStyles.desktopTextExtraExtraSmall(context)
+ : STextStyles.itemSubtitle12(context),
+ ),
+ ],
+ ),
+ if (order.commission != null && order.markupPercent != null)
+ const SizedBox(height: 4),
+ if (order.markupPercent != null)
+ Row(
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ children: [
+ Text(
+ "Markup",
+ style: isDesktop
+ ? STextStyles.desktopTextExtraExtraSmall(context)
+ : STextStyles.itemSubtitle12(context),
+ ),
+ Text(
+ "${order.markupPercent!.toStringAsFixed(2)}%",
+ style: isDesktop
+ ? STextStyles.desktopTextExtraExtraSmall(context)
+ : STextStyles.itemSubtitle12(context),
+ ),
+ ],
+ ),
+ ],
+ ),
+ ),
+ );
+ details.add(SizedBox(height: isDesktop ? 8 : 6));
+ }
+
+ // Expiration countdown.
+ if (order.expirationTime != null) {
+ final isExpired = _timeRemaining == Duration.zero;
+ details.add(
+ RoundedWhiteContainer(
+ child: Row(
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ children: [
+ Text(
+ "Time remaining",
+ style: isDesktop
+ ? STextStyles.desktopTextExtraExtraSmall(context)
+ : STextStyles.itemSubtitle12(context),
+ ),
+ Text(
+ _formatDuration(_timeRemaining),
+ style:
+ (isDesktop
+ ? STextStyles.desktopTextExtraExtraSmall(context)
+ : STextStyles.itemSubtitle12(context))
+ .copyWith(
+ color: isExpired
+ ? Theme.of(
+ context,
+ ).extension<StackColors>()!.accentColorRed
+ : _timeRemaining.inMinutes < 5
+ ? Theme.of(
+ context,
+ ).extension<StackColors>()!.accentColorOrange
+ : null,
+ fontWeight: FontWeight.w600,
+ ),
+ ),
+ ],
+ ),
+ ),
+ );
+ details.add(SizedBox(height: isDesktop ? 8 : 6));
+ }
+
+ // --- Status-dependent payment section ---
+ final status = order.status;
+
+ // Banner for paid / processing states.
+ if (_isPaidOrBeyond(status)) {
+ details.add(SizedBox(height: isDesktop ? 16 : 12));
+ details.add(
+ RoundedWhiteContainer(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Row(
+ children: [
+ Icon(
+ Icons.check_circle,
+ size: 20,
+ color: Theme.of(context)
+ .extension<StackColors>()!
+ .accentColorGreen,
+ ),
+ const SizedBox(width: 8),
+ Expanded(
+ child: Text(
+ status == CakePayOrderStatus.complete
+ ? "Order complete."
+ : "Payment received.",
+ style: (isDesktop
+ ? STextStyles
+ .desktopTextExtraExtraSmall(
+ context,
+ )
+ : STextStyles.itemSubtitle12(
+ context,
+ ))
+ .copyWith(
+ color: Theme.of(context)
+ .extension<StackColors>()!
+ .accentColorGreen,
+ ),
+ ),
+ ),
+ ],
+ ),
+ const SizedBox(height: 8),
+ Text(
+ "Your gift card details will be sent to "
+ "the email address provided when creating "
+ "the order.",
+ style: isDesktop
+ ? STextStyles.desktopTextExtraExtraSmall(
+ context,
+ )
+ : STextStyles.itemSubtitle12(context),
+ ),
+ ],
+ ),
+ ),
+ );
+ details.add(SizedBox(height: isDesktop ? 8 : 6));
+ details.addAll(_orderInfoWidgets(order, isDesktop));
+ details.add(SizedBox(height: isDesktop ? 8 : 6));
+ details.add(
+ const PrimaryButton(
+ label: "ORDER PAID",
+ enabled: false,
+ onPressed: null,
+ ),
+ );
+ details.add(SizedBox(height: isDesktop ? 8 : 6));
+ }
+
+ // Banner for expired / failed / refund states.
+ if (status == CakePayOrderStatus.expired ||
+ status == CakePayOrderStatus.failed ||
+ status == CakePayOrderStatus.pendingRefund ||
+ status == CakePayOrderStatus.refunded) {
+ details.add(SizedBox(height: isDesktop ? 16 : 12));
+ details.add(
+ RoundedWhiteContainer(
+ child: Row(
+ children: [
+ Icon(
+ Icons.cancel,
+ size: 20,
+ color: Theme.of(context)
+ .extension<StackColors>()!
+ .textSubtitle1,
+ ),
+ const SizedBox(width: 8),
+ Expanded(
+ child: Text(
+ _statusLabel(status),
+ style: (isDesktop
+ ? STextStyles
+ .desktopTextExtraExtraSmall(
+ context,
+ )
+ : STextStyles.itemSubtitle12(
+ context,
+ ))
+ .copyWith(
+ color: Theme.of(context)
+ .extension<StackColors>()!
+ .textSubtitle1,
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ );
+ details.add(SizedBox(height: isDesktop ? 8 : 6));
+ details.addAll(_orderInfoWidgets(order, isDesktop));
+ details.add(SizedBox(height: isDesktop ? 8 : 6));
+ }
+
+ // Payment UI: tabs + QR + address + pay button.
+ // Only shown for states that still accept payment.
+ if (_showPaymentUI(status) &&
+ paymentOptions != null &&
+ paymentOptions.isNotEmpty) {
+ // Sort so BTC_LN always appears last.
+ final options = paymentOptions.values.toList()
+ ..sort((a, b) {
+ final aLn = a.ticker.toUpperCase() == 'BTC_LN';
+ final bLn = b.ticker.toUpperCase() == 'BTC_LN';
+ if (aLn && !bLn) return 1;
+ if (!aLn && bLn) return -1;
+ return 0;
+ });
+ if (_selectedPaymentMethod >= options.length) {
+ _selectedPaymentMethod = 0;
+ }
+ final selected = options[_selectedPaymentMethod];
+ final label = _tickerLabel(selected.ticker);
+ final coin = _resolveCoin(selected.ticker);
+ final bool hasWallet =
+ coin != null &&
+ ref.watch(pWallets).wallets.any(
+ (w) => w.info.coin == coin,
+ );
+
+ details.add(SizedBox(height: isDesktop ? 8 : 4));
+ details.add(
+ Text(
+ "Pay with",
+ style: isDesktop
+ ? STextStyles.desktopTextSmall(context)
+ : STextStyles.titleBold12(context),
+ ),
+ );
+ details.add(SizedBox(height: isDesktop ? 8 : 6));
+
+ // Tab selector.
+ details.add(
+ Row(
+ children: List.generate(options.length, (index) {
+ final isSelected =
+ _selectedPaymentMethod == index;
+ return Expanded(
+ child: GestureDetector(
+ onTap: () => setState(
+ () => _selectedPaymentMethod = index,
+ ),
+ child: Container(
+ padding: const EdgeInsets.symmetric(
+ vertical: 10,
+ ),
+ decoration: BoxDecoration(
+ border: Border(
+ bottom: BorderSide(
+ color: isSelected
+ ? Theme.of(context)
+ .extension<StackColors>()!
+ .accentColorBlue
+ : Colors.transparent,
+ width: 2,
+ ),
+ ),
+ ),
+ child: Text(
+ _tickerLabel(options[index].ticker),
+ textAlign: TextAlign.center,
+ style: (isDesktop
+ ? STextStyles
+ .desktopTextExtraExtraSmall(
+ context,
+ )
+ : STextStyles.itemSubtitle12(
+ context,
+ ))
+ .copyWith(
+ color: isSelected
+ ? Theme.of(context)
+ .extension<StackColors>()!
+ .accentColorBlue
+ : null,
+ fontWeight: isSelected
+ ? FontWeight.w600
+ : null,
+ ),
+ ),
+ ),
+ ),
+ );
+ }),
+ ),
+ );
+
+ details.add(SizedBox(height: isDesktop ? 16 : 12));
+
+ // QR code for the selected payment address.
+ if (selected.address.isNotEmpty) {
+ details.add(
+ Center(
+ child: QR(
+ data: selected.address,
+ size: isDesktop ? 200 : 180,
+ ),
+ ),
+ );
+ details.add(SizedBox(height: isDesktop ? 16 : 12));
+ }
+
+ // Selected method details.
+ details.add(
+ RoundedWhiteContainer(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Row(
+ mainAxisAlignment:
+ MainAxisAlignment.spaceBetween,
+ children: [
+ Text(
+ "Amount",
+ style: isDesktop
+ ? STextStyles
+ .desktopTextExtraExtraSmall(
+ context,
+ )
+ : STextStyles.itemSubtitle12(
+ context,
+ ),
+ ),
+ Text(
+ "${selected.amountFrom} $label",
+ style: isDesktop
+ ? STextStyles.desktopTextSmall(
+ context,
+ )
+ : STextStyles.titleBold12(context),
+ ),
+ ],
+ ),
+ const SizedBox(height: 8),
+ GestureDetector(
+ onTap: () {
+ Clipboard.setData(
+ ClipboardData(text: selected.address),
+ );
+ showFloatingFlushBar(
+ type: FlushBarType.info,
+ message: "Copied to clipboard",
+ iconAsset: Assets.svg.copy,
+ context: context,
+ );
+ },
+ child: Column(
+ crossAxisAlignment:
+ CrossAxisAlignment.start,
+ children: [
+ Row(
+ children: [
+ Text(
+ "$label address",
+ style: isDesktop
+ ? STextStyles
+ .desktopTextExtraExtraSmall(
+ context,
+ )
+ : STextStyles
+ .itemSubtitle12(
+ context,
+ ),
+ ),
+ const Spacer(),
+ Icon(
+ Icons.copy,
+ size: 14,
+ color: Theme.of(context)
+ .extension<StackColors>()!
+ .accentColorBlue,
+ ),
+ const SizedBox(width: 4),
+ Text(
+ "Copy",
+ style:
+ STextStyles.link2(context),
+ ),
+ ],
+ ),
+ const SizedBox(height: 4),
+ Text(
+ selected.address,
+ style: isDesktop
+ ? STextStyles
+ .desktopTextExtraExtraSmall(
+ context,
+ )
+ : STextStyles.itemSubtitle12(
+ context,
+ ),
+ ),
+ ],
+ ),
+ ),
+ const SizedBox(height: 12),
+ PrimaryButton(
+ label: hasWallet
+ ? "Pay with $label"
+ : "$label (no wallet)",
+ enabled: hasWallet,
+ onPressed: hasWallet
+ ? () => _payWithOption(
+ selected,
+ order.orderId,
+ )
+ : null,
+ ),
+ ],
+ ),
+ ),
+ );
+ details.add(SizedBox(height: isDesktop ? 8 : 6));
+ }
+
+ final content = SingleChildScrollView(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: details,
+ ),
+ );
+
+ return _scaffold(isDesktop: isDesktop, child: content);
+ }
+
+ Widget _scaffold({required bool isDesktop, required Widget child}) {
+ return ConditionalParent(
+ condition: isDesktop,
+ builder: (child) => DesktopDialog(
+ maxWidth: 580,
+ maxHeight: 650,
+ child: Column(
+ children: [
+ Row(
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ children: [
+ Padding(
+ padding: const EdgeInsets.only(left: 32),
+ child: Text("Order", style: STextStyles.desktopH3(context)),
+ ),
+ const DesktopDialogCloseButton(),
+ ],
+ ),
+ Expanded(
+ child: Padding(
+ padding: const EdgeInsets.symmetric(
+ horizontal: 32,
+ vertical: 8,
+ ),
+ child: child,
+ ),
+ ),
+ ],
+ ),
+ ),
+ child: ConditionalParent(
+ condition: !isDesktop,
+ builder: (child) => Background(
+ child: Scaffold(
+ backgroundColor: Theme.of(
+ context,
+ ).extension<StackColors>()!.background,
+ appBar: AppBar(
+ leading: AppBarBackButton(
+ onPressed: () => Navigator.of(context).pop(),
+ ),
+ title: Text("Order", style: STextStyles.navBarTitle(context)),
+ ),
+ body: SafeArea(
+ child: Padding(padding: const EdgeInsets.all(16), child: child),
+ ),
+ ),
+ ),
+ child: child,
+ ),
+ );
+ }
+}
diff --git a/lib/pages/cakepay/cakepay_orders_view.dart b/lib/pages/cakepay/cakepay_orders_view.dart
new file mode 100644
index 0000000..56e0070
--- /dev/null
+++ b/lib/pages/cakepay/cakepay_orders_view.dart
@@ -0,0 +1,306 @@
+import 'package:flutter/material.dart';
+
+import '../../services/cakepay/cakepay_service.dart';
+import '../../services/cakepay/src/models/order.dart';
+import '../../themes/stack_colors.dart';
+import '../../utilities/text_styles.dart';
+import '../../utilities/util.dart';
+import '../../widgets/background.dart';
+import '../../widgets/conditional_parent.dart';
+import '../../widgets/custom_buttons/app_bar_icon_button.dart';
+import '../../widgets/desktop/desktop_dialog.dart';
+import '../../widgets/desktop/desktop_dialog_close_button.dart';
+import '../../widgets/rounded_white_container.dart';
+import 'cakepay_order_view.dart';
+
+class CakePayOrdersView extends StatefulWidget {
+ const CakePayOrdersView({super.key});
+
+ static const String routeName = "/cakePayOrders";
+
+ @override
+ State<CakePayOrdersView> createState() => _CakePayOrdersViewState();
+}
+
+class _CakePayOrdersViewState extends State<CakePayOrdersView> {
+ List<CakePayOrder> _orders = [];
+ bool _syncing = false;
+
+ @override
+ void initState() {
+ super.initState();
+ _syncFromApi();
+ }
+
+ /// Fetch each locally-tracked order ID individually via getOrder()
+ /// (which works with the seller API key, unlike getMyOrders()).
+ /// Mirrors ShopInBit's _syncFromApi() pattern.
+ Future<void> _syncFromApi() async {
+ setState(() => _syncing = true);
+ try {
+ final orderIds = CakePayService.instance.getOrderIds();
+ final results = <CakePayOrder>[];
+
+ for (final id in orderIds) {
+ final resp = await CakePayService.instance.client.getOrder(id);
+ if (!resp.hasError && resp.value != null) {
+ results.add(resp.value!);
+ }
+ }
+
+ if (mounted) {
+ setState(() {
+ _orders = results;
+ });
+ }
+ } catch (_) {
+ // Fall back to empty list — no local cache to fall back on
+ } finally {
+ if (mounted) {
+ setState(() => _syncing = false);
+ }
+ }
+ }
+
+ String _statusLabel(CakePayOrderStatus status) {
+ switch (status) {
+ case CakePayOrderStatus.new_:
+ return "New";
+ case CakePayOrderStatus.expiredButStillPending:
+ return "Expired (pending)";
+ case CakePayOrderStatus.expired:
+ return "Expired";
+ case CakePayOrderStatus.failed:
+ return "Failed";
+ case CakePayOrderStatus.paid:
+ return "Paid";
+ case CakePayOrderStatus.paidPartial:
+ return "Partially paid";
+ case CakePayOrderStatus.pendingPurchase:
+ return "Pending purchase";
+ case CakePayOrderStatus.purchaseProcessing:
+ return "Processing";
+ case CakePayOrderStatus.purchased:
+ return "Purchased";
+ case CakePayOrderStatus.pendingEmail:
+ return "Pending email";
+ case CakePayOrderStatus.complete:
+ return "Complete";
+ case CakePayOrderStatus.pendingRefund:
+ return "Pending refund";
+ case CakePayOrderStatus.refunded:
+ return "Refunded";
+ }
+ }
+
+ Color _statusColor(BuildContext context, CakePayOrderStatus status) {
+ final colors = Theme.of(context).extension<StackColors>()!;
+ switch (status) {
+ case CakePayOrderStatus.complete:
+ case CakePayOrderStatus.purchased:
+ return colors.accentColorGreen;
+ case CakePayOrderStatus.new_:
+ case CakePayOrderStatus.paid:
+ case CakePayOrderStatus.paidPartial:
+ return colors.accentColorBlue;
+ case CakePayOrderStatus.pendingPurchase:
+ case CakePayOrderStatus.purchaseProcessing:
+ case CakePayOrderStatus.pendingEmail:
+ case CakePayOrderStatus.expiredButStillPending:
+ return colors.accentColorYellow;
+ case CakePayOrderStatus.expired:
+ case CakePayOrderStatus.failed:
+ case CakePayOrderStatus.pendingRefund:
+ case CakePayOrderStatus.refunded:
+ return colors.textSubtitle1;
+ }
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final isDesktop = Util.isDesktop;
+
+ final list = _orders.isEmpty
+ ? Center(
+ child: Text(
+ _syncing ? "Loading orders..." : "No orders yet",
+ style: isDesktop
+ ? STextStyles.desktopTextSmall(context)
+ : STextStyles.itemSubtitle(context),
+ ),
+ )
+ : ListView.separated(
+ shrinkWrap: isDesktop,
+ primary: isDesktop ? false : null,
+ itemCount: _orders.length,
+ separatorBuilder: (_, __) => SizedBox(height: isDesktop ? 16 : 12),
+ itemBuilder: (context, index) {
+ final order = _orders[index];
+ return GestureDetector(
+ onTap: () {
+ if (isDesktop) {
+ Navigator.of(context, rootNavigator: true).pop();
+ showDialog<void>(
+ context: context,
+ builder: (_) => CakePayOrderView(orderId: order.orderId),
+ );
+ } else {
+ Navigator.of(context).pushNamed(
+ CakePayOrderView.routeName,
+ arguments: order.orderId,
+ );
+ }
+ },
+ child: RoundedWhiteContainer(
+ child: Row(
+ children: [
+ Expanded(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Row(
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ children: [
+ Text(
+ order.orderId.length > 8
+ ? "${order.orderId.substring(0, 8)}..."
+ : order.orderId,
+ style: isDesktop
+ ? STextStyles.desktopTextSmall(context)
+ : STextStyles.titleBold12(context),
+ ),
+ Container(
+ padding: const EdgeInsets.symmetric(
+ horizontal: 8,
+ vertical: 2,
+ ),
+ decoration: BoxDecoration(
+ borderRadius: BorderRadius.circular(8),
+ color: _statusColor(
+ context,
+ order.status,
+ ).withValues(alpha: 0.2),
+ ),
+ child: Text(
+ _statusLabel(order.status),
+ style:
+ (isDesktop
+ ? STextStyles.desktopTextExtraExtraSmall(
+ context,
+ )
+ : STextStyles.itemSubtitle12(
+ context,
+ ))
+ .copyWith(
+ color: _statusColor(
+ context,
+ order.status,
+ ),
+ ),
+ ),
+ ),
+ ],
+ ),
+ if (order.amountUsd != null) ...[
+ const SizedBox(height: 4),
+ Text(
+ "\$${order.amountUsd} USD",
+ style: isDesktop
+ ? STextStyles.desktopTextExtraExtraSmall(
+ context,
+ )
+ : STextStyles.itemSubtitle12(
+ context,
+ ).copyWith(
+ color: Theme.of(context)
+ .extension<StackColors>()!
+ .textSubtitle1,
+ ),
+ ),
+ ],
+ ],
+ ),
+ ),
+ SizedBox(width: isDesktop ? 16 : 8),
+ Icon(
+ Icons.chevron_right,
+ color: Theme.of(
+ context,
+ ).extension<StackColors>()!.textSubtitle1,
+ ),
+ ],
+ ),
+ ),
+ );
+ },
+ );
+
+ final content = Stack(
+ children: [
+ list,
+ if (_syncing)
+ const Center(
+ child: SizedBox(
+ width: 24,
+ height: 24,
+ child: CircularProgressIndicator(strokeWidth: 2),
+ ),
+ ),
+ ],
+ );
+
+ return ConditionalParent(
+ condition: isDesktop,
+ builder: (child) => DesktopDialog(
+ maxWidth: 580,
+ maxHeight: 550,
+ child: Column(
+ children: [
+ Row(
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ children: [
+ Padding(
+ padding: const EdgeInsets.only(left: 32),
+ child: Text(
+ "My Orders",
+ style: STextStyles.desktopH3(context),
+ ),
+ ),
+ const DesktopDialogCloseButton(),
+ ],
+ ),
+ Expanded(
+ child: Padding(
+ padding: const EdgeInsets.symmetric(
+ horizontal: 32,
+ vertical: 16,
+ ),
+ child: child,
+ ),
+ ),
+ ],
+ ),
+ ),
+ child: ConditionalParent(
+ condition: !isDesktop,
+ builder: (child) => Background(
+ child: Scaffold(
+ backgroundColor: Theme.of(
+ context,
+ ).extension<StackColors>()!.background,
+ appBar: AppBar(
+ leading: AppBarBackButton(
+ onPressed: () => Navigator.of(context).pop(),
+ ),
+ title: Text("My Orders", style: STextStyles.navBarTitle(context)),
+ ),
+ body: SafeArea(
+ child: Padding(padding: const EdgeInsets.all(16), child: child),
+ ),
+ ),
+ ),
+ child: content,
+ ),
+ );
+ }
+}
diff --git a/lib/pages/cakepay/cakepay_send_from_view.dart b/lib/pages/cakepay/cakepay_send_from_view.dart
new file mode 100644
index 0000000..4213625
--- /dev/null
+++ b/lib/pages/cakepay/cakepay_send_from_view.dart
@@ -0,0 +1,408 @@
+import 'dart:async';
+import 'dart:io';
+
+import 'package:flutter/material.dart';
+import 'package:flutter_riverpod/flutter_riverpod.dart';
+import 'package:flutter_svg/svg.dart';
+
+import '../../app_config.dart';
+import '../../models/isar/models/blockchain_data/address.dart';
+import '../../providers/providers.dart';
+import '../../route_generator.dart';
+import '../../themes/coin_icon_provider.dart';
+import '../../themes/stack_colors.dart';
+import '../../themes/theme_providers.dart';
+import '../../utilities/amount/amount.dart';
+import '../../utilities/amount/amount_formatter.dart';
+import '../../utilities/constants.dart';
+import '../../utilities/enums/fee_rate_type_enum.dart';
+import '../../utilities/logger.dart';
+import '../../utilities/text_styles.dart';
+import '../../utilities/util.dart';
+import '../../wallets/crypto_currency/crypto_currency.dart';
+import '../../wallets/isar/providers/wallet_info_provider.dart';
+import '../../wallets/models/tx_data.dart';
+import '../../wallets/wallet/intermediate/external_wallet.dart';
+import '../../widgets/background.dart';
+import '../../widgets/conditional_parent.dart';
+import '../../widgets/custom_buttons/app_bar_icon_button.dart';
+import '../../widgets/desktop/desktop_dialog.dart';
+import '../../widgets/desktop/desktop_dialog_close_button.dart';
+import '../../widgets/rounded_white_container.dart';
+import '../../widgets/stack_dialog.dart';
+import '../../pages_desktop_specific/desktop_home_view.dart';
+import '../home_view/home_view.dart';
+import '../send_view/sub_widgets/building_transaction_dialog.dart';
+import 'cakepay_confirm_send_view.dart';
+
+class CakePaySendFromView extends ConsumerStatefulWidget {
+ const CakePaySendFromView({
+ super.key,
+ this.coin,
+ this.amount,
+ required this.address,
+ required this.orderId,
+ this.shouldPopRoot = false,
+ });
+
+ static const String routeName = "/cakePaySendFrom";
+
+ final CryptoCurrency? coin;
+ final Amount? amount;
+ final String address;
+ final String orderId;
+ final bool shouldPopRoot;
+
+ @override
+ ConsumerState<CakePaySendFromView> createState() =>
+ _CakePaySendFromViewState();
+}
+
+class _CakePaySendFromViewState extends ConsumerState<CakePaySendFromView> {
+ @override
+ Widget build(BuildContext context) {
+ final List<String> walletIds;
+ if (widget.coin != null) {
+ walletIds = ref
+ .watch(pWallets)
+ .wallets
+ .where((e) => e.info.coin == widget.coin)
+ .map((e) => e.walletId)
+ .toList();
+ } else {
+ walletIds = ref.watch(pWallets).wallets.map((e) => e.walletId).toList();
+ }
+
+ final isDesktop = Util.isDesktop;
+
+ return ConditionalParent(
+ condition: !isDesktop,
+ builder: (child) {
+ return Background(
+ child: Scaffold(
+ backgroundColor: Theme.of(
+ context,
+ ).extension<StackColors>()!.background,
+ appBar: AppBar(
+ leading: AppBarBackButton(
+ onPressed: () => Navigator.of(context).pop(),
+ ),
+ title: Text("Send from", style: STextStyles.navBarTitle(context)),
+ ),
+ body: SafeArea(
+ child: Padding(padding: const EdgeInsets.all(16), child: child),
+ ),
+ ),
+ );
+ },
+ child: ConditionalParent(
+ condition: isDesktop,
+ builder: (child) => DesktopDialog(
+ maxHeight: double.infinity,
+ child: Column(
+ children: [
+ Row(
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ children: [
+ Padding(
+ padding: const EdgeInsets.only(left: 32),
+ child: Text(
+ "Send from ${AppConfig.prefix}",
+ style: STextStyles.desktopH3(context),
+ ),
+ ),
+ DesktopDialogCloseButton(
+ onPressedOverride: Navigator.of(
+ context,
+ rootNavigator: widget.shouldPopRoot,
+ ).pop,
+ ),
+ ],
+ ),
+ Padding(
+ padding: const EdgeInsets.only(left: 32, right: 32, bottom: 32),
+ child: child,
+ ),
+ ],
+ ),
+ ),
+ child: Column(
+ mainAxisAlignment: MainAxisAlignment.start,
+ children: [
+ Row(
+ children: [
+ Text(
+ widget.amount != null && widget.coin != null
+ ? "You need to send ${ref.watch(pAmountFormatter(widget.coin!)).format(widget.amount!)}"
+ : "Select a wallet to pay",
+ style: isDesktop
+ ? STextStyles.desktopTextExtraExtraSmall(context)
+ : STextStyles.itemSubtitle(context),
+ ),
+ ],
+ ),
+ const SizedBox(height: 16),
+ ConditionalParent(
+ condition: !isDesktop,
+ builder: (child) => Expanded(child: child),
+ child: ListView.builder(
+ primary: isDesktop ? false : null,
+ shrinkWrap: isDesktop,
+ itemCount: walletIds.length,
+ itemBuilder: (context, index) {
+ return Padding(
+ padding: const EdgeInsets.symmetric(vertical: 4),
+ child: _CakePaySendFromCard(
+ walletId: walletIds[index],
+ amount: widget.amount,
+ address: widget.address,
+ orderId: widget.orderId,
+ ),
+ );
+ },
+ ),
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+}
+
+class _CakePaySendFromCard extends ConsumerStatefulWidget {
+ const _CakePaySendFromCard({
+ required this.walletId,
+ this.amount,
+ required this.address,
+ required this.orderId,
+ });
+
+ final String walletId;
+ final Amount? amount;
+ final String address;
+ final String orderId;
+
+ @override
+ ConsumerState<_CakePaySendFromCard> createState() =>
+ _CakePaySendFromCardState();
+}
+
+class _CakePaySendFromCardState extends ConsumerState<_CakePaySendFromCard> {
+ Future<void> _send() async {
+ final coin = ref.read(pWalletCoin(widget.walletId));
+ final Amount? sendAmount = widget.amount;
+
+ if (sendAmount == null) {
+ await showDialog<dynamic>(
+ context: context,
+ useSafeArea: false,
+ barrierDismissible: true,
+ builder: (context) {
+ return StackDialog(
+ title: "Transaction failed",
+ message: "Payment amount not available yet",
+ rightButton: TextButton(
+ style: Theme.of(context)
+ .extension<StackColors>()!
+ .getSecondaryEnabledButtonStyle(context),
+ child: Text(
+ "Ok",
+ style: STextStyles.button(context).copyWith(
+ color: Theme.of(
+ context,
+ ).extension<StackColors>()!.buttonTextSecondary,
+ ),
+ ),
+ onPressed: () => Navigator.of(context).pop(),
+ ),
+ );
+ },
+ );
+ return;
+ }
+
+ bool wasCancelled = false;
+
+ try {
+ final wallet = ref.read(pWallets).getWallet(widget.walletId);
+
+ unawaited(
+ showDialog<dynamic>(
+ context: context,
+ useSafeArea: false,
+ barrierDismissible: false,
+ builder: (context) {
+ return ConditionalParent(
+ condition: Util.isDesktop,
+ builder: (child) => DesktopDialog(
+ maxWidth: 400,
+ maxHeight: double.infinity,
+ child: Padding(padding: const EdgeInsets.all(32), child: child),
+ ),
+ child: BuildingTransactionDialog(
+ coin: coin,
+ isSpark: false,
+ onCancel: () {
+ wasCancelled = true;
+ Navigator.of(context).pop();
+ },
+ ),
+ );
+ },
+ ),
+ );
+
+ if (wallet is ExternalWallet) {
+ await wallet.init();
+ await wallet.open();
+ }
+
+ final time = Future<dynamic>.delayed(const Duration(milliseconds: 2500));
+
+ final addressType =
+ wallet.cryptoCurrency.getAddressType(widget.address) ??
+ AddressType.unknown;
+
+ final recipient = TxRecipient(
+ address: widget.address,
+ amount: sendAmount,
+ isChange: false,
+ addressType: addressType,
+ );
+
+ final txDataFuture = wallet.prepareSend(
+ txData: TxData(
+ recipients: [recipient],
+ feeRateType: FeeRateType.average,
+ ),
+ );
+
+ final results = await Future.wait([txDataFuture, time]);
+
+ final txData = (results.first as TxData).copyWith(
+ note: "CakePay payment",
+ );
+
+ if (!wasCancelled) {
+ if (mounted) {
+ Navigator.of(context, rootNavigator: true).pop();
+ }
+
+ if (mounted) {
+ await Navigator.of(context).push(
+ RouteGenerator.getRoute<dynamic>(
+ shouldUseMaterialRoute: RouteGenerator.useMaterialPageRoute,
+ builder: (_) => CakePayConfirmSendView(
+ txData: txData,
+ walletId: widget.walletId,
+ routeOnSuccessName: Util.isDesktop
+ ? DesktopHomeView.routeName
+ : HomeView.routeName,
+ orderId: widget.orderId,
+ ),
+ settings: const RouteSettings(
+ name: CakePayConfirmSendView.routeName,
+ ),
+ ),
+ );
+ }
+ }
+ } catch (e, s) {
+ Logging.instance.e("$e\n$s", error: e, stackTrace: s);
+ if (mounted && !wasCancelled) {
+ Navigator.of(context, rootNavigator: true).pop();
+
+ await showDialog<dynamic>(
+ context: context,
+ useSafeArea: false,
+ barrierDismissible: true,
+ builder: (context) {
+ return StackDialog(
+ title: "Transaction failed",
+ message: e.toString(),
+ rightButton: TextButton(
+ style: Theme.of(context)
+ .extension<StackColors>()!
+ .getSecondaryEnabledButtonStyle(context),
+ child: Text(
+ "Ok",
+ style: STextStyles.button(context).copyWith(
+ color: Theme.of(
+ context,
+ ).extension<StackColors>()!.buttonTextSecondary,
+ ),
+ ),
+ onPressed: () => Navigator.of(context).pop(),
+ ),
+ );
+ },
+ );
+ }
+ }
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final coin = ref.watch(pWalletCoin(widget.walletId));
+
+ return RoundedWhiteContainer(
+ padding: const EdgeInsets.all(0),
+ child: MaterialButton(
+ splashColor: Theme.of(context).extension<StackColors>()!.highlight,
+ key: Key("cakePayWalletKey_${widget.walletId}"),
+ padding: const EdgeInsets.all(8),
+ materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
+ shape: RoundedRectangleBorder(
+ borderRadius: BorderRadius.circular(
+ Constants.size.circularBorderRadius,
+ ),
+ ),
+ onPressed: () async {
+ if (mounted) unawaited(_send());
+ },
+ child: Row(
+ children: [
+ Container(
+ decoration: BoxDecoration(
+ color: ref.watch(pCoinColor(coin)).withValues(alpha: 0.5),
+ borderRadius: BorderRadius.circular(
+ Constants.size.circularBorderRadius,
+ ),
+ ),
+ child: Padding(
+ padding: const EdgeInsets.all(6),
+ child: SvgPicture.file(
+ File(ref.watch(coinIconProvider(coin))),
+ width: 24,
+ height: 24,
+ ),
+ ),
+ ),
+ const SizedBox(width: 12),
+ Expanded(
+ child: Column(
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ ref.watch(pWalletName(widget.walletId)),
+ style: STextStyles.titleBold12(context),
+ ),
+ const SizedBox(height: 2),
+ Text(
+ ref
+ .watch(pAmountFormatter(coin))
+ .format(
+ ref.watch(pWalletBalance(widget.walletId)).spendable,
+ ),
+ style: STextStyles.itemSubtitle(context),
+ ),
+ ],
+ ),
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+}
diff --git a/lib/pages/cakepay/cakepay_vendors_view.dart b/lib/pages/cakepay/cakepay_vendors_view.dart
new file mode 100644
index 0000000..dc88f9c
--- /dev/null
+++ b/lib/pages/cakepay/cakepay_vendors_view.dart
@@ -0,0 +1,450 @@
+import 'package:dropdown_button2/dropdown_button2.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter_svg/flutter_svg.dart';
+
+import '../../services/cakepay/cakepay_service.dart';
+import '../../services/cakepay/src/models/card.dart';
+import '../../services/cakepay/src/models/country.dart';
+import '../../services/cakepay/src/models/vendor.dart';
+import '../../themes/stack_colors.dart';
+import '../../utilities/constants.dart';
+import '../../utilities/text_styles.dart';
+import '../../utilities/util.dart';
+import '../../widgets/background.dart';
+import '../../widgets/conditional_parent.dart';
+import '../../widgets/custom_buttons/app_bar_icon_button.dart';
+import '../../widgets/desktop/desktop_dialog.dart';
+import '../../widgets/desktop/desktop_dialog_close_button.dart';
+import '../../widgets/rounded_white_container.dart';
+import '../../widgets/stack_text_field.dart';
+import '../../utilities/assets.dart';
+import 'cakepay_card_detail_view.dart';
+
+class CakePayVendorsView extends StatefulWidget {
+ const CakePayVendorsView({super.key});
+
+ static const String routeName = "/cakePayVendors";
+
+ @override
+ State<CakePayVendorsView> createState() => _CakePayVendorsViewState();
+}
+
+class _CakePayVendorsViewState extends State<CakePayVendorsView> {
+ List<CakePayVendor> _vendors = [];
+ List<CakePayCountry> _countries = [];
+ String? _selectedCountryCode;
+ bool _loading = true;
+ String? _error;
+ final _searchController = TextEditingController();
+ final _searchFocusNode = FocusNode();
+ final _countrySearchController = TextEditingController();
+
+ @override
+ void initState() {
+ super.initState();
+ _loadCountries();
+ _loadVendors();
+ }
+
+ @override
+ void dispose() {
+ _searchController.dispose();
+ _searchFocusNode.dispose();
+ _countrySearchController.dispose();
+ super.dispose();
+ }
+
+ Future<void> _loadCountries() async {
+ final resp = await CakePayService.instance.client.getCountries(pageSize: 500);
+ if (mounted && !resp.hasError && resp.value != null) {
+ // Deduplicate by country code: the API can return entries like both
+ // "US" and "United States" with the same code, which breaks
+ // DropdownButton2 (values must be unique).
+ final seen = <String>{};
+ final unique = <CakePayCountry>[];
+ for (final c in resp.value!) {
+ if (seen.add(c.countryCode)) {
+ unique.add(c);
+ }
+ }
+ setState(() => _countries = unique);
+ }
+ }
+
+ Future<void> _loadVendors() async {
+ setState(() {
+ _loading = true;
+ _error = null;
+ });
+ final resp = await CakePayService.instance.client.getVendors(
+ countryCode: _selectedCountryCode,
+ search: _searchController.text.trim().isNotEmpty
+ ? _searchController.text.trim()
+ : null,
+ );
+ if (mounted) {
+ setState(() {
+ _loading = false;
+ if (!resp.hasError && resp.value != null) {
+ _vendors = resp.value!;
+ } else {
+ _error = resp.exception?.message ?? "Failed to load gift cards";
+ }
+ });
+ }
+ }
+
+ List<CakePayCard> get _allCards {
+ final cards = <CakePayCard>[];
+ for (final vendor in _vendors) {
+ cards.addAll(vendor.cards.where((c) => c.available));
+ }
+ return cards;
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final isDesktop = Util.isDesktop;
+ final cards = _allCards;
+
+ final searchField = ClipRRect(
+ borderRadius: BorderRadius.circular(Constants.size.circularBorderRadius),
+ child: TextField(
+ controller: _searchController,
+ focusNode: _searchFocusNode,
+ style: isDesktop
+ ? STextStyles.desktopTextExtraSmall(context).copyWith(
+ color: Theme.of(
+ context,
+ ).extension<StackColors>()!.textFieldActiveText,
+ )
+ : STextStyles.field(context),
+ decoration:
+ standardInputDecoration(
+ "Search gift cards",
+ _searchFocusNode,
+ context,
+ ).copyWith(
+ prefixIcon: const Padding(
+ padding: EdgeInsets.symmetric(horizontal: 10, vertical: 12),
+ child: Icon(Icons.search, size: 20),
+ ),
+ ),
+ onSubmitted: (_) => _loadVendors(),
+ ),
+ );
+
+ final countryDropdown = _countries.isEmpty
+ ? const SizedBox.shrink()
+ : Padding(
+ padding: const EdgeInsets.only(top: 12),
+ child: ClipRRect(
+ borderRadius: BorderRadius.circular(
+ Constants.size.circularBorderRadius,
+ ),
+ child: DropdownButtonHideUnderline(
+ child: DropdownButton2<String?>(
+ value: _selectedCountryCode,
+ isExpanded: true,
+ hint: Text(
+ "All countries",
+ style: isDesktop
+ ? STextStyles.desktopTextExtraSmall(context).copyWith(
+ color: Theme.of(context)
+ .extension<StackColors>()!
+ .textFieldDefaultSearchIconLeft,
+ )
+ : STextStyles.fieldLabel(context),
+ ),
+ items: [
+ DropdownMenuItem<String?>(
+ value: null,
+ child: Text(
+ "All countries",
+ style: isDesktop
+ ? STextStyles.desktopTextExtraSmall(
+ context,
+ ).copyWith(
+ color: Theme.of(
+ context,
+ ).extension<StackColors>()!.textFieldActiveText,
+ )
+ : STextStyles.w500_14(context),
+ ),
+ ),
+ ..._countries.map(
+ (c) => DropdownMenuItem<String?>(
+ value: c.countryCode,
+ child: Text(
+ c.name,
+ style: isDesktop
+ ? STextStyles.desktopTextExtraSmall(
+ context,
+ ).copyWith(
+ color: Theme.of(context)
+ .extension<StackColors>()!
+ .textFieldActiveText,
+ )
+ : STextStyles.w500_14(context),
+ ),
+ ),
+ ),
+ ],
+ onMenuStateChange: (isOpen) {
+ if (!isOpen) {
+ _countrySearchController.clear();
+ }
+ },
+ onChanged: (value) {
+ setState(() => _selectedCountryCode = value);
+ _loadVendors();
+ },
+ buttonStyleData: ButtonStyleData(
+ decoration: BoxDecoration(
+ color: Theme.of(
+ context,
+ ).extension<StackColors>()!.textFieldDefaultBG,
+ borderRadius: BorderRadius.circular(
+ Constants.size.circularBorderRadius,
+ ),
+ ),
+ ),
+ iconStyleData: IconStyleData(
+ icon: Padding(
+ padding: const EdgeInsets.only(right: 10),
+ child: SvgPicture.asset(
+ Assets.svg.chevronDown,
+ width: 12,
+ height: 6,
+ colorFilter: ColorFilter.mode(
+ Theme.of(context)
+ .extension<StackColors>()!
+ .textFieldActiveSearchIconRight,
+ BlendMode.srcIn,
+ ),
+ ),
+ ),
+ ),
+ dropdownStyleData: DropdownStyleData(
+ offset: const Offset(0, -10),
+ elevation: 0,
+ maxHeight: 300,
+ decoration: BoxDecoration(
+ color: Theme.of(
+ context,
+ ).extension<StackColors>()!.textFieldDefaultBG,
+ borderRadius: BorderRadius.circular(
+ Constants.size.circularBorderRadius,
+ ),
+ ),
+ ),
+ dropdownSearchData: DropdownSearchData<String?>(
+ searchController: _countrySearchController,
+ searchInnerWidgetHeight: 48,
+ searchInnerWidget: TextFormField(
+ controller: _countrySearchController,
+ decoration: InputDecoration(
+ isDense: true,
+ contentPadding: const EdgeInsets.symmetric(
+ horizontal: 16,
+ vertical: 14,
+ ),
+ hintText: "Search...",
+ hintStyle: STextStyles.fieldLabel(context),
+ border: InputBorder.none,
+ ),
+ ),
+ searchMatchFn: (item, searchValue) {
+ if (item.value == null) {
+ return "all countries".contains(
+ searchValue.toLowerCase(),
+ );
+ }
+ final country = _countries
+ .where((c) => c.countryCode == item.value)
+ .firstOrNull;
+ return country?.name.toLowerCase().contains(
+ searchValue.toLowerCase(),
+ ) ??
+ false;
+ },
+ ),
+ menuItemStyleData: const MenuItemStyleData(
+ padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
+ ),
+ ),
+ ),
+ ),
+ );
+
+ final cardsList = _loading
+ ? const Center(
+ child: SizedBox(
+ width: 24,
+ height: 24,
+ child: CircularProgressIndicator(strokeWidth: 2),
+ ),
+ )
+ : cards.isEmpty
+ ? Center(
+ child: Text(
+ _error ?? "No gift cards found",
+ style: isDesktop
+ ? STextStyles.desktopTextSmall(context)
+ : STextStyles.itemSubtitle(context),
+ ),
+ )
+ : ListView.separated(
+ shrinkWrap: isDesktop,
+ primary: isDesktop ? false : null,
+ itemCount: cards.length,
+ separatorBuilder: (_, __) => SizedBox(height: isDesktop ? 16 : 12),
+ itemBuilder: (context, index) {
+ final card = cards[index];
+ return GestureDetector(
+ onTap: () {
+ if (isDesktop) {
+ Navigator.of(context, rootNavigator: true).pop();
+ showDialog<void>(
+ context: context,
+ builder: (_) => CakePayCardDetailView(cardId: card.id),
+ );
+ } else {
+ Navigator.of(context).pushNamed(
+ CakePayCardDetailView.routeName,
+ arguments: card.id,
+ );
+ }
+ },
+ child: RoundedWhiteContainer(
+ child: Row(
+ children: [
+ if (card.cardImageUrl != null)
+ ClipRRect(
+ borderRadius: BorderRadius.circular(4),
+ child: Image.network(
+ card.cardImageUrl!,
+ width: isDesktop ? 60 : 48,
+ height: isDesktop ? 40 : 32,
+ fit: BoxFit.cover,
+ errorBuilder: (_, __, ___) => Icon(
+ Icons.card_giftcard,
+ size: isDesktop ? 40 : 32,
+ ),
+ ),
+ )
+ else
+ Icon(Icons.card_giftcard, size: isDesktop ? 40 : 32),
+ const SizedBox(width: 12),
+ Expanded(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ card.name,
+ style: isDesktop
+ ? STextStyles.desktopTextSmall(context)
+ : STextStyles.titleBold12(context),
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ ),
+ const SizedBox(height: 2),
+ Text(
+ card.denominationRange.isNotEmpty
+ ? "${card.denominationRange} ${card.currencyCode ?? ''}"
+ : card.currencyCode ?? '',
+ style: isDesktop
+ ? STextStyles.desktopTextExtraExtraSmall(
+ context,
+ )
+ : STextStyles.itemSubtitle12(
+ context,
+ ).copyWith(
+ color: Theme.of(
+ context,
+ ).extension<StackColors>()!.textSubtitle1,
+ ),
+ ),
+ ],
+ ),
+ ),
+ Icon(
+ Icons.chevron_right,
+ color: Theme.of(
+ context,
+ ).extension<StackColors>()!.textSubtitle1,
+ ),
+ ],
+ ),
+ ),
+ );
+ },
+ );
+
+ final body = Column(
+ children: [
+ searchField,
+ countryDropdown,
+ SizedBox(height: isDesktop ? 16 : 12),
+ Expanded(child: cardsList),
+ ],
+ );
+
+ return ConditionalParent(
+ condition: isDesktop,
+ builder: (child) => DesktopDialog(
+ maxWidth: 580,
+ maxHeight: 650,
+ child: Column(
+ children: [
+ Row(
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ children: [
+ Padding(
+ padding: const EdgeInsets.only(left: 32),
+ child: Text(
+ "Gift Cards",
+ style: STextStyles.desktopH3(context),
+ ),
+ ),
+ const DesktopDialogCloseButton(),
+ ],
+ ),
+ Expanded(
+ child: Padding(
+ padding: const EdgeInsets.symmetric(
+ horizontal: 32,
+ vertical: 8,
+ ),
+ child: child,
+ ),
+ ),
+ ],
+ ),
+ ),
+ child: ConditionalParent(
+ condition: !isDesktop,
+ builder: (child) => Background(
+ child: Scaffold(
+ backgroundColor: Theme.of(
+ context,
+ ).extension<StackColors>()!.background,
+ appBar: AppBar(
+ leading: AppBarBackButton(
+ onPressed: () => Navigator.of(context).pop(),
+ ),
+ title: Text(
+ "Gift Cards",
+ style: STextStyles.navBarTitle(context),
+ ),
+ ),
+ body: SafeArea(
+ child: Padding(padding: const EdgeInsets.all(16), child: child),
+ ),
+ ),
+ ),
+ child: body,
+ ),
+ );
+ }
+}
diff --git a/lib/pages/wallet_view/wallet_view.dart b/lib/pages/wallet_view/wallet_view.dart
index 8573b2a..9b614f0 100644
--- a/lib/pages/wallet_view/wallet_view.dart
+++ b/lib/pages/wallet_view/wallet_view.dart
@@ -109,6 +109,7 @@ import '../settings_views/wallet_settings_view/wallet_network_settings_view/wall
import '../settings_views/wallet_settings_view/wallet_settings_view.dart';
import '../signing/signing_view.dart';
import '../spark_names/spark_names_home_view.dart';
+import '../more_view/gift_cards_view.dart';
import '../more_view/services_view.dart';
import '../token_view/my_tokens_view.dart';
import 'sub_widgets/transactions_list.dart';
@@ -1361,6 +1362,22 @@ class _WalletViewState extends ConsumerState<WalletView> {
);
},
),
+ WalletNavigationBarItemData(
+ label: "Gift cards",
+ icon: SvgPicture.asset(
+ Assets.svg.creditCard,
+ height: 20,
+ width: 20,
+ color: Theme.of(
+ context,
+ ).extension<StackColors>()!.bottomNavIconIcon,
+ ),
+ onTap: () {
+ Navigator.of(context).pushNamed(
+ GiftCardsView.routeName,
+ );
+ },
+ ),
],
),
),
diff --git a/lib/route_generator.dart b/lib/route_generator.dart
index f4e2a1d..0ce9f63 100644
--- a/lib/route_generator.dart
+++ b/lib/route_generator.dart
@@ -89,7 +89,13 @@ import 'pages/masternodes/create_masternode_view.dart';
import 'pages/masternodes/masternode_details_view.dart';
import 'pages/masternodes/masternodes_home_view.dart';
import 'pages/monkey/monkey_view.dart';
-// import 'pages/more_view/gift_cards_view.dart';
+import 'pages/cakepay/cakepay_card_detail_view.dart';
+import 'pages/cakepay/cakepay_confirm_send_view.dart';
+import 'pages/cakepay/cakepay_order_view.dart';
+import 'pages/cakepay/cakepay_orders_view.dart';
+import 'pages/cakepay/cakepay_send_from_view.dart';
+import 'pages/cakepay/cakepay_vendors_view.dart';
+import 'pages/more_view/gift_cards_view.dart';
import 'pages/more_view/services_view.dart';
import 'pages/namecoin_names/buy_domain_view.dart';
import 'pages/namecoin_names/confirm_name_transaction_view.dart';
@@ -1083,6 +1089,58 @@ class RouteGenerator {
}
return _routeError("${settings.name} invalid args: ${args.toString()}");
+ case CakePayVendorsView.routeName:
+ return getRoute(
+ shouldUseMaterialRoute: useMaterialPageRoute,
+ builder: (_) => const CakePayVendorsView(),
+ settings: RouteSettings(name: settings.name),
+ );
+
+ case CakePayCardDetailView.routeName:
+ if (args is int) {
+ return getRoute(
+ shouldUseMaterialRoute: useMaterialPageRoute,
+ builder: (_) => CakePayCardDetailView(cardId: args),
+ settings: RouteSettings(name: settings.name),
+ );
+ }
+ return _routeError("${settings.name} invalid args: ${args.toString()}");
+
+ case CakePayOrderView.routeName:
+ if (args is String) {
+ return getRoute(
+ shouldUseMaterialRoute: useMaterialPageRoute,
+ builder: (_) => CakePayOrderView(orderId: args),
+ settings: RouteSettings(name: settings.name),
+ );
+ }
+ return _routeError("${settings.name} invalid args: ${args.toString()}");
+
+ case CakePayOrdersView.routeName:
+ return getRoute(
+ shouldUseMaterialRoute: useMaterialPageRoute,
+ builder: (_) => const CakePayOrdersView(),
+ settings: RouteSettings(name: settings.name),
+ );
+
+ case CakePaySendFromView.routeName:
+ if (args is Map<String, dynamic>) {
+ return getRoute(
+ shouldUseMaterialRoute: useMaterialPageRoute,
+ builder: (_) => CakePaySendFromView(
+ address: args['address'] as String,
+ orderId: args['orderId'] as String,
+ coin: args['coin'] as CryptoCurrency?,
+ amount: args['amount'] as Amount?,
+ ),
+ settings: RouteSettings(name: settings.name),
+ );
+ }
+ return _routeError("${settings.name} invalid args: ${args.toString()}");
+
+ case CakePayConfirmSendView.routeName:
+ return _routeError("${settings.name} should be pushed directly");
+
case ShopInBitStep1.routeName:
if (args is ShopInBitOrderModel) {
return getRoute(
Why this scored 24/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.