-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnft.tsx
81 lines (73 loc) · 2.43 KB
/
nft.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import type { BoxProps } from "@chakra-ui/react";
import { Box, HStack, Skeleton, Text, VStack } from "@chakra-ui/react";
import type { FC } from "react";
import { useEffect, useState } from "react";
import type { Abi } from "starknet";
import { json, shortString } from "starknet";
import avnuNft from "../../../../assets/abis/AVNUNft.json";
import environment from "../../../../environment";
import MintButton from "@/lib/shared/components/nft/mint-button";
import type { NftMetadata } from "@/lib/shared/models/nft-metadata";
// Compiled ABI of the AVNUNft contract
const compiledAvnuNft: Abi = json.parse(JSON.stringify(avnuNft)) as Abi;
// Component to display a label and a value
function Info({
label,
value,
}: {
label: string;
value: JSX.Element | string | undefined;
}) {
return (
<HStack align="flex-start">
<Text minW="100px" fontWeight="semibold">
{label}
</Text>
<Text>{value}</Text>
</HStack>
);
}
const Nft: FC<BoxProps> = ({ ...props }) => {
// TODO use the useContractRead hook from starknet-react to get the tokenURI metadata
// const { data: tokenUriData } = ...
// Internal state of the metadata fecthed from the tokenURI
const [metadata, setMetadata] = useState<NftMetadata | undefined>(undefined);
// Update the internal state when the tokenURI data changes
useEffect(() => {
if (tokenUriData) {
fetch(
// eslint-disable-next-line
// @ts-ignore
tokenUriData.uri.reduce(
(acc: string, cur: string) =>
acc + shortString.decodeShortString(cur),
""
)
)
.then((response: Response) => response.json())
.then((response: NftMetadata) => {
setMetadata(response);
});
}
return undefined;
}, [tokenUriData]);
return (
<HStack align="flex-start">
<VStack maxW="300px">
<Skeleton h="300px" w="300px" borderRadius="lg" isLoaded={!!metadata}>
<Box h="full" w="full" {...props}>
<video src={metadata?.external_url} width="400" autoPlay muted loop>
Your browser does not support the video tag.
</video>
</Box>
</Skeleton>
<MintButton w="full" mt={2} />
</VStack>
<VStack align="flex-start" maxW="500px">
<Info label="Name" value={metadata?.name} />
<Info label="Description" value={metadata?.description} />
</VStack>
</HStack>
);
};
export default Nft;