Skip to content

Commit

Permalink
fix nft nulls
Browse files Browse the repository at this point in the history
  • Loading branch information
robtfm committed Nov 24, 2023
1 parent 429a25b commit d1c99a0
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 33 deletions.
19 changes: 12 additions & 7 deletions crates/nft/src/asset_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,12 @@ pub struct NftOwner {
#[derive(Asset, TypePath, Deserialize)]
pub struct Nft {
pub image_url: String,
pub name: String,
pub description: String,
pub permalink: String,
pub creator: NftIdent,
pub name: Option<String>,
pub description: Option<String>,
pub permalink: Option<String>,
pub creator: Option<NftIdent>,
pub last_sale: Option<NftLastSale>,
pub top_ownerships: Vec<NftOwner>,
pub top_ownerships: Option<Vec<NftOwner>>,
}

pub struct NftLoader;
Expand All @@ -263,8 +263,13 @@ impl AssetLoader for NftLoader {
.read_to_end(&mut bytes)
.await
.map_err(|e| std::io::Error::new(e.kind(), e))?;
serde_json::from_reader(bytes.as_slice())
.map_err(|e| std::io::Error::new(ErrorKind::InvalidData, e))

let res = serde_json::from_reader(bytes.as_slice())
.map_err(|e| std::io::Error::new(ErrorKind::InvalidData, e));
if res.is_err() {
debug!("errored nft bytes: {}", String::from_utf8(bytes).unwrap());
}
res
})
}

Expand Down
48 changes: 30 additions & 18 deletions crates/restricted_actions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use dcl_component::proto_components::kernel::comms::rfc4;
use ethers_core::types::Address;
use ipfs::{ipfs_path::IpfsPath, ChangeRealmEvent, EntityDefinition, ServerAbout};
use isahc::{http::StatusCode, AsyncReadResponseExt};
use nft::asset_source::Nft;
use nft::asset_source::{Nft, NftIdent};
use scene_runner::{
initialize_scene::{
LiveScenes, PortableScenes, PortableSource, SceneHash, SceneLoading, PARCEL_SIZE,
Expand Down Expand Up @@ -827,13 +827,18 @@ impl<'a> IntoDialogBody for NftDialog<'a> {
..Default::default()
})
.with_children(|c| {
let creator = self.0.creator.get_string();
let creator = self
.0
.creator
.as_ref()
.map(NftIdent::get_string)
.unwrap_or("???".to_owned());
c.spawn(TextBundle::from_section(
format!("Creator: {creator}"),
BODY_TEXT_STYLE.get().unwrap().clone(),
));

if let Some(owner) = self.0.top_ownerships.first() {
if let Some(owner) = self.0.top_ownerships.as_ref().and_then(|v| v.first()) {
let owner = owner.owner.get_string();
c.spawn(TextBundle::from_section(
format!("Owner: {owner}"),
Expand All @@ -852,11 +857,9 @@ impl<'a> IntoDialogBody for NftDialog<'a> {
BODY_TEXT_STYLE.get().unwrap().clone(),
));

let description: String = if self.0.description.len() < 500 {
self.0.description.clone()
} else {
self.0
.description
let mut description = self.0.description.clone().unwrap_or("???".to_owned());
if description.len() > 500 {
description = description
.chars()
.take(500)
.chain(std::iter::repeat('.').take(3))
Expand Down Expand Up @@ -884,16 +887,25 @@ fn show_nft_dialog(
nft_spawn.response.clone().send(Ok(()));
let link = nft.permalink.clone();

commands.spawn_dialog_two(
nft.name.clone(),
NftDialog(nft, &asset_server),
"Close",
move || {},
"View on Opensea",
move || {
let _ = opener::open(link.clone());
},
)
if let Some(link) = link {
commands.spawn_dialog_two(
nft.name.clone().unwrap_or("Unnamed Nft".to_owned()),
NftDialog(nft, &asset_server),
"Close",
move || {},
"View on Opensea",
move || {
let _ = opener::open(link.clone());
},
)
} else {
commands.spawn_dialog(
nft.name.clone().unwrap_or("Unnamed Nft".to_owned()),
NftDialog(nft, &asset_server),
"Close",
move || {},
)
}
} else if asset_server.load_state(nft_spawn.h_nft.id()) == LoadState::Failed {
commands.entity(ent).remove::<NftDialogSpawn>();
nft_spawn
Expand Down
13 changes: 5 additions & 8 deletions crates/ui_core/src/dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use super::{
};

pub trait SpawnDialog {
fn spawn_dialog<M>(
fn spawn_dialog<M, B: IntoDialogBody>(
&mut self,
title: String,
body: String,
body: B,
button_one_label: impl Into<String>,
button_one_action: impl IntoSystem<(), (), M>,
);
Expand All @@ -27,10 +27,10 @@ pub trait SpawnDialog {
}

impl<'w, 's> SpawnDialog for Commands<'w, 's> {
fn spawn_dialog<M>(
fn spawn_dialog<M, B: IntoDialogBody>(
&mut self,
title: String,
body: String,
body: B,
button_one_label: impl Into<String>,
button_one_action: impl IntoSystem<(), (), M>,
) {
Expand Down Expand Up @@ -90,10 +90,7 @@ impl<'w, 's> SpawnDialog for Commands<'w, 's> {
TextBundle::from_section(title, TITLE_TEXT_STYLE.get().unwrap().clone())
.with_text_alignment(TextAlignment::Center),
);
commands.spawn(
TextBundle::from_section(body, BODY_TEXT_STYLE.get().unwrap().clone())
.with_text_alignment(TextAlignment::Center),
);
body.body(commands);
commands
.spawn(NodeBundle {
style: Style {
Expand Down

0 comments on commit d1c99a0

Please sign in to comment.