From ca361b4e31df6ed0973ff34c626c29f99290de00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Calder=C3=B3n?= Date: Thu, 16 Jan 2025 12:02:05 -0300 Subject: [PATCH] Fix cancel on waiting payment (#428) --- src/app/cancel.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/app/cancel.rs b/src/app/cancel.rs index 0564316..637c243 100644 --- a/src/app/cancel.rs +++ b/src/app/cancel.rs @@ -277,13 +277,6 @@ pub async fn cancel_pay_hold_invoice( my_keys: &Keys, request_id: Option, ) -> Result<()> { - if order.hash.is_some() { - // We return funds to seller - if let Some(hash) = order.hash.as_ref() { - ln_client.cancel_hold_invoice(hash).await?; - info!("Order Id {}: Funds returned to seller", &order.id); - } - } let user_pubkey = event.rumor.pubkey.to_string(); let (seller_pubkey, buyer_pubkey) = match (&order.seller_pubkey, &order.buyer_pubkey) { @@ -298,6 +291,14 @@ pub async fn cancel_pay_hold_invoice( return Ok(()); } + if order.hash.is_some() { + // We cancel the hold invoice, if it was paid those funds return to seller + if let Some(hash) = order.hash.as_ref() { + ln_client.cancel_hold_invoice(hash).await?; + info!("Order Id {}: Hold invoice canceled", &order.id); + } + } + if order.creator_pubkey == seller_pubkey.to_string() { // We publish a new replaceable kind nostr event with the status updated // and update on local database the status and new event id