Skip to content

Commit

Permalink
When taking an order, check the status first and then the quantity (#351
Browse files Browse the repository at this point in the history
)

* fix conflicts

* small fix
  • Loading branch information
Catrya authored Oct 8, 2024
1 parent 13da59c commit 878131c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/app/add_invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub async fn add_invoice_action(
{
Ok(_) => payment_request,
Err(_) => {
send_new_order_msg(None, Action::IncorrectInvoiceAmount, None, &event.sender)
send_new_order_msg(Some(order.id), Action::IncorrectInvoiceAmount, None, &event.sender)
.await;
return Ok(());
}
Expand Down
29 changes: 15 additions & 14 deletions src/app/take_buy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,6 @@ 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.sender,
)
.await;
return Ok(());
}

let order_status = match Status::from_str(&order.status) {
Ok(s) => s,
Err(e) => {
Expand Down Expand Up @@ -90,6 +76,21 @@ 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.sender,
)
.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) =
Expand Down
28 changes: 14 additions & 14 deletions src/app/take_sell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,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.sender,
)
.await;
return Ok(());
}

// Maker can't take own order
if order.creator_pubkey == event.sender.to_hex() {
send_cant_do_msg(Some(order.id), None, &event.sender).await;
Expand Down Expand Up @@ -110,6 +96,20 @@ pub async fn take_sell_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.sender,
)
.await;
return Ok(());
}

// Add buyer pubkey to order
order.buyer_pubkey = Some(buyer_pubkey.to_string());
Expand Down

0 comments on commit 878131c

Please sign in to comment.