Commit ed7f126b authored by Charles Bachmeier's avatar Charles Bachmeier Committed by GitHub

fix: updates to wallet asset schemas (#5132)

* updates to wallet asset schemas

* update map type and market check

* much better syntax
parent 9a38c4e5
...@@ -4,6 +4,7 @@ import { useLazyLoadQuery, usePaginationFragment } from 'react-relay' ...@@ -4,6 +4,7 @@ import { useLazyLoadQuery, usePaginationFragment } from 'react-relay'
import { NftBalancePaginationQuery } from './__generated__/NftBalancePaginationQuery.graphql' import { NftBalancePaginationQuery } from './__generated__/NftBalancePaginationQuery.graphql'
import { NftBalanceQuery } from './__generated__/NftBalanceQuery.graphql' import { NftBalanceQuery } from './__generated__/NftBalanceQuery.graphql'
import { NftBalanceQuery_nftBalances$data } from './__generated__/NftBalanceQuery_nftBalances.graphql'
const nftBalancePaginationQuery = graphql` const nftBalancePaginationQuery = graphql`
fragment NftBalanceQuery_nftBalances on Query @refetchable(queryName: "NftBalancePaginationQuery") { fragment NftBalanceQuery_nftBalances on Query @refetchable(queryName: "NftBalancePaginationQuery") {
...@@ -18,6 +19,7 @@ const nftBalancePaginationQuery = graphql` ...@@ -18,6 +19,7 @@ const nftBalancePaginationQuery = graphql`
edges { edges {
node { node {
ownedAsset { ownedAsset {
id
animationUrl animationUrl
collection { collection {
isVerified isVerified
...@@ -105,6 +107,11 @@ const nftBalanceQuery = graphql` ...@@ -105,6 +107,11 @@ const nftBalanceQuery = graphql`
} }
` `
type NftBalanceQueryAsset = NonNullable<
NonNullable<NonNullable<NftBalanceQuery_nftBalances$data['nftBalances']>['edges']>[number]
>
//
// export type TokenQueryData = NonNullable<TokenQuery$data['tokens']>[number]
export function useNftBalanceQuery( export function useNftBalanceQuery(
ownerAddress: string, ownerAddress: string,
collectionFilters?: string[], collectionFilters?: string[],
...@@ -127,31 +134,31 @@ export function useNftBalanceQuery( ...@@ -127,31 +134,31 @@ export function useNftBalanceQuery(
nftBalancePaginationQuery, nftBalancePaginationQuery,
queryData queryData
) )
const walletAssets: WalletAsset[] = data.nftBalances?.edges?.map((queryAsset: { node: any }) => { const walletAssets: WalletAsset[] = data.nftBalances?.edges?.map((queryAsset: NftBalanceQueryAsset) => {
const asset = queryAsset.node.ownedAsset const asset = queryAsset.node.ownedAsset
return { return {
id: asset.id, id: asset?.id,
image_url: asset.image?.url, image_url: asset?.image?.url,
image_preview_url: asset.smallImage?.url, image_preview_url: asset?.smallImage?.url,
name: asset.name, name: asset?.name,
tokenId: asset.tokenId, tokenId: asset?.tokenId,
asset_contract: { asset_contract: {
address: asset.collection?.nftContracts[0].address, address: asset?.collection?.nftContracts?.[0]?.address,
schema_name: asset.collection?.nftContracts[0].standard, schema_name: asset?.collection?.nftContracts?.[0]?.standard,
name: asset.collection?.name, name: asset?.collection?.name,
description: asset.description, description: asset?.description,
image_url: asset.collection?.image?.url, image_url: asset?.collection?.image?.url,
payout_address: queryAsset.node.listingFees && queryAsset.node.listingFees[0].payoutAddress, payout_address: queryAsset?.node?.listingFees?.[0]?.payoutAddress,
}, },
collection: asset.collection, collection: asset?.collection,
collectionIsVerified: asset.collection?.isVerified, collectionIsVerified: asset?.collection?.isVerified,
lastPrice: queryAsset.node.lastPrice?.value, lastPrice: queryAsset.node.lastPrice?.value,
floorPrice: asset.collection?.markets[0]?.floorPrice?.value, floorPrice: asset?.collection?.markets?.[0]?.floorPrice?.value,
creatorPercentage: queryAsset.node.listingFees && queryAsset.node.listingFees[0].basisPoints / 10000, creatorPercentage: queryAsset?.node?.listingFees?.[0]?.basisPoints ?? 0 / 10000,
listing_date: asset.listings ? asset.listings[0]?.edges[0]?.node.createdAt : undefined, listing_date: asset?.listings?.edges?.[0]?.node?.createdAt,
date_acquired: queryAsset.node.lastPrice?.timestamp, date_acquired: queryAsset.node.lastPrice?.timestamp,
sellOrders: asset.listings?.edges, sellOrders: asset?.listings?.edges.map((edge: any) => edge.node),
floor_sell_order_price: asset.listings ? asset.listings[0]?.edges[0]?.node.price.value : undefined, floor_sell_order_price: asset?.listings?.edges?.[0]?.node?.price?.value,
} }
}) })
return { walletAssets, hasNext, isLoadingNext, loadNext } return { walletAssets, hasNext, isLoadingNext, loadNext }
......
...@@ -91,17 +91,19 @@ export const WalletAssetDisplay = ({ asset, isSellMode }: { asset: WalletAsset; ...@@ -91,17 +91,19 @@ export const WalletAssetDisplay = ({ asset, isSellMode }: { asset: WalletAsset;
<Row justifyContent="flex-end"> <Row justifyContent="flex-end">
{uniqueSellOrdersMarketplaces.map((market, index) => { {uniqueSellOrdersMarketplaces.map((market, index) => {
return ( return (
<Box market && (
as="img" <Box
key={index} as="img"
alt={market} key={index}
width="16" alt={market}
height="16" width="16"
borderRadius="4" height="16"
marginLeft="4" borderRadius="4"
objectFit="cover" marginLeft="4"
src={`/nft/svgs/marketplaces/${market.toLowerCase()}.svg`} objectFit="cover"
/> src={`/nft/svgs/marketplaces/${market.toLowerCase()}.svg`}
/>
)
) )
})} })}
</Row> </Row>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment