diff --git a/src/endpoints/quests/mod.rs b/src/endpoints/quests/mod.rs index d16a997..4cc16c2 100644 --- a/src/endpoints/quests/mod.rs +++ b/src/endpoints/quests/mod.rs @@ -22,6 +22,7 @@ pub mod rhino; pub mod sithswap; pub mod starknet; pub mod starknetid; +pub mod strk_farm; pub mod tribe; pub mod uri; pub mod verify_balance; diff --git a/src/endpoints/quests/strk_farm/check_balance.rs b/src/endpoints/quests/strk_farm/check_balance.rs new file mode 100644 index 0000000..9f1db06 --- /dev/null +++ b/src/endpoints/quests/strk_farm/check_balance.rs @@ -0,0 +1,47 @@ +use std::sync::Arc; + +use crate::{ + models::{AppState, VerifyQuery}, + utils::{get_error, CompletedTasksTrait}, +}; +use axum::{ + extract::{Query, State}, + http::StatusCode, + response::IntoResponse, + Json, +}; +use axum_auto_routes::route; +use serde_json::json; + +type StrkFarmAPIResponse = serde_json::Value; + +#[route( + get, + "/quests/strkFarm/check_balance", + crate::endpoints::quests::strk_farm::check_balance +)] +pub async fn handler( + State(state): State>, + Query(query): Query, +) -> impl IntoResponse { + let task_id = 185; + let addr = &query.addr; + let url = format!("https://www.strkfarm.xyz/api/stats/{addr}"); + let res = reqwest::get(&url).await.unwrap().text().await.unwrap(); + // Res in a JSON containing the user's balance + let json: StrkFarmAPIResponse = serde_json::from_str(&res).unwrap(); + let usd = json["holdingsUSD"].as_f64().unwrap(); + if usd == 0.0 { + get_error("You didn't invest on StrkFarm.".to_string()) + } else if usd < 10.0 { + get_error(format!( + "You need to invest at least $10 on StrkFarm (You have ${}).", + usd + )) + } else { + match state.upsert_completed_task(query.addr, task_id).await { + Ok(_) => (StatusCode::OK, Json(json!({"res": true}))).into_response(), + Err(e) => get_error(format!("{}", e)), + } + } +} diff --git a/src/endpoints/quests/strk_farm/mod.rs b/src/endpoints/quests/strk_farm/mod.rs new file mode 100644 index 0000000..efaa97b --- /dev/null +++ b/src/endpoints/quests/strk_farm/mod.rs @@ -0,0 +1 @@ +pub mod check_balance;