From f4474ce524141f43afc7b29e1a38be6002f8782f Mon Sep 17 00:00:00 2001 From: Catrya <140891948+Catrya@users.noreply.github.com> Date: Mon, 2 Sep 2024 16:33:10 -0400 Subject: [PATCH] fix 349 Now Mostro will first check the status of the order and then if the quantity requested to be taken is within the range and not the other way around. --- src/app/take_buy.rs | 30 +++++++++++++++--------------- src/app/take_sell.rs | 28 ++++++++++++++-------------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/app/take_buy.rs b/src/app/take_buy.rs index 10b5b955..b406f9cc 100644 --- a/src/app/take_buy.rs +++ b/src/app/take_buy.rs @@ -48,21 +48,7 @@ pub async fn take_buy_action( send_cant_do_msg(Some(order.id), None, &event.pubkey).await; return Ok(()); } - - // Get amount request if user requested one for range order - fiat amount will be used below - if let Some(am) = get_fiat_amount_requested(&order, &msg) { - order.fiat_amount = am; - } else { - send_new_order_msg( - Some(order.id), - Action::OutOfRangeFiatAmount, - None, - &event.pubkey, - ) - .await; - return Ok(()); - } - + let order_status = match Status::from_str(&order.status) { Ok(s) => s, Err(e) => { @@ -97,6 +83,20 @@ pub async fn take_buy_action( return Ok(()); } + // Get amount request if user requested one for range order - fiat amount will be used below + if let Some(am) = get_fiat_amount_requested(&order, &msg) { + order.fiat_amount = am; + } else { + send_new_order_msg( + Some(order.id), + Action::OutOfRangeFiatAmount, + None, + &event.pubkey, + ) + .await; + return Ok(()); + } + // Check market price value in sats - if order was with market price then calculate if order.amount == 0 { let (new_sats_amount, fee) = diff --git a/src/app/take_sell.rs b/src/app/take_sell.rs index ffdcb917..9fdc8844 100644 --- a/src/app/take_sell.rs +++ b/src/app/take_sell.rs @@ -33,20 +33,6 @@ pub async fn take_sell_action( } }; - // Get amount request if user requested one for range order - fiat amount will be used below - if let Some(am) = get_fiat_amount_requested(&order, &msg) { - order.fiat_amount = am; - } else { - send_new_order_msg( - Some(order.id), - Action::OutOfRangeFiatAmount, - None, - &event.pubkey, - ) - .await; - return Ok(()); - } - // Maker can't take own order if order.creator_pubkey == event.pubkey.to_hex() { send_cant_do_msg(Some(order.id), None, &event.pubkey).await; @@ -141,6 +127,20 @@ pub async fn take_sell_action( } } + // Get amount request if user requested one for range order - fiat amount will be used below + if let Some(am) = get_fiat_amount_requested(&order, &msg) { + order.fiat_amount = am; + } else { + send_new_order_msg( + Some(order.id), + Action::OutOfRangeFiatAmount, + None, + &event.pubkey, + ) + .await; + return Ok(()); + } + // Check market price value in sats - if order was with market price then calculate it and send a DM to buyer if order.amount == 0 { let (new_sats_amount, fee) =