diff --git a/src/app/add_invoice.rs b/src/app/add_invoice.rs index 1746ada8..db4368a7 100644 --- a/src/app/add_invoice.rs +++ b/src/app/add_invoice.rs @@ -7,7 +7,7 @@ use anyhow::Result; use log::error; use mostro_core::message::{Action, Content, Message}; use mostro_core::order::SmallOrder; -use mostro_core::order::{Order, Status}; +use mostro_core::order::{Kind, Order, Status}; use nostr_sdk::prelude::*; use sqlx::{Pool, Sqlite}; use sqlx_crud::Crud; @@ -73,6 +73,15 @@ pub async fn add_invoice_action( return Ok(()); } }; + + let order_kind = match Kind::from_str(&order.kind) { + Ok(k) => k, + Err(e) => { + error!("Order Id {order_id} wrong kind: {e:?}"); + return Ok(()); + } + }; + let buyer_pubkey = match order.buyer_pubkey.as_ref() { Some(pk) => XOnlyPublicKey::from_bech32(pk)?, None => { @@ -114,8 +123,8 @@ pub async fn add_invoice_action( // We send this data related to the order to the parties let order_data = SmallOrder::new( Some(order.id), - None, - None, + Some(order_kind), + Some(order_status), order.amount, order.fiat_code.clone(), order.fiat_amount, diff --git a/src/flow.rs b/src/flow.rs index 7f661de4..68062741 100644 --- a/src/flow.rs +++ b/src/flow.rs @@ -1,10 +1,12 @@ use crate::cli::settings::Settings; use crate::util::send_dm; +use log::error; use log::info; use mostro_core::message::{Action, Content, Message}; -use mostro_core::order::{SmallOrder, Status}; +use mostro_core::order::{Kind, SmallOrder, Status}; use nostr_sdk::prelude::*; +use std::str::FromStr; pub async fn hold_invoice_paid(hash: &str) { let pool = crate::db::connect().await.unwrap(); @@ -25,11 +27,18 @@ pub async fn hold_invoice_paid(hash: &str) { master_buyer_pubkey = order.master_buyer_pubkey.clone(); master_seller_pubkey = order.master_seller_pubkey.clone(); } + let order_kind = match Kind::from_str(&order.kind) { + Ok(k) => k, + Err(e) => { + error!("Order Id {} wrong kind: {:?}", order.id, e); + return; + } + }; // We send this data related to the order to the parties let mut order_data = SmallOrder::new( Some(order.id), - None, + Some(order_kind), None, order.amount, order.fiat_code.clone(), @@ -51,6 +60,8 @@ pub async fn hold_invoice_paid(hash: &str) { Action::BuyerTookOrder, Some(Content::Order(order_data.clone())), ); + status = Status::Active; + order_data.status = Some(status); let message = message.as_json().unwrap(); send_dm(&client, &my_keys, &seller_pubkey, message) .await @@ -66,14 +77,14 @@ pub async fn hold_invoice_paid(hash: &str) { send_dm(&client, &my_keys, &buyer_pubkey, message) .await .unwrap(); - status = Status::Active; } else { let mostro_settings = Settings::get_mostro(); let sub_fee = mostro_settings.fee * order_data.amount as f64; let rounded_fee = sub_fee.round(); let new_amount = order_data.amount - rounded_fee as i64; order_data.amount = new_amount; - + status = Status::WaitingBuyerInvoice; + order_data.status = Some(status); // We ask to buyer for a new invoice let message = Message::new_order( Some(order.id), @@ -91,7 +102,6 @@ pub async fn hold_invoice_paid(hash: &str) { send_dm(&client, &my_keys, &seller_pubkey, message) .await .unwrap(); - status = Status::WaitingBuyerInvoice; } // We publish a new replaceable kind nostr event with the status updated // and update on local database the status and new event id