Skip to content

Commit

Permalink
Improve fetching simple hash nft's
Browse files Browse the repository at this point in the history
  • Loading branch information
gemcoder21 committed Jan 24, 2025
1 parent 72a34c9 commit 7f9bf1d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion crates/nft/src/simplehash/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl SimpleHashClient {
pub async fn get_assets_evm(&self, address: &str) -> Result<NftResponse, reqwest::Error> {
let url = format!("{}/api/v0/nfts/owners_v2", BASE_URL);
let chains = EVM_CHAINS.join(",");
let query = [("chains", chains), ("wallet_addresses", address.to_string())];
let query = [("chains", chains), ("wallet_addresses", address.to_string()), ("limit", "50".to_string())];
let response = self.client.get(&url).query(&query).send().await?;
response.json::<NftResponse>().await
}
Expand Down
27 changes: 14 additions & 13 deletions crates/nft/src/simplehash/mapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl super::model::Nft {
}

pub fn as_type(&self) -> Option<primitives::NFTType> {
match self.contract.r#type.as_str() {
match self.contract.contract_type.as_str() {
"ERC721" => Some(primitives::NFTType::ERC721),
"ERC1155" => Some(primitives::NFTType::ERC1155),
_ => None,
Expand Down Expand Up @@ -61,20 +61,21 @@ impl super::model::Nft {
}

pub fn as_primitive_collection_image(&self) -> primitives::NFTImage {
if self.collection.image_properties.mime_type == Some("image/png".to_string()) {
let image_url = self.collection.image_url.clone();
NFTImage {
image_url,
preview_image_url: self.collection.image_url.clone(),
original_source_url: self.collection.image_url.clone(),
}
} else {
NFTImage {
image_url: "".to_string(),
preview_image_url: "".to_string(),
original_source_url: "".to_string(),
if let Some(image_properties) = &self.collection.image_properties {
if image_properties.mime_type == Some("image/png".to_string()) {
let image_url = self.collection.image_url.clone().unwrap_or_default();
return NFTImage {
image_url: image_url.clone(),
preview_image_url: image_url.clone(),
original_source_url: image_url.clone(),
};
}
}
NFTImage {
image_url: "".to_string(),
preview_image_url: "".to_string(),
original_source_url: "".to_string(),
}
}

pub fn as_primitive_asset(&self) -> Option<primitives::NFTAsset> {
Expand Down
7 changes: 4 additions & 3 deletions crates/nft/src/simplehash/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ pub struct ImageProperties {

#[derive(Debug, Serialize, Deserialize)]
pub struct Contract {
pub r#type: String,
#[serde(rename = "type")]
pub contract_type: String,
// pub name: String,
// pub symbol: String,
// pub deployed_by: String,
Expand All @@ -97,8 +98,8 @@ pub struct Collection {
// pub collection_id: String,
pub name: Option<String>,
pub description: Option<String>,
pub image_url: String,
pub image_properties: ImageProperties,
pub image_url: Option<String>,
pub image_properties: Option<ImageProperties>,
// pub banner_image_url: String,
// pub category: String,
// pub is_nsfw: bool,
Expand Down

0 comments on commit 7f9bf1d

Please sign in to comment.