Skip to content

Commit

Permalink
use ok()
Browse files Browse the repository at this point in the history
  • Loading branch information
taitruong committed Nov 27, 2023
1 parent 9c9b056 commit 75acead
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
20 changes: 9 additions & 11 deletions contracts/sg-ics721/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ impl Ics721Execute for SgIcs721Contract {
let ics721_contract_info = deps
.querier
.query_wasm_contract_info(env.contract.address.to_string())?;
// use by default ClassId, in case there's no class data with name and symbol
let mut instantiate_msg = sg721::InstantiateMsg {
// source chain may not send optional collection data
// if not, by default class id is used for name and symbol
name: class.id.clone().into(),
symbol: class.id.clone().into(),
minter: env.contract.address.to_string(),
Expand All @@ -57,15 +56,14 @@ impl Ics721Execute for SgIcs721Contract {
},
};

// unwrapped to collection data and in case of success, set creator, name and symbol
if let Some(binary) = class.data.clone() {
let class_data_result: StdResult<CollectionData> = from_json(binary);
if class_data_result.is_ok() {
let class_data = class_data_result?;
// set name and symbol
instantiate_msg.symbol = class_data.symbol;
instantiate_msg.name = class_data.name;
}
// use collection data for setting name and symbol
let collection_data = class
.data
.clone()
.and_then(|binary| from_json::<CollectionData>(binary).ok());
if let Some(collection_data) = collection_data {
instantiate_msg.name = collection_data.name;
instantiate_msg.symbol = collection_data.symbol;
}

to_json_binary(&instantiate_msg)
Expand Down
16 changes: 8 additions & 8 deletions packages/ics721/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,14 +332,14 @@ where
minter: env.contract.address.to_string(),
};

// unwrapped to collection data and in case of success, set name and symbol
if let Some(binary) = class.data.clone() {
let class_data_result: StdResult<CollectionData> = from_json(binary);
if class_data_result.is_ok() {
let class_data = class_data_result?;
instantiate_msg.symbol = class_data.symbol;
instantiate_msg.name = class_data.name;
}
// use collection data for setting name and symbol
let collection_data = class
.data
.clone()
.and_then(|binary| from_json::<CollectionData>(binary).ok());
if let Some(collection_data) = collection_data {
instantiate_msg.name = collection_data.name;
instantiate_msg.symbol = collection_data.symbol;
}

to_json_binary(&instantiate_msg)
Expand Down

0 comments on commit 75acead

Please sign in to comment.