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

Quick fix for rate user on order creation #295

Merged
merged 5 commits into from
Jun 10, 2024
Merged
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/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
Loading