Skip to content

Commit 2e62f58

Browse files
committed
app: recv: allow editing offer amount and/or description
1 parent f99ea30 commit 2e62f58

File tree

3 files changed

+95
-27
lines changed

3 files changed

+95
-27
lines changed

app/lib/design_mode/main.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ import 'package:lexeapp/route/open_channel.dart'
7272
show OpenChannelConfirmPage, OpenChannelPage;
7373
import 'package:lexeapp/route/payment_detail.dart' show PaymentDetailPageInner;
7474
import 'package:lexeapp/route/receive/page.dart'
75-
show ReceivePaymentEditInvoicePage, ReceivePaymentPage;
76-
import 'package:lexeapp/route/receive/state.dart' show LnInvoiceInputs;
75+
show ReceivePaymentEditPage, ReceivePaymentPage;
76+
import 'package:lexeapp/route/receive/state.dart' show AmountDescription;
7777
import 'package:lexeapp/route/restore.dart'
7878
show RestoreChooseWalletPage, RestorePage, RestorePasswordPage;
7979
import 'package:lexeapp/route/scan.dart' show ScanPage;
@@ -574,9 +574,9 @@ class _LexeDesignPageState extends State<LexeDesignPage> {
574574
),
575575
),
576576
Component(
577-
"ReceivePaymentEditInvoicePage",
578-
(context) => const ReceivePaymentEditInvoicePage(
579-
prev: LnInvoiceInputs(amountSats: null, description: null),
577+
"ReceivePaymentEditPage",
578+
(context) => const ReceivePaymentEditPage(
579+
prev: AmountDescription(amountSats: null, description: null),
580580
),
581581
),
582582
Component(

app/lib/route/receive/page.dart

Lines changed: 58 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import 'package:lexeapp/logger.dart';
3333
import 'package:lexeapp/result.dart';
3434
import 'package:lexeapp/route/receive/state.dart'
3535
show
36+
AmountDescription,
3637
BtcAddrInputs,
3738
BtcAddrKind,
3839
LnInvoiceInputs,
@@ -468,27 +469,28 @@ class ReceivePaymentPageInnerState extends State<ReceivePaymentPageInner> {
468469
// Open an edit page when we press a "+ Amount" or "Edit" button for the given
469470
// page.
470471
Future<void> openEditPage(PaymentOfferKind kind) async {
471-
// Only support setting amount/desc for invoices atm.
472-
if (kind != PaymentOfferKind.lightningInvoice) return;
473-
474472
switch (kind) {
475473
case PaymentOfferKind.lightningInvoice:
476-
await this.openEditInvoicePage();
474+
await this.openEditLnInvoicePage();
475+
return;
476+
case PaymentOfferKind.lightningOffer:
477+
await this.openEditLnOfferPage();
477478
return;
478-
479479
// Other kinds don't support editing amount/description yet.
480480
default:
481481
return;
482482
}
483483
}
484484

485-
Future<void> openEditInvoicePage() async {
486-
final prev = this.lnInvoiceInputs.value;
485+
Future<void> openEditLnInvoicePage() async {
486+
final prevInvoice = this.lnInvoiceInputs.value;
487+
final prev = AmountDescription(
488+
amountSats: prevInvoice.amountSats,
489+
description: prevInvoice.description,
490+
);
487491

488-
final LnInvoiceInputs? flowResult = await Navigator.of(this.context).push(
489-
MaterialPageRoute(
490-
builder: (_) => ReceivePaymentEditInvoicePage(prev: prev),
491-
),
492+
final AmountDescription? flowResult = await Navigator.of(this.context).push(
493+
MaterialPageRoute(builder: (_) => ReceivePaymentEditPage(prev: prev)),
492494
);
493495

494496
if (!this.mounted || flowResult == null || flowResult == prev) return;
@@ -505,7 +507,43 @@ class ReceivePaymentPageInnerState extends State<ReceivePaymentPageInner> {
505507
);
506508

507509
// Update inputs to fetch new invoice.
508-
this.lnInvoiceInputs.value = flowResult;
510+
final inputs = LnInvoiceInputs(
511+
amountSats: flowResult.amountSats,
512+
description: flowResult.description,
513+
);
514+
this.lnInvoiceInputs.value = inputs;
515+
}
516+
517+
Future<void> openEditLnOfferPage() async {
518+
final prevOffer = this.lnOfferInputs.value;
519+
final prev = AmountDescription(
520+
amountSats: prevOffer.amountSats,
521+
description: prevOffer.description,
522+
);
523+
524+
final AmountDescription? flowResult = await Navigator.of(this.context).push(
525+
MaterialPageRoute(builder: (_) => ReceivePaymentEditPage(prev: prev)),
526+
);
527+
528+
if (!this.mounted || flowResult == null || flowResult == prev) return;
529+
530+
// Clear LN offer code so it's clear we're fetching a new one.
531+
final lnOfferPaymentOffer = this.lnOfferPaymentOffer();
532+
final lnOffer = lnOfferPaymentOffer.value;
533+
lnOfferPaymentOffer.value = PaymentOffer(
534+
kind: lnOffer.kind,
535+
code: null,
536+
expiresAt: null,
537+
amountSats: flowResult.amountSats,
538+
description: flowResult.description,
539+
);
540+
541+
// Update inputs to fetch new offer.
542+
final inputs = LnOfferInputs(
543+
amountSats: flowResult.amountSats,
544+
description: flowResult.description,
545+
);
546+
this.lnOfferInputs.value = inputs;
509547
}
510548

511549
@override
@@ -1283,20 +1321,18 @@ class CopyCodeButtonOrPlaceholder extends StatelessWidget {
12831321
// }
12841322
// }
12851323

1286-
/// A page for the user to set a desired amount and optional description on
1287-
/// their payment offer.
1288-
class ReceivePaymentEditInvoicePage extends StatefulWidget {
1289-
const ReceivePaymentEditInvoicePage({super.key, required this.prev});
1324+
/// A page for the user to set an optional amount and/or optional description on
1325+
/// their inbound payment details.
1326+
class ReceivePaymentEditPage extends StatefulWidget {
1327+
const ReceivePaymentEditPage({super.key, required this.prev});
12901328

1291-
final LnInvoiceInputs prev;
1329+
final AmountDescription prev;
12921330

12931331
@override
1294-
State<ReceivePaymentEditInvoicePage> createState() =>
1295-
_ReceivePaymentEditInvoicePageState();
1332+
State<ReceivePaymentEditPage> createState() => _ReceivePaymentEditPageState();
12961333
}
12971334

1298-
class _ReceivePaymentEditInvoicePageState
1299-
extends State<ReceivePaymentEditInvoicePage> {
1335+
class _ReceivePaymentEditPageState extends State<ReceivePaymentEditPage> {
13001336
final GlobalKey<FormFieldState<String>> amountFieldKey = GlobalKey();
13011337
final GlobalKey<FormFieldState<String>> descriptionFieldKey = GlobalKey();
13021338

@@ -1331,7 +1367,7 @@ class _ReceivePaymentEditInvoicePageState
13311367
description = null;
13321368
}
13331369

1334-
final flowResult = LnInvoiceInputs(
1370+
final flowResult = AmountDescription(
13351371
amountSats: amountSats,
13361372
description: description,
13371373
);

app/lib/route/receive/state.dart

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,38 @@ enum BtcAddrKind {
2626
};
2727
}
2828

29+
/// Amount and description.
30+
@immutable
31+
class AmountDescription {
32+
const AmountDescription({
33+
required this.amountSats,
34+
required this.description,
35+
});
36+
37+
final int? amountSats;
38+
final String? description;
39+
40+
@override
41+
String toString() {
42+
return "AmountDescription(amountSats: $amountSats, description: $description)";
43+
}
44+
45+
@override
46+
bool operator ==(Object other) {
47+
return identical(this, other) ||
48+
(other.runtimeType == this.runtimeType &&
49+
other is AmountDescription &&
50+
(identical(other.amountSats, this.amountSats) ||
51+
other.amountSats == this.amountSats) &&
52+
(identical(other.description, this.description) ||
53+
other.description == this.description));
54+
}
55+
56+
@override
57+
int get hashCode =>
58+
Object.hash(this.runtimeType, this.amountSats, this.description);
59+
}
60+
2961
/// The inputs used to generate a Lightning invoice [PaymentOffer].
3062
@immutable
3163
class LnInvoiceInputs {

0 commit comments

Comments
 (0)