Skip to content

Commit 769e36e

Browse files
committed
simpler points
1 parent cf01ade commit 769e36e

File tree

2 files changed

+6
-26
lines changed

2 files changed

+6
-26
lines changed

compute/src/utils/points.rs

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,17 @@
11
use eyre::Context;
2-
use serde::Deserialize;
32

43
/// Points URL, use with an `address` query parameter.
54
const POINTS_API_BASE_URL: &str =
65
"https://mainnet.dkn.dria.co/dashboard/supply/v0/leaderboard/steps";
76

8-
#[derive(Debug, Deserialize)]
7+
#[derive(Debug, serde::Deserialize)]
98
pub struct DriaPoints {
10-
#[serde(deserialize_with = "deserialize_percentile")]
119
/// Indicates in which top percentile your points are.
12-
pub percentile: u64,
10+
pub percentile: u32,
1311
/// The total number of points you have accumulated.
1412
pub score: f64,
1513
}
1614

17-
// the API returns a stringified number due to frontend issues, so we need to parse it
18-
fn deserialize_percentile<'de, D>(deserializer: D) -> Result<u64, D::Error>
19-
where
20-
D: serde::Deserializer<'de>,
21-
{
22-
let s: String = String::deserialize(deserializer)?;
23-
let parsed = s.parse().map_err(serde::de::Error::custom)?;
24-
25-
if parsed > 100 {
26-
return Err(serde::de::Error::custom(
27-
"percentile must be between 0 and 100",
28-
));
29-
}
30-
31-
Ok(parsed)
32-
}
33-
3415
/// Returns the points for the given address.
3516
pub async fn get_points(address: &str) -> eyre::Result<DriaPoints> {
3617
// the address can have 0x or not, we add it ourselves here
@@ -40,12 +21,12 @@ pub async fn get_points(address: &str) -> eyre::Result<DriaPoints> {
4021
address.trim_start_matches("0x")
4122
);
4223

43-
reqwest::get(&url)
24+
let res = reqwest::get(&url)
4425
.await
45-
.wrap_err("could not make request")?
46-
.json::<DriaPoints>()
26+
.wrap_err("could not make request")?;
27+
res.json::<DriaPoints>()
4728
.await
48-
.wrap_err("could not parse body")
29+
.wrap_err("could not parse response")
4930
}
5031

5132
#[cfg(test)]

utils/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ crypto = [
1818
]
1919

2020
[dependencies]
21-
2221
serde.workspace = true
2322
serde_json.workspace = true
2423

0 commit comments

Comments
 (0)