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

disallow premium with fixed order #400

Merged
merged 4 commits into from
Dec 11, 2024
Merged
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions src/app/order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ pub async fn order_action(
amount_vec.push(max);
}

if order.premium != 0 && order.amount !=0 && order.fiat_amount !=0 {
send_cant_do_msg(None, None, &event.sender).await;
return Ok(());
}

Copy link
Contributor

@coderabbitai coderabbitai bot Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve error handling for premium validation.

While the validation logic correctly implements the business rule, the error handling could be more informative and maintain context.

Consider applying these improvements:

-        if order.premium != 0 && order.amount !=0 && order.fiat_amount !=0 {
-            send_cant_do_msg(None, None, &event.sender).await;
+        if order.premium != 0 && order.amount != 0 && order.fiat_amount != 0 {
+            send_new_order_msg(
+                request_id,
+                order.id,
+                Action::InvalidOrderCombination,
+                Some("Orders cannot have both fixed price and premium".to_string()),
+                &event.sender,
+            )
             return Ok(());
         }

This change:

  1. Preserves the request_id and order.id context
  2. Uses a more specific error message
  3. Uses send_new_order_msg for consistent error handling

Committable suggestion skipped: line range outside the PR's diff.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

waiting for it to be decided whether to do #393 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Catrya, understood. I'll await the outcome of the discussion in PR #393.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from cosmetics of the code it makes sense to me.
Waiting for @grunch opinion

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

for fiat_amount in amount_vec.iter() {
let quote = match order.amount {
0 => match get_bitcoin_price(&order.fiat_code) {
Expand Down
Loading