fix: Adds some null checks to Asset gql query (#5058)
* add some null checks * undo susflag change * fix not for sale logic * fix rarity * fix rarity format * remove logging Co-authored-by: Charles Bachmeier <charlie@genie.xyz>
This commit is contained in:
parent
d3cbcc769c
commit
734a15e350
@ -1,6 +1,6 @@
|
|||||||
import graphql from 'babel-plugin-relay/macro'
|
import graphql from 'babel-plugin-relay/macro'
|
||||||
import { parseEther } from 'ethers/lib/utils'
|
import { parseEther } from 'ethers/lib/utils'
|
||||||
import { GenieAsset } from 'nft/types'
|
import { GenieAsset, Rarity } from 'nft/types'
|
||||||
import { loadQuery, usePaginationFragment, usePreloadedQuery } from 'react-relay'
|
import { loadQuery, usePaginationFragment, usePreloadedQuery } from 'react-relay'
|
||||||
|
|
||||||
import RelayEnvironment from '../RelayEnvironment'
|
import RelayEnvironment from '../RelayEnvironment'
|
||||||
@ -135,16 +135,16 @@ export function useAssetsQuery(
|
|||||||
|
|
||||||
const assets: GenieAsset[] = data.nftAssets?.edges?.map((queryAsset: { node: any }) => {
|
const assets: GenieAsset[] = data.nftAssets?.edges?.map((queryAsset: { node: any }) => {
|
||||||
const asset = queryAsset.node
|
const asset = queryAsset.node
|
||||||
const ethPrice = parseEther(asset.listings?.edges[0].node.price.value?.toString() ?? '0').toString()
|
const ethPrice = parseEther(asset.listings?.edges[0]?.node.price.value?.toString() ?? '0').toString()
|
||||||
return {
|
return {
|
||||||
id: asset.id,
|
id: asset.id,
|
||||||
address: asset.collection.nftContracts[0].address,
|
address: asset.collection.nftContracts[0]?.address,
|
||||||
notForSale: asset.listings === null,
|
notForSale: asset.listings?.edges.length === 0,
|
||||||
collectionName: asset.collection?.name,
|
collectionName: asset.collection?.name,
|
||||||
collectionSymbol: asset.collection?.image?.url,
|
collectionSymbol: asset.collection?.image?.url,
|
||||||
imageUrl: asset.image?.url,
|
imageUrl: asset.image?.url,
|
||||||
animationUrl: asset.animationUrl,
|
animationUrl: asset.animationUrl,
|
||||||
marketplace: asset.listings?.edges[0].node.marketplace.toLowerCase(),
|
marketplace: asset.listings?.edges[0]?.node.marketplace.toLowerCase(),
|
||||||
name: asset.name,
|
name: asset.name,
|
||||||
priceInfo: asset.listings
|
priceInfo: asset.listings
|
||||||
? {
|
? {
|
||||||
@ -158,12 +158,17 @@ export function useAssetsQuery(
|
|||||||
sellorders: asset.listings?.edges,
|
sellorders: asset.listings?.edges,
|
||||||
smallImageUrl: asset.smallImage?.url,
|
smallImageUrl: asset.smallImage?.url,
|
||||||
tokenId: asset.tokenId,
|
tokenId: asset.tokenId,
|
||||||
tokenType: asset.collection.nftContracts[0].standard,
|
tokenType: asset.collection.nftContracts[0]?.standard,
|
||||||
// totalCount?: number, // TODO waiting for BE changes
|
// totalCount?: number, // TODO waiting for BE changes
|
||||||
collectionIsVerified: asset.collection?.isVerified,
|
collectionIsVerified: asset.collection?.isVerified,
|
||||||
rarity: {
|
rarity: {
|
||||||
primaryProvider: 'Rarity Sniper', // TODO update when backend adds more providers
|
primaryProvider: 'Rarity Sniper', // TODO update when backend adds more providers
|
||||||
providers: asset.rarities,
|
providers: asset.rarities.map((rarity: Rarity) => {
|
||||||
|
return {
|
||||||
|
...rarity,
|
||||||
|
provider: 'Rarity Sniper',
|
||||||
|
}
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
owner: asset.ownerAddress,
|
owner: asset.ownerAddress,
|
||||||
creator: {
|
creator: {
|
||||||
|
Loading…
Reference in New Issue
Block a user