Skip to content

Commit

Permalink
apply payment status
Browse files Browse the repository at this point in the history
  • Loading branch information
ubbabeck committed Sep 22, 2023
1 parent dd8d828 commit 27e88dc
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 27 deletions.
5 changes: 3 additions & 2 deletions lib/background/payment_hash_poller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ class PaymentHashPoller {
);
for (var payment in paymentList) {
final detailsData = payment.details.data;
final isPaymentReceived =
!payment.pending && detailsData is LnPaymentDetails && detailsData.paymentHash == paymentHash;
final isPaymentReceived = payment.status == PaymentStatus.Complete &&
detailsData is LnPaymentDetails &&
detailsData.paymentHash == paymentHash;
if (isPaymentReceived) {
print("Payment received! Stop polling.");
timer.cancel();
Expand Down
6 changes: 3 additions & 3 deletions lib/models/payment_minutiae.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class PaymentMinutiae {
final int amountSat;
final bool hasMetadata;
final bool isKeySend;
final bool isPending;
final PaymentStatus status;

const PaymentMinutiae({
required this.id,
Expand All @@ -49,7 +49,7 @@ class PaymentMinutiae {
required this.amountSat,
required this.hasMetadata,
required this.isKeySend,
required this.isPending,
required this.status,
});

factory PaymentMinutiae.fromPayment(Payment payment, BreezTranslations texts) {
Expand All @@ -72,7 +72,7 @@ class PaymentMinutiae {
amountSat: factory._amountSat(),
hasMetadata: factory._hasMetadata(),
isKeySend: factory._isKeySend(),
isPending: payment.pending,
status: payment.status,
);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:breez_sdk/bridge_generated.dart';
import 'package:breez_translations/breez_translations_locales.dart';
import 'package:c_breez/models/payment_minutiae.dart';
import 'package:c_breez/routes/home/widgets/payments_list/dialog/tx_widget.dart';
Expand All @@ -16,7 +17,7 @@ class ClosedChannelPaymentDetailsWidget extends StatelessWidget {
final themeData = Theme.of(context);
final texts = context.texts();

if (!paymentMinutiae.isPending) {
if (paymentMinutiae.status == PaymentStatus.Complete) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:breez_sdk/bridge_generated.dart';
import 'package:breez_translations/breez_translations_locales.dart';
import 'package:c_breez/models/payment_minutiae.dart';
import 'package:c_breez/routes/home/widgets/payments_list/dialog/closed_channel_payment_details.dart';
Expand All @@ -19,7 +20,7 @@ class PaymentDetailsDialogClosedChannelDialog extends StatelessWidget {
return AlertDialog(
titlePadding: const EdgeInsets.fromLTRB(24, 22, 0, 16),
title: Text(
paymentMinutiae.isPending
paymentMinutiae.status == PaymentStatus.Pending
? texts.payment_details_dialog_closed_channel_title_pending
: texts.payment_details_dialog_closed_channel_title,
style: themeData.dialogTheme.titleTextStyle,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:auto_size_text/auto_size_text.dart';
import 'package:breez_sdk/bridge_generated.dart';
import 'package:breez_translations/breez_translations_locales.dart';
import 'package:c_breez/models/payment_minutiae.dart';
import 'package:flutter/material.dart';
Expand All @@ -18,7 +19,7 @@ class PaymentDetailsDialogExpiration extends StatelessWidget {
final texts = context.texts();
final themeData = Theme.of(context);

if (!paymentMinutiae.isPending) {
if (paymentMinutiae.status == PaymentStatus.Complete) {
return Container();
}

Expand Down
17 changes: 9 additions & 8 deletions lib/routes/home/widgets/payments_list/payment_item_amount.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ class PaymentItemAmount extends StatelessWidget {
);

return Column(
mainAxisAlignment: _paymentMinutiae.feeMilliSat == 0 || _paymentMinutiae.isPending
? MainAxisAlignment.center
: MainAxisAlignment.spaceAround,
mainAxisAlignment:
_paymentMinutiae.feeMilliSat == 0 || _paymentMinutiae.status == PaymentStatus.Pending
? MainAxisAlignment.center
: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
Expand All @@ -59,7 +60,7 @@ class PaymentItemAmount extends StatelessWidget {
: texts.wallet_dashboard_payment_item_balance_negative(amount),
style: themeData.paymentItemAmountTextStyle,
),
(fee == 0 || _paymentMinutiae.isPending)
(fee == 0 || _paymentMinutiae.status == PaymentStatus.Pending)
? const SizedBox()
: Text(
hideBalance
Expand Down Expand Up @@ -102,7 +103,7 @@ void main() async {
feeMsat: 0,
paymentTime: 1661791810,
amountMsat: 4321000,
pending: false,
status: PaymentStatus.Complete,
description: "",
details: PaymentDetails.ln(
data: LnPaymentDetails(
Expand All @@ -128,7 +129,7 @@ void main() async {
feeMsat: 1234,
paymentTime: 1661791810,
amountMsat: 4321000,
pending: true,
status: PaymentStatus.Complete,
description: "",
details: PaymentDetails.ln(
data: LnPaymentDetails(
Expand All @@ -154,7 +155,7 @@ void main() async {
feeMsat: 1234,
paymentTime: 1661791810,
amountMsat: 4321000,
pending: false,
status: PaymentStatus.Complete,
description: "",
details: PaymentDetails.ln(
data: LnPaymentDetails(
Expand All @@ -180,7 +181,7 @@ void main() async {
feeMsat: 1234,
paymentTime: 1661791810,
amountMsat: 4321000,
pending: false,
status: PaymentStatus.Complete,
description: "",
details: PaymentDetails.ln(
data: LnPaymentDetails(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class PaymentItemSubtitle extends StatelessWidget {
BreezDateUtils.formatTimelineRelative(_paymentMinutiae.paymentTime),
style: subtitleTextStyle,
),
_paymentMinutiae.isPending
_paymentMinutiae.status == PaymentStatus.Pending
? Text(
texts.wallet_dashboard_payment_item_balance_pending_suffix,
style: subtitleTextStyle.copyWith(
Expand All @@ -55,7 +55,7 @@ void main() {
feeMsat: 1234,
paymentTime: 1661791810,
amountMsat: 4321000,
pending: false,
status: PaymentStatus.Complete,
description: "",
details: PaymentDetails.ln(
data: LnPaymentDetails(
Expand All @@ -81,7 +81,7 @@ void main() {
feeMsat: 1234,
paymentTime: 1661791810,
amountMsat: 4321000,
pending: true,
status: PaymentStatus.Pending,
description: "",
details: PaymentDetails.ln(
data: LnPaymentDetails(
Expand Down
6 changes: 3 additions & 3 deletions lib/routes/home/widgets/payments_list/payment_item_title.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void main() {
feeMsat: 0,
paymentTime: 1661791810,
amountMsat: 4321000,
pending: false,
status: PaymentStatus.Complete,
description: "",
details: PaymentDetails.ln(
data: LnPaymentDetails(
Expand All @@ -62,7 +62,7 @@ void main() {
feeMsat: 0,
paymentTime: 1661791810,
amountMsat: 4321000,
pending: false,
status: PaymentStatus.Complete,
description: "A long title\nwith a new line",
details: PaymentDetails.ln(
data: LnPaymentDetails(
Expand All @@ -88,7 +88,7 @@ void main() {
feeMsat: 0,
paymentTime: 1661791810,
amountMsat: 4321000,
pending: false,
status: PaymentStatus.Complete,
description: "A short title",
details: PaymentDetails.ln(
data: LnPaymentDetails(
Expand Down
6 changes: 3 additions & 3 deletions lib/routes/home/widgets/payments_list/payments_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void main() async {
feeMsat: 0,
paymentTime: 1661791810,
amountMsat: 4321000,
pending: false,
status: PaymentStatus.Complete,
description: "A title",
details: PaymentDetails.ln(
data: LnPaymentDetails(
Expand All @@ -88,7 +88,7 @@ void main() async {
feeMsat: 12,
paymentTime: 1661791810,
amountMsat: 4321000,
pending: false,
status: PaymentStatus.Complete,
description: "A title",
details: PaymentDetails.ln(
data: LnPaymentDetails(
Expand All @@ -110,7 +110,7 @@ void main() async {
feeMsat: 3456,
paymentTime: DateTime.now().millisecondsSinceEpoch ~/ 1000,
amountMsat: 4321000,
pending: false,
status: PaymentStatus.Complete,
description: "A title",
details: const PaymentDetails.ln(
data: LnPaymentDetails(
Expand Down
4 changes: 2 additions & 2 deletions test/models/payment_minutiae_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ PaymentMinutiae make({
paymentTime: paymentTime,
amountMsat: amountMilliSat,
feeMsat: feeMilliSat,
pending: false,
status: PaymentStatus.Complete,
description: description,
details: const PaymentDetails.closedChannel(
data: ClosedChannelPaymentDetails(
Expand Down Expand Up @@ -313,7 +313,7 @@ PaymentMinutiae makeLnPayment({
paymentTime: 3,
amountMsat: 2,
feeMsat: 1,
pending: false,
status: PaymentStatus.Complete,
description: "description",
details: PaymentDetails.ln(
data: LnPaymentDetails(
Expand Down

0 comments on commit 27e88dc

Please sign in to comment.