Skip to content

Commit

Permalink
simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
taitruong committed Sep 3, 2024
1 parent eafba9e commit d4aac2e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 35 deletions.
39 changes: 9 additions & 30 deletions contracts/sg-ics721/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ impl Ics721Execute for SgIcs721Contract {
data: Option<Binary>,
) -> StdResult<Binary> {
// parse token data and check whether it is of type NftExtension
let extension: Metadata = match data {
Some(data) => {
match from_json::<NftExtension>(data).ok().map(|ext| Metadata {
let extension = data
.and_then(|binary| {
from_json::<NftExtension>(binary).ok().map(|ext| Metadata {
animation_url: ext.animation_url,
attributes: ext.attributes.map(|traits| {
traits
Expand All @@ -145,33 +145,12 @@ impl Ics721Execute for SgIcs721Contract {
image_data: ext.image_data,
youtube_url: ext.youtube_url,
name: ext.name,
}) {
Some(extension) => extension,
None => Metadata {
animation_url: None,
attributes: None,
background_color: None,
description: None,
external_url: None,
image: None,
image_data: None,
youtube_url: None,
name: None,
},
}
}
None => Metadata {
animation_url: None,
attributes: None,
background_color: None,
description: None,
external_url: None,
image: None,
image_data: None,
youtube_url: None,
name: None,
},
};
})
})
.unwrap_or(Metadata {
// no onchain metadata (only offchain), in this case empty metadata is created
..Default::default()
});

let msg = sg721_metadata_onchain::ExecuteMsg::Mint {
token_id,
Expand Down
9 changes: 4 additions & 5 deletions packages/ics721/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,8 +748,8 @@ where
data: Option<Binary>,
) -> StdResult<Binary> {
// parse token data and check whether it is of type NftExtension
let extension: Option<NftExtensionMsg> = match data {
Some(data) => from_json::<NftExtension>(data)
let extension = data.and_then(|binary| {
from_json::<NftExtension>(binary)
.ok()
.map(|ext| NftExtensionMsg {
animation_url: ext.animation_url,
Expand All @@ -761,9 +761,8 @@ where
image_data: ext.image_data,
youtube_url: ext.youtube_url,
name: ext.name,
}),
None => None,
};
})
});

let msg = cw721_metadata_onchain::msg::ExecuteMsg::Mint {
token_id,
Expand Down

0 comments on commit d4aac2e

Please sign in to comment.