Skip to content

Commit

Permalink
fix: fetch credential logo URI from logo.uri (#321)
Browse files Browse the repository at this point in the history
* fix: fetch credential logo URI from `logo.uri`

* fix: update display property in test
  • Loading branch information
nanderstabel authored Aug 7, 2024
1 parent f3ea615 commit e05cb3e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 30 deletions.
60 changes: 31 additions & 29 deletions identity-wallet/src/state/qr_code/reducers/read_credential_offer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,35 +107,7 @@ pub async fn read_credential_offer(state: AppState, action: Action) -> Result<Ap
info!("issuer_name in credential_offer: {:?}", issuer_name);
info!("logo_uri in credential_offer: {:?}", logo_uri);

for (credential_configuration_id, credential_configuration) in credential_configurations.iter() {
let credential_logo_url = credential_configuration
.display
.first()
.and_then(|value| value.get("logo").and_then(|value| value.get("url")));

info!("credential_logo_url: {:?}", credential_logo_url);

if let Some(credential_logo_url) = credential_logo_url {
debug!(
"{}",
format!("Downloading credential logo from url: {}", credential_logo_url)
);
if let Some(credential_logo_url) = credential_logo_url
.as_str()
.and_then(|s| s.parse::<reqwest::Url>().ok())
{
let _ = download_asset(
credential_logo_url,
format!("credential_{}", credential_configuration_id).as_str(),
)
.await;
}
}

if credential_logo_url.is_none() && logo_uri.is_none() {
debug!("No logo found in metadata.");
}
}
download_credential_logos(&credential_configurations).await;

if logo_uri.is_some() {
debug!(
Expand Down Expand Up @@ -167,3 +139,33 @@ pub async fn read_credential_offer(state: AppState, action: Action) -> Result<Ap

Ok(state)
}

/// Downloads all the Credential logos.
async fn download_credential_logos(
credential_configurations: &HashMap<String, CredentialConfigurationsSupportedObject>,
) {
for (credential_configuration_id, credential_configuration) in credential_configurations.iter() {
let credential_logo_uri = credential_configuration
.display
.first()
.and_then(|value| value["logo"]["uri"].as_str());

info!("credential_logo_uri: {:?}", credential_logo_uri);

if let Some(credential_logo_uri) = credential_logo_uri {
debug!(
"{}",
format!("Downloading credential logo from URI: {}", credential_logo_uri)
);
if let Ok(credential_logo_uri) = credential_logo_uri.parse::<reqwest::Url>() {
let _ = download_asset(
credential_logo_uri,
format!("credential_{}", credential_configuration_id).as_str(),
)
.await;
} else {
debug!("Failed to parse credential logo URI: {}", credential_logo_uri);
}
}
}
}
2 changes: 1 addition & 1 deletion unime/src-tauri/tests/tests/credential_offer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ async fn download_credential_logo() {
"name": "University Credential",
"locale": "en-US",
"logo": {
"url": format!("{}/logo/credential.svg", &mock_server.uri()),
"uri": format!("{}/logo/credential.svg", &mock_server.uri()),
"alternative_text": "a square logo of a university"
},
"background_color": "#12107c",
Expand Down

0 comments on commit e05cb3e

Please sign in to comment.