From 668d34080d1859e45049d773d33826dfe4723739 Mon Sep 17 00:00:00 2001 From: Daniel Karzel Date: Fri, 19 Mar 2021 17:40:14 +1100 Subject: [PATCH] Show the actual BTC amount and fee to be swapped --- swap/src/bin/swap.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/swap/src/bin/swap.rs b/swap/src/bin/swap.rs index e4c9f102..0ec610b5 100644 --- a/swap/src/bin/swap.rs +++ b/swap/src/bin/swap.rs @@ -327,7 +327,7 @@ async fn determine_btc_to_swap( // TODO: Also wait for more funds if balance < dust let initial_balance = initial_balance.await?; - if initial_balance == Amount::ZERO { + let balance = if initial_balance == Amount::ZERO { info!( "Please deposit the BTC you want to swap to {} (max {})", get_new_address.await?, @@ -339,23 +339,23 @@ async fn determine_btc_to_swap( .context("Failed to wait for Bitcoin deposit")?; info!("Received {}", new_balance); + new_balance } else { info!("Found {} in wallet", initial_balance); - } + initial_balance + }; let max_giveable = max_giveable .await .context("Failed to compute max 'giveable' Bitcoin amount")?; + let fees = balance - max_giveable; + let max_accepted = bid_quote.max_quantity; - if max_giveable > max_accepted { - info!( - "Max giveable amount {} exceeds max accepted amount {}!", - max_giveable, max_accepted - ); - } + let btc_swap_amount = min(max_giveable, max_accepted); + info!("Swapping {} with {} fees", btc_swap_amount, fees); - Ok(min(max_giveable, max_accepted)) + Ok(btc_swap_amount) } #[cfg(test)]