Skip to content

Commit

Permalink
Merge pull request #163 from NetSepio/rushikesh-nft
Browse files Browse the repository at this point in the history
fix aptos
  • Loading branch information
Rushikeshnimkar authored Oct 15, 2024
2 parents 0094722 + 0213d62 commit 8a27e77
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 46 deletions.
19 changes: 10 additions & 9 deletions components/NftdataCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,14 @@ const NftdataCard: React.FC<ReviewCardProps> = ({
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) {
Expand All @@ -134,7 +133,6 @@ const NftdataCard: React.FC<ReviewCardProps> = ({
fetchMetaData();
}, [metaData, chainSymbol]);


if (isLoading) {
return (
<div className="flex flex-col items-center justify-center w-full max-w-sm mx-auto">
Expand Down Expand Up @@ -171,17 +169,20 @@ const NftdataCard: React.FC<ReviewCardProps> = ({
<div>
<div className="flex flex-col">
<div className="">
<img
<img
alt={metaData.current_token_data.token_name}
src={imageSrc || "/path/to/placeholder/image.png"}
src={
imageSrc ||
metaData.current_token_data.cdn_asset_uris?.cdn_image_uri
}
className="w-full h-48 object-cover rounded-lg"
onError={(e) => {
console.error(
"Image failed to load:",
(e.target as HTMLImageElement).src
);
(e.target as HTMLImageElement).src =
"/path/to/placeholder/image.png";
"/path/to/placeholder/image.png"; // Fallback image
}}
/>
</div>
Expand Down
59 changes: 29 additions & 30 deletions components/UserNFTs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand All @@ -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: '',
},
}));

Expand Down
13 changes: 6 additions & 7 deletions pages/subscription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -183,7 +182,6 @@ const Subscription = () => {
}, [loggedin, loading, isDataChecked, nftLoading, nftdata, trialsubscriptiondata, nftError]);



const handleSubmit = async (e: FormEvent) => {
e.preventDefault();

Expand Down Expand Up @@ -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");
Expand All @@ -461,7 +460,7 @@ const Subscription = () => {
}
}
};

fetchNFTs();
}, [wallet]);

Expand Down

0 comments on commit 8a27e77

Please sign in to comment.