Skip to content

Commit

Permalink
fix(cryptocompare): ignore currencies that don't have the RAW field
Browse files Browse the repository at this point in the history
Signed-off-by: Taiga Nakayama <dora@dora-gt.jp>
  • Loading branch information
dora-gt authored and emschwartz committed Nov 9, 2019
1 parent 8016457 commit 710fb48
Showing 1 changed file with 3 additions and 2 deletions.
Expand Up @@ -38,7 +38,7 @@ struct Record {
#[serde(rename = "CoinInfo")]
coin_info: CoinInfo,
#[serde(rename = "RAW")]
raw: Raw,
raw: Option<Raw>,
}

#[derive(Deserialize, Debug)]
Expand Down Expand Up @@ -79,7 +79,8 @@ pub fn query_cryptocompare(
let rates = res
.data
.into_iter()
.map(|asset| (asset.coin_info.name.to_uppercase(), asset.raw.usd.price))
.filter(|asset| asset.raw.is_some())
.map(|asset| (asset.coin_info.name.to_uppercase(), asset.raw.unwrap().usd.price))
.chain(once(("USD".to_string(), 1.0)));
Ok(HashMap::from_iter(rates))
})
Expand Down

0 comments on commit 710fb48

Please sign in to comment.