From bc779e3269094bf2a527cb8e5270abc967daa2fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Granh=C3=A3o?= <32176319+danielgranhao@users.noreply.github.com> Date: Fri, 17 Jan 2025 13:26:42 +0000 Subject: [PATCH] Fix amountless receiver amount and waiting fee acceptance condition (#670) --- lib/core/src/model.rs | 11 ++--------- lib/core/src/persist/mod.rs | 2 +- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/lib/core/src/model.rs b/lib/core/src/model.rs index cedadea..61ad1b3 100644 --- a/lib/core/src/model.rs +++ b/lib/core/src/model.rs @@ -774,7 +774,7 @@ pub(crate) struct ChainSwap { pub(crate) actual_payer_amount_sat: Option, /// Receiver amount defined at swap creation pub(crate) receiver_amount_sat: u64, - /// The final receiver amount, in case of an over/underpayment that has been accepted + /// The final receiver amount, in case of an amountless swap for which fees have been accepted pub(crate) accepted_receiver_amount_sat: Option, pub(crate) claim_fees_sat: u64, /// The [ChainPair] chosen on swap creation @@ -904,15 +904,8 @@ impl ChainSwap { Ok(create_response_json) } - pub(crate) fn is_amount_mismatch(&self) -> bool { - match self.actual_payer_amount_sat { - Some(actual_amount) => actual_amount != self.payer_amount_sat, - None => false, - } - } - pub(crate) fn is_waiting_fee_acceptance(&self) -> bool { - self.is_amount_mismatch() && self.accepted_receiver_amount_sat.is_none() + self.payer_amount_sat == 0 && self.accepted_receiver_amount_sat.is_none() } } diff --git a/lib/core/src/persist/mod.rs b/lib/core/src/persist/mod.rs index 7a490b4..1719c11 100644 --- a/lib/core/src/persist/mod.rs +++ b/lib/core/src/persist/mod.rs @@ -597,7 +597,7 @@ impl Persister { maybe_chain_swap_actual_payer_amount_sat, maybe_chain_swap_payer_amount_sat, ) { - (Some(actual), Some(expected)) if actual != expected => actual, // For over/underpaid chain swaps WaitingFeeAcceptance, show zero fees + (Some(actual), Some(0)) => actual, // For amountless chain swaps WaitingFeeAcceptance, show zero fees _ => maybe_chain_swap_receiver_amount_sat.unwrap_or(0), }, };