From 0213d627153df9e6f85f4058996cf76da9469d5a Mon Sep 17 00:00:00 2001 From: Rushikeshnimkar Date: Tue, 15 Oct 2024 18:27:08 +0530 Subject: [PATCH] fix aptos --- components/NftdataCard.tsx | 19 ++++++------ components/UserNFTs.tsx | 59 +++++++++++++++++++------------------- pages/subscription.tsx | 13 ++++----- 3 files changed, 45 insertions(+), 46 deletions(-) diff --git a/components/NftdataCard.tsx b/components/NftdataCard.tsx index e474366..523fa9f 100644 --- a/components/NftdataCard.tsx +++ b/components/NftdataCard.tsx @@ -113,15 +113,14 @@ const NftdataCard: React.FC = ({ metadata?.image || metadata?.image_url || metadata?.imageUrl || - metadata?.url || - metaData.current_token_data.cdn_asset_uris?.cdn_image_uri; + metadata?.url; setImageSrc(imageUrl?.replace("ipfs://", "https://ipfs.io/ipfs/")); setAttributes({ - name: metadata.name || metaData.current_token_data.token_name, - description: metadata.description || metaData.current_token_data.description, + name: metadata.name, + description: metadata.description, symbol: metadata.symbol, externalUrl: metadata.external_url, - collection: metadata.collection || metaData.current_token_data.current_collection, + collection: metadata.collection, ...metadata.attributes, }); } catch (error) { @@ -134,7 +133,6 @@ const NftdataCard: React.FC = ({ fetchMetaData(); }, [metaData, chainSymbol]); - if (isLoading) { return (
@@ -171,9 +169,12 @@ const NftdataCard: React.FC = ({
- {metaData.current_token_data.token_name} { console.error( @@ -181,7 +182,7 @@ const NftdataCard: React.FC = ({ (e.target as HTMLImageElement).src ); (e.target as HTMLImageElement).src = - "/path/to/placeholder/image.png"; + "/path/to/placeholder/image.png"; // Fallback image }} />
diff --git a/components/UserNFTs.tsx b/components/UserNFTs.tsx index b27fb91..6f24000 100644 --- a/components/UserNFTs.tsx +++ b/components/UserNFTs.tsx @@ -61,36 +61,36 @@ const fetchUserNFTs = async (chainSymbol: string) => { return filteredNFTs; } else if (chainSymbol === 'apt') { - const APTOS_GRAPHQL_ENDPOINT = process.env.NEXT_PUBLIC_APTOS_GRAPHQL_ENDPOINT; + const APTOS_GRAPHQL_ENDPOINT = process.env.NEXT_PUBLIC_GRAPHQL_APTOS; const query = ` - query GetAccountNfts($address: String) { - current_token_ownerships_v2( - where: {owner_address: {_eq: $address}, amount: {_gt: "0"}} - ) { - current_token_data { - collection_id - largest_property_version_v1 - current_collection { - collection_id - collection_name - description - creator_address - uri - __typename - } - description - token_name - token_data_id - token_standard - token_uri - __typename - } - owner_address - amount - __typename - } - } + query GetAccountNfts($address: String) { +current_token_ownerships_v2( + where: {owner_address: {_eq: $address}, amount: {_gt: "0"}} +) { + current_token_data { + collection_id + largest_property_version_v1 + current_collection { + collection_id + collection_name + description + creator_address + uri + __typename + } + description + token_name + token_data_id + token_standard + token_uri + __typename + } + owner_address + amount + __typename +} +} `; const variables = { address: userAddress }; @@ -114,9 +114,8 @@ const fetchUserNFTs = async (chainSymbol: string) => { cdn_asset_uris: { cdn_image_uri: nft.current_token_data.token_uri, }, - collection: nft.current_token_data.current_collection.collection_name, - symbol: '', current_collection: nft.current_token_data.current_collection, + symbol: '', }, })); diff --git a/pages/subscription.tsx b/pages/subscription.tsx index c81ebed..c7c2a3f 100644 --- a/pages/subscription.tsx +++ b/pages/subscription.tsx @@ -168,12 +168,11 @@ const Subscription = () => { }); if (loggedin && !loading && isDataChecked && !nftLoading) { - if (((nftdata && nftdata.length === 0) || !nftdata) && !trialsubscriptiondata && !nftError) { - console.log("Conditions met for redirection to /plans"); + if ((!nftdata || nftdata.length === 0) && !trialsubscriptiondata && !nftError) { + console.log("No NFTs found, redirecting to /plans"); const redirectTimer = setTimeout(() => { - console.log("Redirecting to /plans"); router.push("/plans"); - }, 1000); // 1 second delay + }, 1000); return () => clearTimeout(redirectTimer); } else { @@ -183,7 +182,6 @@ const Subscription = () => { }, [loggedin, loading, isDataChecked, nftLoading, nftdata, trialsubscriptiondata, nftError]); - const handleSubmit = async (e: FormEvent) => { e.preventDefault(); @@ -451,8 +449,9 @@ const Subscription = () => { setNftError(null); try { const chainSymbol = Cookies.get("Chain_symbol") || "sol"; // Default to "sol" if not set - const nfts = await fetchUserNFTs(wallet); + const nfts = await fetchUserNFTs(chainSymbol); setnftdata(nfts); + console.log("Fetched NFTs:", nfts); } catch (error) { console.error("Error fetching NFTs:", error); setNftError("Failed to fetch NFTs"); @@ -461,7 +460,7 @@ const Subscription = () => { } } }; - + fetchNFTs(); }, [wallet]);