From f0225fd8846ab1b2ba123dd79fc2d1d6bed17049 Mon Sep 17 00:00:00 2001 From: Michael Merz Date: Mon, 11 Dec 2023 14:34:14 -0500 Subject: [PATCH] wip: single nft view --- frontend/src/hooks/useNFTFromCollection.tsx | 6 +- frontend/src/pages/nft-view/NFTView.tsx | 105 ++++++++++---------- 2 files changed, 59 insertions(+), 52 deletions(-) diff --git a/frontend/src/hooks/useNFTFromCollection.tsx b/frontend/src/hooks/useNFTFromCollection.tsx index 6a5201c..cc3c0ac 100644 --- a/frontend/src/hooks/useNFTFromCollection.tsx +++ b/frontend/src/hooks/useNFTFromCollection.tsx @@ -3,9 +3,11 @@ import { AllNftInfoResponseForMetadata } from "types/AllianceNftCollection" import { contracts } from "config" import { useAppContext } from "contexts" -const useNFTFromCollection = (token_id: string | number) => { +const useNFTFromCollection = (token_id: string | number | undefined) => { const { chainId, lcd } = useAppContext() + const token = token_id ? token_id.toString() : "" + return useQuery({ queryKey: ["nft_info", token_id], queryFn: () => { @@ -14,7 +16,7 @@ const useNFTFromCollection = (token_id: string | number) => { contracts[chainId].collection, { all_nft_info: { - token_id: token_id.toString(), + token_id: token, }, } ) diff --git a/frontend/src/pages/nft-view/NFTView.tsx b/frontend/src/pages/nft-view/NFTView.tsx index b565970..938ae85 100644 --- a/frontend/src/pages/nft-view/NFTView.tsx +++ b/frontend/src/pages/nft-view/NFTView.tsx @@ -1,36 +1,58 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -import { mockNFTs } from 'fakeData/mockNFTs'; -import { useParams } from 'react-router-dom'; -import styles from './NFTView.module.scss'; -import { useMediaQuery } from 'usehooks-ts'; -import { NFTViewMobile } from './NFTViewMobile'; -import StarMap from 'components/starmap'; +import { mockNFTs } from "fakeData/mockNFTs" +import { useParams } from "react-router-dom" +import styles from "./NFTView.module.scss" +import { useMediaQuery } from "usehooks-ts" +import { NFTViewMobile } from "./NFTViewMobile" +// import StarMap from "components/starmap" +import { useNFTFromCollection } from "hooks" + +type NFTDetail = Record export const NFTView = () => { - const { id } = useParams(); - const allNFTs = mockNFTs; - const nft = allNFTs[Number(id)]; + const { id } = useParams() + const { data: nftInfo } = useNFTFromCollection(id) + + const ipfsUrl = "https://ipfs.io/ipfs/{id}" + + const details: NFTDetail = {} + + if (nftInfo?.info?.extension?.attributes) { + nftInfo?.info?.extension?.attributes.map((attr) => { + if (attr.trait_type !== "broken" && attr.trait_type !== "rewards") { + details[attr.trait_type] = attr.value + } + }) + } - const isMobile = useMediaQuery('(max-width: 976px)'); + const allNFTs = mockNFTs + const nft = allNFTs[Number(id)] + + const isMobile = useMediaQuery("(max-width: 976px)") if (!id) { - return ( -
- NFT Not Found -
- ) + return
NFT Not Found
} if (isMobile) { - return ( - - ) + return } return (
- NFT + NFT
@@ -42,42 +64,25 @@ export const NFTView = () => {
Unique ID
-
{nft.id}
-
-
-
Biome
-
{nft.biome}
-
-
-
Character
-
{nft.character}
-
-
-
Object
-
{nft.object}
-
-
-
Rarity Score
-
{nft.rarityScore}
-
-
-
Rewards Accrued
-
{nft.rewards}
-
-
-
Claimed
- {/*
{nft.claimed}
*/} -
24 Dec 2023
+
{id}
+ {Object.entries(details).map((entry, i) => { + return ( +
+
{entry[0]}
+
{entry[1]}
+
+ ) + })}
-
+ {/*
-
+
*/}
- + {/* */}
- ); -}; + ) +}