Skip to content

Commit

Permalink
Display invoice amount on share invoice screen
Browse files Browse the repository at this point in the history
It's nice for the user to have this information there.
This is in preparation for displaying additional fees.
  • Loading branch information
da-kami committed Jul 6, 2023
1 parent a98df25 commit 8ef391f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
6 changes: 4 additions & 2 deletions mobile/lib/features/wallet/create_invoice_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:get_10101/common/amount_text.dart';
import 'package:get_10101/common/amount_text_input_form_field.dart';
import 'package:get_10101/common/application/channel_info_service.dart';
import 'package:get_10101/common/domain/model.dart';
import 'package:get_10101/features/wallet/domain/share_invoice.dart';
import 'package:get_10101/features/wallet/share_invoice_screen.dart';
import 'package:get_10101/features/wallet/wallet_change_notifier.dart';
import 'package:get_10101/features/wallet/wallet_screen.dart';
Expand Down Expand Up @@ -177,8 +178,9 @@ class _CreateInvoiceScreenState extends State<CreateInvoiceScreen> {
showValidationHint = false;
walletService.createInvoice(amount!).then((invoice) {
if (invoice != null) {
GoRouter.of(context)
.go(ShareInvoiceScreen.route, extra: invoice);
GoRouter.of(context).go(ShareInvoiceScreen.route,
extra: ShareInvoice(
rawInvoice: invoice, invoiceAmount: amount!));
}
});
} else {
Expand Down
8 changes: 8 additions & 0 deletions mobile/lib/features/wallet/domain/share_invoice.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import '../../../common/domain/model.dart';

class ShareInvoice {
final String rawInvoice;
final Amount invoiceAmount;

ShareInvoice({required this.rawInvoice, required this.invoiceAmount});
}
29 changes: 23 additions & 6 deletions mobile/lib/features/wallet/share_invoice_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:f_logs/f_logs.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get_10101/common/snack_bar.dart';
import 'package:get_10101/common/value_data_row.dart';
import 'package:get_10101/features/wallet/create_invoice_screen.dart';
import 'package:get_10101/features/wallet/domain/wallet_info.dart';
import 'package:get_10101/features/wallet/wallet_change_notifier.dart';
Expand All @@ -15,11 +16,12 @@ import 'package:go_router/go_router.dart';
import 'package:provider/provider.dart';
import 'package:qr_flutter/qr_flutter.dart';
import 'package:share_plus/share_plus.dart';
import 'package:get_10101/features/wallet/domain/share_invoice.dart';

class ShareInvoiceScreen extends StatefulWidget {
static const route = "${WalletScreen.route}/${CreateInvoiceScreen.subRouteName}/$subRouteName";
static const subRouteName = "share_invoice";
final String invoice;
final ShareInvoice invoice;

const ShareInvoiceScreen({super.key, required this.invoice});

Expand Down Expand Up @@ -50,7 +52,7 @@ class _ShareInvoiceScreenState extends State<ShareInvoiceScreen> {
Expanded(
child: Column(crossAxisAlignment: CrossAxisAlignment.center, children: [
const Padding(
padding: EdgeInsets.only(top: 25.0, bottom: 50.0),
padding: EdgeInsets.only(top: 25.0, bottom: 30.0),
child: Text(
"Share payment request",
style: TextStyle(fontSize: 18.0, fontWeight: FontWeight.bold),
Expand All @@ -59,12 +61,27 @@ class _ShareInvoiceScreenState extends State<ShareInvoiceScreen> {
Expanded(
child: Center(
child: QrImageView(
data: widget.invoice,
data: widget.invoice.rawInvoice,
version: QrVersions.auto,
size: 200.0,
padding: const EdgeInsets.all(10.0),
),
),
),
Padding(
padding: const EdgeInsets.only(bottom: 10.0),
child: Center(
child: SizedBox(
// Size of the qr image minus padding
width: 190,
child: ValueDataRow(
type: ValueType.amount,
value: widget.invoice.invoiceAmount,
label: 'Amount',
labelTextStyle: const TextStyle(color: Colors.grey),
valueTextStyle: const TextStyle(color: Colors.grey),
))),
),
]),
),
// Faucet button, only available if we are on regtest
Expand All @@ -80,7 +97,7 @@ class _ShareInvoiceScreenState extends State<ShareInvoiceScreen> {

final router = GoRouter.of(context);
try {
await payInvoiceWithFaucet(widget.invoice);
await payInvoiceWithFaucet(widget.invoice.rawInvoice);
// Pop both create invoice screen and share invoice screen
router.pop();
router.pop();
Expand All @@ -106,7 +123,7 @@ class _ShareInvoiceScreenState extends State<ShareInvoiceScreen> {
padding: buttonSpacing,
child: OutlinedButton(
onPressed: () {
Clipboard.setData(ClipboardData(text: widget.invoice)).then((_) {
Clipboard.setData(ClipboardData(text: widget.invoice.rawInvoice)).then((_) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Invoice copied to clipboard')));
});
Expand All @@ -133,7 +150,7 @@ class _ShareInvoiceScreenState extends State<ShareInvoiceScreen> {
child: Padding(
padding: buttonSpacing,
child: OutlinedButton(
onPressed: () => Share.share(widget.invoice),
onPressed: () => Share.share(widget.invoice.rawInvoice),
style: ElevatedButton.styleFrom(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(5.0))),
Expand Down
3 changes: 2 additions & 1 deletion mobile/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import 'package:get_10101/features/trade/settings_screen.dart';
import 'package:get_10101/features/trade/trade_theme.dart';
import 'package:get_10101/features/wallet/application/wallet_service.dart';
import 'package:get_10101/features/wallet/create_invoice_screen.dart';
import 'package:get_10101/features/wallet/domain/share_invoice.dart';
import 'package:get_10101/features/wallet/seed_screen.dart';
import 'package:get_10101/features/wallet/send_payment_change_notifier.dart';
import 'package:get_10101/features/wallet/share_invoice_screen.dart';
Expand Down Expand Up @@ -137,7 +138,7 @@ class _TenTenOneAppState extends State<TenTenOneApp> {
// Use root navigator so the screen overlays the application shell
parentNavigatorKey: _rootNavigatorKey,
builder: (BuildContext context, GoRouterState state) {
return ShareInvoiceScreen(invoice: state.extra as String);
return ShareInvoiceScreen(invoice: state.extra as ShareInvoice);
},
),
]),
Expand Down

0 comments on commit 8ef391f

Please sign in to comment.