Skip to content

Commit

Permalink
Feat: Add metadata logo path to SNS aggregator data (#3301)
Browse files Browse the repository at this point in the history
# Motivation

The logo to the SNS Metadata needs to be hardcoded by the frontend
following a specific pattern.

In this PR, I add the relative path of the logo so that the logic of
where the logo lives lies only in the SNS aggregator canister.

Another reason is because the logo is optional. Therefore, this way it's
easier to know whether the logo is present or not. Otherwise, we would
need to try to fetch the asset and check it.

# Changes

* New field `logo` in `SlowMetadata`.
* Change `SlowMetadata::from` for `from_get_metadata_response` because
it uses a second argument for the logo url.

# Tests

Tests are skipped.

# Todos

- [x] Add entry to changelog (if necessary).
  • Loading branch information
lmuntaner authored Sep 12, 2023
1 parent 6ea5492 commit 52cc6ed
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG-Sns_Aggregator.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ The SNS Aggregator is released through proposals in the Network Nervous System.
## Unreleased

### Wasm changes

* New field `logo` in the `meta` data with the relative path to the logo asset.

### Operations

## [Proposal 124250](https://nns.ic0.app/proposal/?u=qoctq-giaaa-aaaaa-aaaea-cai&proposal=124250)
Expand Down
21 changes: 14 additions & 7 deletions rs/sns_aggregator/src/types/slow.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Slowly changing information about an SNS
use crate::types::ic_sns_governance::{GetMetadataResponse, ListNervousSystemFunctionsResponse};
use crate::types::ic_sns_governance::ListNervousSystemFunctionsResponse;
use crate::types::ic_sns_root::ListSnsCanistersResponse;
use crate::types::ic_sns_swap::{
DerivedState, GetDerivedStateResponse, GetInitResponse, GetLifecycleResponse, GetSaleParametersResponse,
Expand Down Expand Up @@ -50,7 +50,7 @@ impl From<&UpstreamData> for SlowSnsData {
index: upstream.index,
canister_ids: upstream.canister_ids.clone(),
list_sns_canisters: upstream.list_sns_canisters.clone(),
meta: SlowMetadata::from(&upstream.meta),
meta: SlowMetadata::from(upstream),
parameters: upstream.parameters.clone(),
swap_state: SlowSwapState::from(&upstream.swap_state),
icrc1_metadata: upstream.icrc1_metadata.clone(),
Expand All @@ -77,14 +77,21 @@ pub struct SlowMetadata {
/// Same as upstream.
/// Note: The description can also be quite long and isn't needed for the initial view of all the SNSs
pub description: Option<String>,
/// Relative path of the logo if present
pub logo: Option<String>,
}

impl From<&GetMetadataResponse> for SlowMetadata {
fn from(upstream: &GetMetadataResponse) -> Self {
impl From<&UpstreamData> for SlowMetadata {
fn from(upstream: &UpstreamData) -> Self {
SlowMetadata {
url: upstream.url.clone(),
name: upstream.name.clone(),
description: upstream.description.clone(),
url: upstream.meta.url.clone(),
name: upstream.meta.name.clone(),
description: upstream.meta.description.clone(),
// Logo URL example: https://3r4gx-wqaaa-aaaaq-aaaia-cai.ic0.app/v1/sns/root/u67kc-jyaaa-aaaaq-aabpq-cai/logo.png
logo: match (upstream.meta.logo.clone(), upstream.list_sns_canisters.root) {
(Some(_), Some(canister_id)) => Some(format!("/v1/sns/root/{}/logo.png", canister_id.to_text())),
_ => None,
},
}
}
}
Expand Down

0 comments on commit 52cc6ed

Please sign in to comment.