From 734a15e350a1dab3bbfb95f8a092e99439f4e133 Mon Sep 17 00:00:00 2001 From: Charles Bachmeier Date: Tue, 1 Nov 2022 11:06:53 -0700 Subject: [PATCH] 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 --- src/graphql/data/nft/Asset.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/graphql/data/nft/Asset.ts b/src/graphql/data/nft/Asset.ts index d775438a65..2d87a48220 100644 --- a/src/graphql/data/nft/Asset.ts +++ b/src/graphql/data/nft/Asset.ts @@ -1,6 +1,6 @@ import graphql from 'babel-plugin-relay/macro' 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 RelayEnvironment from '../RelayEnvironment' @@ -135,16 +135,16 @@ export function useAssetsQuery( const assets: GenieAsset[] = data.nftAssets?.edges?.map((queryAsset: { node: any }) => { 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 { id: asset.id, - address: asset.collection.nftContracts[0].address, - notForSale: asset.listings === null, + address: asset.collection.nftContracts[0]?.address, + notForSale: asset.listings?.edges.length === 0, collectionName: asset.collection?.name, collectionSymbol: asset.collection?.image?.url, imageUrl: asset.image?.url, animationUrl: asset.animationUrl, - marketplace: asset.listings?.edges[0].node.marketplace.toLowerCase(), + marketplace: asset.listings?.edges[0]?.node.marketplace.toLowerCase(), name: asset.name, priceInfo: asset.listings ? { @@ -158,12 +158,17 @@ export function useAssetsQuery( sellorders: asset.listings?.edges, smallImageUrl: asset.smallImage?.url, tokenId: asset.tokenId, - tokenType: asset.collection.nftContracts[0].standard, + tokenType: asset.collection.nftContracts[0]?.standard, // totalCount?: number, // TODO waiting for BE changes collectionIsVerified: asset.collection?.isVerified, rarity: { 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, creator: {