1
1
use eyre:: Context ;
2
- use serde:: Deserialize ;
3
2
4
3
/// Points URL, use with an `address` query parameter.
5
4
const POINTS_API_BASE_URL : & str =
6
5
"https://mainnet.dkn.dria.co/dashboard/supply/v0/leaderboard/steps" ;
7
6
8
- #[ derive( Debug , Deserialize ) ]
7
+ #[ derive( Debug , serde :: Deserialize ) ]
9
8
pub struct DriaPoints {
10
- #[ serde( deserialize_with = "deserialize_percentile" ) ]
11
9
/// Indicates in which top percentile your points are.
12
- pub percentile : u64 ,
10
+ pub percentile : u32 ,
13
11
/// The total number of points you have accumulated.
14
12
pub score : f64 ,
15
13
}
16
14
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
-
34
15
/// Returns the points for the given address.
35
16
pub async fn get_points ( address : & str ) -> eyre:: Result < DriaPoints > {
36
17
// 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> {
40
21
address. trim_start_matches( "0x" )
41
22
) ;
42
23
43
- reqwest:: get ( & url)
24
+ let res = reqwest:: get ( & url)
44
25
. await
45
- . wrap_err ( "could not make request" ) ?
46
- . json :: < DriaPoints > ( )
26
+ . wrap_err ( "could not make request" ) ?;
27
+ res . json :: < DriaPoints > ( )
47
28
. await
48
- . wrap_err ( "could not parse body " )
29
+ . wrap_err ( "could not parse response " )
49
30
}
50
31
51
32
#[ cfg( test) ]
0 commit comments