Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When taking an order, check the status first and then the quantity #351

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading