Skip to content

Commit

Permalink
Quick fix for rate user on order creation (#295)
Browse files Browse the repository at this point in the history
* quick fix for rate user on order creation

* fixed typo on premium tag

* small fix on field of first event of user rating

* improved format of rating tag in new order event

---------

Co-authored-by: Lucio Pinese <[email protected]>
Co-authored-by: Francisco Calderón <[email protected]>
  • Loading branch information
3 people authored Jun 10, 2024
1 parent 4c4e2a6 commit bb9c57c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/app/rate_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ pub async fn update_user_reputation_action(
// Assing new total rating to review
reputation.total_rating = new_rating;
} else {
reputation = Rating::new(1, rating as f64, MIN_RATING, MAX_RATING, rating);
reputation = Rating::new(1, rating as f64, rating, MIN_RATING, MAX_RATING);
}
let reputation = reputation.to_tags()?;

Expand Down
14 changes: 13 additions & 1 deletion src/nip33.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ pub fn new_event(
EventBuilder::new(Kind::Custom(NOSTR_REPLACEABLE_EVENT_KIND), content, tags).to_event(keys)
}

fn create_rating_string(rating: Option<Rating>) -> String {
if let Some(rating) = rating {
if let Ok(rating_json) = rating.as_json() {
rating_json
} else {
"bad format value".to_string()
}
} else {
"none".to_string()
}
}

fn create_fiat_amt_string(order: &Order) -> String {
if order.min_amount.is_some()
&& order.max_amount.is_some()
Expand Down Expand Up @@ -82,7 +94,7 @@ pub fn order_to_tags(order: &Order, reputation: Option<Rating>) -> Vec<(String,
// premium (premium) - The premium
("premium".to_string(), order.premium.to_string()),
// User rating
("Rating".to_string(), create_rating_string(reputation)),
("rating".to_string(), create_rating_string(reputation)),
// Label to identify this is a Mostro's order
("y".to_string(), "mostrop2p".to_string()),
// Table name
Expand Down
2 changes: 2 additions & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ pub async fn publish_order(
let reputation = get_user_reputation(initiator_pubkey, keys).await?;

info!("New order saved Id: {}", order_id);
// Get user reputation
let reputation = get_user_reputation(initiator_pubkey, keys).await?;
// We transform the order fields to tags to use in the event
let tags = order_to_tags(&new_order_db, reputation);

Expand Down

0 comments on commit bb9c57c

Please sign in to comment.