diff --git a/mobile/lib/features/wallet/domain/wallet_history.dart b/mobile/lib/features/wallet/domain/wallet_history.dart index de9ce456a..49edb041e 100644 --- a/mobile/lib/features/wallet/domain/wallet_history.dart +++ b/mobile/lib/features/wallet/domain/wallet_history.dart @@ -80,6 +80,10 @@ abstract class WalletHistoryItemData { rust.WalletHistoryItemType_Lightning type = item.walletType as rust.WalletHistoryItemType_Lightning; + DateTime? expiry = type.expiryTimestamp != null + ? DateTime.fromMillisecondsSinceEpoch(type.expiryTimestamp! * 1000) + : null; + return LightningPaymentData( flow: flow, amount: amount, @@ -88,6 +92,7 @@ abstract class WalletHistoryItemData { preimage: type.paymentPreimage, description: type.description, paymentHash: type.paymentHash, + expiry: expiry, invoice: type.invoice); } } @@ -97,6 +102,7 @@ class LightningPaymentData extends WalletHistoryItemData { final String? preimage; final String description; final String? invoice; + final DateTime? expiry; LightningPaymentData( {required super.flow, @@ -106,6 +112,7 @@ class LightningPaymentData extends WalletHistoryItemData { required this.preimage, required this.description, required this.invoice, + required this.expiry, required this.paymentHash}); @override diff --git a/mobile/lib/features/wallet/wallet_history_item.dart b/mobile/lib/features/wallet/wallet_history_item.dart index 306ab457a..03f3387cb 100644 --- a/mobile/lib/features/wallet/wallet_history_item.dart +++ b/mobile/lib/features/wallet/wallet_history_item.dart @@ -167,6 +167,10 @@ class LightningPaymentHistoryItem extends WalletHistoryItem { @override List getDetails() { return [ + Visibility( + visible: data.expiry != null, + child: HistoryDetail(label: "Expiry time", value: WalletHistoryItem.dateFormat.format(data.expiry ?? DateTime.utc(0))), + ), HistoryDetail(label: "Invoice description", value: data.description), Visibility( visible: data.invoice != null, diff --git a/mobile/native/src/api.rs b/mobile/native/src/api.rs index 65be218b1..788d38151 100644 --- a/mobile/native/src/api.rs +++ b/mobile/native/src/api.rs @@ -85,6 +85,7 @@ pub enum WalletHistoryItemType { description: String, payment_preimage: Option, invoice: Option, + expiry_timestamp: Option, }, Trade { order_id: String, diff --git a/mobile/native/src/ln_dlc/mod.rs b/mobile/native/src/ln_dlc/mod.rs index cf21f3c39..4435a4598 100644 --- a/mobile/native/src/ln_dlc/mod.rs +++ b/mobile/native/src/ln_dlc/mod.rs @@ -347,18 +347,23 @@ fn keep_wallet_balance_and_history_up_to_date(node: &Node) -> Result<()> { None => return None, }; - let expired = match details.invoice.as_deref().map(Invoice::from_str) { + let decoded_invoice = match details.invoice.as_deref().map(Invoice::from_str) { Some(Ok(inv)) => { tracing::info!(?inv, "Decoded invoice"); - inv.is_expired() + Some(inv) } Some(Err(err)) => { tracing::warn!(%err, "Failed to deserialize invoice"); - false + None } - None => false, + None => None, }; + let expired = decoded_invoice + .as_ref() + .map(|inv| inv.is_expired()) + .unwrap_or(false); + let status = match details.status { HTLCStatus::Pending if expired => api::Status::Expired, HTLCStatus::Pending => api::Status::Pending, @@ -391,11 +396,16 @@ fn keep_wallet_balance_and_history_up_to_date(node: &Node) -> Result<()> { payment_hash, } } else { + let expiry_timestamp = decoded_invoice + .and_then(|inv| inv.timestamp().checked_add(inv.expiry_time())) + .map(|time| OffsetDateTime::from(time).unix_timestamp() as u64); + api::WalletHistoryItemType::Lightning { payment_hash, description: details.description.clone(), payment_preimage: details.preimage.clone(), invoice: details.invoice.clone(), + expiry_timestamp, } };