-
Notifications
You must be signed in to change notification settings - Fork 25
feat(bond): support Phase 1.5 anti-abuse bond invoice flow #592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a51b844
feat(bond): support Phase 1.5 anti-abuse bond invoice flow
Catrya a28dfe8
pay deposit entry point from trade detail
Catrya b969fae
fix overlapping
Catrya 0c17e0e
flatten pay-bond screen background to match scaffold
Catrya 2442580
align cancel dialog with trade cancel modal UI
Catrya 7e4b32c
show bond amount on pay-bond screen
Catrya fb75c27
guard pay-bond prompt against zero amount
Catrya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
235 changes: 235 additions & 0 deletions
235
lib/features/order/screens/pay_bond_invoice_screen.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,235 @@ | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:flutter/services.dart'; | ||
| import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
| import 'package:go_router/go_router.dart'; | ||
| import 'package:qr_flutter/qr_flutter.dart'; | ||
| import 'package:share_plus/share_plus.dart'; | ||
| import 'package:url_launcher/url_launcher.dart'; | ||
| import 'package:mostro_mobile/core/app_theme.dart'; | ||
| import 'package:mostro_mobile/features/order/providers/order_notifier_provider.dart'; | ||
| import 'package:mostro_mobile/features/order/widgets/order_app_bar.dart'; | ||
| import 'package:mostro_mobile/generated/l10n.dart'; | ||
| import 'package:mostro_mobile/services/logger_service.dart'; | ||
| import 'package:mostro_mobile/shared/utils/snack_bar_helper.dart'; | ||
|
|
||
| class PayBondInvoiceScreen extends ConsumerWidget { | ||
| final String orderId; | ||
|
|
||
| const PayBondInvoiceScreen({super.key, required this.orderId}); | ||
|
|
||
| Future<void> _confirmAndCancel( | ||
| BuildContext context, | ||
| WidgetRef ref, | ||
| ) async { | ||
| final s = S.of(context)!; | ||
| final confirmed = await showDialog<bool>( | ||
| context: context, | ||
| builder: (dialogContext) => AlertDialog( | ||
| backgroundColor: AppTheme.backgroundCard, | ||
| shape: RoundedRectangleBorder( | ||
| borderRadius: BorderRadius.circular(16), | ||
| side: BorderSide(color: Colors.white.withValues(alpha: 0.1)), | ||
| ), | ||
| title: Text( | ||
| s.cancelTradeDialogTitle, | ||
| style: const TextStyle( | ||
| color: AppTheme.textPrimary, | ||
| fontSize: 18, | ||
| fontWeight: FontWeight.w600, | ||
| ), | ||
| ), | ||
| content: Text( | ||
| s.areYouSureCancel, | ||
| style: const TextStyle( | ||
| color: AppTheme.textSecondary, | ||
| fontSize: 14, | ||
| height: 1.5, | ||
| ), | ||
| ), | ||
| actions: [ | ||
| TextButton( | ||
| onPressed: () => Navigator.of(dialogContext).pop(false), | ||
| child: Text( | ||
| s.no, | ||
| style: const TextStyle( | ||
| color: AppTheme.textSecondary, | ||
| fontSize: 16, | ||
| fontWeight: FontWeight.w500, | ||
| ), | ||
| textAlign: TextAlign.center, | ||
| ), | ||
| ), | ||
| const SizedBox(width: 12), | ||
| ElevatedButton( | ||
| onPressed: () => Navigator.of(dialogContext).pop(true), | ||
| style: ElevatedButton.styleFrom( | ||
| backgroundColor: AppTheme.activeColor, | ||
| foregroundColor: Colors.black, | ||
| shape: RoundedRectangleBorder( | ||
| borderRadius: BorderRadius.circular(8), | ||
| ), | ||
| padding: | ||
| const EdgeInsets.symmetric(horizontal: 12, vertical: 12), | ||
| ), | ||
| child: Text( | ||
| s.yes, | ||
| style: const TextStyle( | ||
| fontSize: 16, | ||
| fontWeight: FontWeight.w500, | ||
| ), | ||
| textAlign: TextAlign.center, | ||
| ), | ||
| ), | ||
| ], | ||
| ), | ||
| ); | ||
|
|
||
| if (confirmed != true) return; | ||
| if (!context.mounted) return; | ||
|
|
||
| final orderNotifier = ref.read(orderNotifierProvider(orderId).notifier); | ||
| context.go('/'); | ||
| await orderNotifier.cancelOrder(); | ||
| } | ||
|
|
||
| Future<void> _shareInvoice(BuildContext context, String lnInvoice) async { | ||
| final messenger = ScaffoldMessenger.of(context); | ||
| final mediaQuery = MediaQuery.of(context); | ||
| final errorMessage = S.of(context)!.failedToShareInvoice; | ||
|
|
||
| try { | ||
| final uri = Uri.parse('lightning:$lnInvoice'); | ||
| if (await canLaunchUrl(uri)) { | ||
| await launchUrl(uri); | ||
| logger.i('Launched Lightning wallet with bond invoice'); | ||
| } else { | ||
| await Share.share(lnInvoice); | ||
| logger.i('Shared bond invoice via share sheet'); | ||
| } | ||
| } catch (e) { | ||
| logger.e('Failed to share bond invoice: $e'); | ||
| SnackBarHelper.showTopSnackBarAsync( | ||
| messenger: messenger, | ||
| screenHeight: mediaQuery.size.height, | ||
| statusBarHeight: mediaQuery.padding.top, | ||
| message: errorMessage, | ||
| duration: const Duration(seconds: 3), | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| @override | ||
| Widget build(BuildContext context, WidgetRef ref) { | ||
| final s = S.of(context)!; | ||
| final orderState = ref.watch(orderNotifierProvider(orderId)); | ||
| final lnInvoice = orderState.paymentRequest?.lnInvoice ?? ''; | ||
| final bondAmount = orderState.paymentRequest?.order?.amount; | ||
|
|
||
| return Scaffold( | ||
| backgroundColor: AppTheme.dark1, | ||
| appBar: OrderAppBar(title: s.bondScreenTitle), | ||
| body: SingleChildScrollView( | ||
| padding: EdgeInsets.fromLTRB( | ||
| 16, | ||
| 16, | ||
| 16, | ||
| 16 + MediaQuery.of(context).viewPadding.bottom, | ||
| ), | ||
| child: Column( | ||
| crossAxisAlignment: CrossAxisAlignment.stretch, | ||
| children: [ | ||
| Text( | ||
| s.bondExplanation, | ||
| style: const TextStyle( | ||
| color: AppTheme.cream1, | ||
| fontSize: 15, | ||
| height: 1.4, | ||
| ), | ||
| ), | ||
| if (bondAmount != null && bondAmount > 0) ...[ | ||
| const SizedBox(height: 16), | ||
| Text( | ||
| s.bondPayInvoicePrompt(bondAmount), | ||
| style: const TextStyle( | ||
| color: AppTheme.cream1, | ||
| fontSize: 15, | ||
| height: 1.4, | ||
| fontWeight: FontWeight.w500, | ||
| ), | ||
| ), | ||
| ], | ||
| const SizedBox(height: 20), | ||
| Center( | ||
| child: Container( | ||
| padding: const EdgeInsets.all(8.0), | ||
| color: AppTheme.cream1, | ||
| child: QrImageView( | ||
| data: lnInvoice, | ||
| version: QrVersions.auto, | ||
| size: 250.0, | ||
| backgroundColor: AppTheme.cream1, | ||
| errorStateBuilder: (cxt, err) { | ||
| return Center( | ||
| child: Text( | ||
| s.failedToGenerateQR, | ||
| textAlign: TextAlign.center, | ||
| ), | ||
| ); | ||
| }, | ||
| ), | ||
| ), | ||
| ), | ||
| const SizedBox(height: 20), | ||
| Row( | ||
| mainAxisAlignment: MainAxisAlignment.spaceEvenly, | ||
| children: [ | ||
| ElevatedButton.icon( | ||
| onPressed: lnInvoice.isEmpty | ||
| ? null | ||
| : () { | ||
| Clipboard.setData(ClipboardData(text: lnInvoice)); | ||
| logger.i('Copied bond invoice to clipboard'); | ||
| SnackBarHelper.showTopSnackBar( | ||
| context, | ||
| s.invoiceCopiedToClipboard, | ||
| duration: const Duration(seconds: 2), | ||
| ); | ||
| }, | ||
| icon: const Icon(Icons.copy), | ||
| label: Text(s.copy), | ||
| style: ElevatedButton.styleFrom( | ||
| backgroundColor: AppTheme.mostroGreen, | ||
| ), | ||
| ), | ||
| ElevatedButton.icon( | ||
| onPressed: lnInvoice.isEmpty | ||
| ? null | ||
| : () => _shareInvoice(context, lnInvoice), | ||
| icon: const Icon(Icons.share), | ||
| label: Text(s.share), | ||
| style: ElevatedButton.styleFrom( | ||
| backgroundColor: AppTheme.mostroGreen, | ||
| ), | ||
| ), | ||
| ], | ||
| ), | ||
| const SizedBox(height: 20), | ||
| Row( | ||
| mainAxisAlignment: MainAxisAlignment.center, | ||
| children: [ | ||
| ElevatedButton( | ||
| onPressed: () => _confirmAndCancel(context, ref), | ||
| style: ElevatedButton.styleFrom( | ||
| foregroundColor: Colors.white, | ||
| backgroundColor: Colors.red, | ||
| ), | ||
| child: Text(s.cancel), | ||
| ), | ||
| ], | ||
| ), | ||
| ], | ||
| ), | ||
| ), | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.