Skip to content

Commit

Permalink
Fix improperly null meatadata crashes.
Browse files Browse the repository at this point in the history
  • Loading branch information
creativedrewy committed Sep 12, 2021
1 parent be85599 commit 4ab043d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package com.creativedrewy.nativ.chainsupport.nft

data class NftMetadata(
val name: String,
val symbol: String,
val description: String,
val image: String,
val name: String?,
val symbol: String?,
val description: String?,
val image: String?,
val animationUrl: String?,
val externalUrl: String,
val externalUrl: String?,
val attributes: List<NftAttributes>?,
val properties: NftProperties
val properties: NftProperties?
)

data class NftAttributes(
val traitType: String,
val value: String,
val traitType: String?,
val value: String?,
val traitCount: Int = 0
)

Expand All @@ -23,22 +23,22 @@ object NftCategories {
}

data class NftProperties(
val category: String,
val files: List<FileDetails>,
val creators: List<NftCreator>
val category: String?,
val files: List<FileDetails>?,
val creators: List<NftCreator>?
)

object NftFileTypes {
const val GLB = "glb"
}

data class FileDetails(
val uri: String,
val type: String
val uri: String?,
val type: String?
)

data class NftCreator(
val address: String,
val verified: Boolean,
val share: Int
val address: String?,
val verified: Boolean = false,
val share: Int = 0
)
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ class GalleryViewStateMapping @Inject constructor() {
val chainDetails = Blockchain(chain.ticker, chain.iconRes)
val attribs = nft.attributes?.map {
Attribute(
name = it.traitType,
value = it.value
name = it.traitType ?: "",
value = it.value ?: ""
)
} ?: listOf()

NftViewProps(
id = UUID.randomUUID(),
name = nft.name,
description = nft.description,
name = nft.name ?: "",
description = nft.description ?: "",
blockchain = chainDetails,
siteUrl = nft.externalUrl,
displayImageUrl = nft.image,
siteUrl = nft.externalUrl ?: "",
displayImageUrl = nft.image ?: "",
videoUrl = nft.animationUrl ?: "",
assetType = determineAssetType(nft),
assetUrl = findDownloadUri(nft.properties) ?: "",
Expand All @@ -44,18 +44,18 @@ class GalleryViewStateMapping @Inject constructor() {

private fun determineAssetType(nft: NftMetadata): AssetType {
return when {
nft.properties.category == NftCategories.VR -> Model3d
nft.properties.category == NftCategories.Image
nft.properties?.category == NftCategories.VR -> Model3d
nft.properties?.category == NftCategories.Image
&& nft.animationUrl?.endsWith(".mp4") == true -> ImageAndVideo
else -> Image
}
}

private fun findDownloadUri(props: NftProperties): String? {
return when (props.category) {
private fun findDownloadUri(props: NftProperties?): String? {
return when (props?.category) {
NftCategories.VR -> {
props.files.firstOrNull { it.type == NftFileTypes.GLB }?.uri
?: props.files.firstOrNull()?.uri
props.files?.firstOrNull { it.type == NftFileTypes.GLB }?.uri
?: props.files?.firstOrNull()?.uri
}
else -> null //We don't actually know what we want to do in other cases yet
}
Expand Down

0 comments on commit 4ab043d

Please sign in to comment.