diff --git a/contracts/sg-ics721/src/execute.rs b/contracts/sg-ics721/src/execute.rs index 9759b2f..df8bbd8 100644 --- a/contracts/sg-ics721/src/execute.rs +++ b/contracts/sg-ics721/src/execute.rs @@ -124,9 +124,9 @@ impl Ics721Execute for SgIcs721Contract { data: Option, ) -> StdResult { // parse token data and check whether it is of type NftExtension - let extension: Metadata = match data { - Some(data) => { - match from_json::(data).ok().map(|ext| Metadata { + let extension = data + .and_then(|binary| { + from_json::(binary).ok().map(|ext| Metadata { animation_url: ext.animation_url, attributes: ext.attributes.map(|traits| { traits @@ -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, diff --git a/packages/ics721/src/execute.rs b/packages/ics721/src/execute.rs index 7e2ff0c..e2adb0f 100644 --- a/packages/ics721/src/execute.rs +++ b/packages/ics721/src/execute.rs @@ -748,8 +748,8 @@ where data: Option, ) -> StdResult { // parse token data and check whether it is of type NftExtension - let extension: Option = match data { - Some(data) => from_json::(data) + let extension = data.and_then(|binary| { + from_json::(binary) .ok() .map(|ext| NftExtensionMsg { animation_url: ext.animation_url, @@ -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,