diff --git a/src/app/order.rs b/src/app/order.rs index 390cf2a..eea435c 100644 --- a/src/app/order.rs +++ b/src/app/order.rs @@ -2,6 +2,7 @@ use crate::cli::settings::Settings; use crate::util::{get_market_quote, publish_order, send_dm}; use anyhow::Result; +use log::error; use mostro_core::{Action, Message}; use nostr_sdk::prelude::ToBech32; use nostr_sdk::{Client, Event, Keys}; @@ -16,7 +17,13 @@ pub async fn order_action( ) -> Result<()> { if let Some(order) = msg.get_order() { let mostro_settings = Settings::get_mostro(); - let quote = get_market_quote(&order.fiat_amount, &order.fiat_code, &0).await?; + let quote = match get_market_quote(&order.fiat_amount, &order.fiat_code, &0).await { + Ok(amount) => amount, + Err(e) => { + error!("{:?}", e.to_string()); + return Ok(()); + } + }; if quote > mostro_settings.max_order_amount as i64 { let message = Message::new(0, order.id, None, Action::CantDo, None); let message = message.as_json()?; diff --git a/src/app/take_buy.rs b/src/app/take_buy.rs index 906d4f0..03e04b4 100644 --- a/src/app/take_buy.rs +++ b/src/app/take_buy.rs @@ -22,7 +22,7 @@ pub async fn take_buy_action( let mut order = match Order::by_id(pool, order_id).await? { Some(order) => order, None => { - error!("TakeBuy: Order Id {order_id} not found!"); + error!("Order Id {order_id} not found!"); return Ok(()); } }; @@ -37,21 +37,21 @@ pub async fn take_buy_action( } if order.kind != "Buy" { - error!("TakeBuy: Order Id {order_id} wrong kind"); + error!("Order Id {order_id} wrong kind"); return Ok(()); } let order_status = match Status::from_str(&order.status) { Ok(s) => s, Err(e) => { - error!("TakeBuy: Order Id {order_id} wrong status: {e:?}"); + error!("Order Id {order_id} wrong status: {e:?}"); return Ok(()); } }; let buyer_pubkey = match order.buyer_pubkey.as_ref() { Some(pk) => XOnlyPublicKey::from_bech32(pk)?, None => { - error!("TakeBuy: Buyer pubkey not found for order {}!", order.id); + error!("Buyer pubkey not found for order {}!", order.id); return Ok(()); } }; @@ -92,7 +92,13 @@ pub async fn take_buy_action( // Check market price value in sats - if order was with market price then calculate if order.amount == 0 { order.amount = - get_market_quote(&order.fiat_amount, &order.fiat_code, &order.premium).await?; + match get_market_quote(&order.fiat_amount, &order.fiat_code, &order.premium).await { + Ok(amount) => amount, + Err(e) => { + error!("{:?}", e); + return Ok(()); + } + }; } show_hold_invoice( diff --git a/src/models.rs b/src/models.rs index dbca9ca..e62287e 100644 --- a/src/models.rs +++ b/src/models.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -#[derive(Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize)] pub struct Yadio { request: Request, pub result: f64, @@ -8,7 +8,7 @@ pub struct Yadio { timestamp: i64, } -#[derive(Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize)] pub struct Request { amount: i64, from: String, diff --git a/src/util.rs b/src/util.rs index f69fbea..0b9e0c8 100644 --- a/src/util.rs +++ b/src/util.rs @@ -43,6 +43,7 @@ pub async fn get_market_quote( "https://api.yadio.io/convert/{}/{}/BTC", fiat_amount, fiat_code ); + info!("Requesting API price: {}", req_string); let mut req = None; // Retry for 4 times @@ -64,11 +65,14 @@ pub async fn get_market_quote( // Case no answers from Yadio if req.is_none() { - println!("Send dm to user to signal no API response"); return Err(MostroError::NoAPIResponse); } - let quote = req.unwrap().json::().await?; + let quote = req.unwrap().json::().await; + if quote.is_err() { + return Err(MostroError::NoAPIResponse); + } + let quote = quote.unwrap(); let mut sats = quote.result * 100_000_000_f64;