Skip to content

Commit

Permalink
added view details & view select screens 🏋🏾
Browse files Browse the repository at this point in the history
  • Loading branch information
dysbulic committed Mar 21, 2022
1 parent 22c52ec commit 8291e65
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 40 deletions.
13 changes: 8 additions & 5 deletions packages/ui/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import NextLink from 'next/link'
import {
Box, Container, Flex, Image, Stack, Tooltip,
Table, Thead, Tbody, Tr, Th, Td,
Spinner, Text, Link as ChakraLink,
Spinner, Text, Link as ChakraLink, chakra,
} from '@chakra-ui/react'
import Markdown from 'react-markdown'
import { httpURL } from 'lib/helpers'
Expand Down Expand Up @@ -42,7 +42,7 @@ const Home: NextPage = () => {
)

const setToken = (index: number, info: Record<string, unknown>) => {
setTokens((tkns) => ([
setTokens((tkns: Array<TokenState>) => ([
...tkns.slice(0, index),
{ ...tkns[index], ...info },
...tkns.slice(index + 1),
Expand Down Expand Up @@ -87,8 +87,11 @@ const Home: NextPage = () => {
return (
<Container maxW="full">
<Head>
<title>’Chievemint NFTs</title>
<meta name="description" content="MetaGame’s ’Chievemint NFTs" />
<chakra.title>’Chievemint NFTs</chakra.title>
<chakra.meta
name="description"
content="MetaGame’s ’Chievemint NFTs"
/>
</Head>

<Flex h="33vh" maxW="40rem" margin="auto">
Expand Down Expand Up @@ -118,7 +121,7 @@ const Home: NextPage = () => {
</Tr>
</Thead>
<Tbody>
{tokens.map((token) => {
{tokens.map((token: TokenState) => {
if(token.state === 'loaded') {
return (
<Tr key={token.id}>
Expand Down
87 changes: 68 additions & 19 deletions packages/ui/pages/view/[nft_id].tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,48 @@
import { useEffect, useMemo, useState } from 'react'
import {
Alert, AlertDescription, AlertIcon, AlertTitle, Box,
Button, Container, Image, Input,
Button, Container, Image, Input, chakra, Heading,
Flex, Spinner, Text,
} from '@chakra-ui/react'
import { ethers } from 'ethers'
import Head from 'next/head'
import { useRouter } from 'next/router'
import type { NextPage } from 'next'
import { httpURL, isEmpty } from '../../lib/helpers'
import { Maybe } from '../../lib/types'
import address from '../../contracts/BulkDisbersableNFTs.address'
import abi from '../../contracts/BulkDisbersableNFTs.abi'
import ReactMarkdown from 'react-markdown'
import { httpURL, isEmpty } from 'lib/helpers'
import { Maybe } from 'lib/types'
import address from 'contracts/BulkDisbersableNFTs.address'
import abi from 'contracts/BulkDisbersableNFTs.abi'

const Markdown = chakra(ReactMarkdown)

const View: NextPage = () => {
const router = useRouter()
const tokenId = router.query.nft_id
const [metadata, setMetadata] = useState<Record<string, unknown>>()
const [error, setError] = useState<string>()

let ethereum: Maybe<ethers.providers.ExternalProvider> = null
if (typeof window !== 'undefined') {
({ ethereum } = window)
}
// let ethereum: Maybe<ethers.providers.ExternalProvider> = null
// if (typeof window !== 'undefined') {
// ({ ethereum } = window)
// }
// const provider = useMemo(
// () => (
// ethereum ? new ethers.providers.Web3Provider(ethereum) : null
// ),
// [ethereum],
// )
const provider = useMemo(
() => (
ethereum ? new ethers.providers.Web3Provider(ethereum) : null
new ethers.providers.JsonRpcProvider(
process.env.NEXT_PUBLIC_TOKEN_RPC
)
),
[ethereum],
[],
)
const contract = useMemo(
() => (provider ? (
new ethers.Contract(address, abi, provider.getSigner())
new ethers.Contract(address, abi, provider)
) : (
null
)),
Expand Down Expand Up @@ -70,16 +82,53 @@ const View: NextPage = () => {
)
}

if(!metadata) {
return (
<Flex align="center" justify="center" h="100vh">
<Spinner thickness="4px" speed="1s" mr={2}/>
<Text>Loading Metadata For Token #{tokenId}</Text>
</Flex>
)
}

const {
name, image, animation_url: animationURL,
description,
} = metadata

return (
<Container>
<Container maxW="full" align="center">
<Head>
<title>View NFT</title>
<meta name="description" content="MetaGame’s ’Chievemint NFTs" />
<title>View NFT #{tokenId}</title>
<meta
name="description"
content="MetaGame’s ’Chievemint NFTs"
/>
</Head>

<pre>
{JSON.stringify(metadata, null, 2)}
</pre>
{name && <Heading>{name}</Heading>}
{image && (
<Image
src={httpURL(image)}
alt={name}
maxW={64}
maxH={64}
/>
)}
{description && (
<Markdown
sx={{ a: { textDecoration: 'underline' } }}
>
{description}
</Markdown>
)}
{animationURL && (
<chakra.video
maxW={60} maxH={60}
controls autoPlay loop muted
>
<chakra.source src={httpURL(animationURL)}/>
</chakra.video>
)}
</Container>
)
}
Expand Down
51 changes: 35 additions & 16 deletions packages/ui/pages/view/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { useEffect, useMemo, useState } from 'react'
import { Box, Button, Container, Input } from '@chakra-ui/react'
import {
useEffect, useMemo, useState, ChangeEvent, FormEvent
} from 'react'
import {
chakra, Box, Button, Container, Input, Stack, Heading,
} from '@chakra-ui/react'
import { ethers } from 'ethers'
import Head from 'next/head'
import { useRouter } from 'next/router'
Expand All @@ -14,19 +18,27 @@ const View: NextPage = () => {
const [value, setValue] = useState<string | number>()
const router = useRouter()

let ethereum: Maybe<ethers.providers.ExternalProvider> = null
if (typeof window !== 'undefined') {
({ ethereum } = window)
}
// let ethereum: Maybe<ethers.providers.ExternalProvider> = null
// if (typeof window !== 'undefined') {
// ({ ethereum } = window)
// }
// const provider = useMemo(
// () => (
// ethereum ? new ethers.providers.Web3Provider(ethereum) : null
// ),
// [ethereum],
// )
const provider = useMemo(
() => (
ethereum ? new ethers.providers.Web3Provider(ethereum) : null
new ethers.providers.JsonRpcProvider(
process.env.NEXT_PUBLIC_TOKEN_RPC
)
),
[ethereum],
[],
)
const contract = useMemo(
() => (provider ? (
new ethers.Contract(address, abi, provider.getSigner())
new ethers.Contract(address, abi, provider)
) : (
null
)),
Expand All @@ -49,35 +61,42 @@ const View: NextPage = () => {
return (
<Container>
<Head>
<title>View A NFT</title>
<meta
<chakra.title>View A NFT</chakra.title>
<chakra.meta
name="description"
content="Pick one of MetaGame’s ’Chievemint NFTs to view."
/>
</Head>

<Box
<Stack
as="form"
onSubmit={(evt: React.FormEvent) => {
align="center"
justify="center"
h="100vh"
onSubmit={(evt: FormEvent) => {
evt.preventDefault()
router.push(`/view/0x${Number(value).toString(16)}`)
}}
>
<Heading textAlign="center">
Enter the ID of a ’Chievemint NFT to view.
</Heading>
<Input
type="number"
min={1}
{...{ max, value }}
onChange={({ target: { value }}) => {
autoFocus
onChange={({ target: { value }}: ChangeEvent) => {
setValue(isEmpty(value) ? value : Number(value))
}}
/>
<Button
type="submit"
isDisabled={[undefined, ''].includes(value as string)}
>
View{!isEmpty(value) ? ` #0x${Number(value).toString(16)}` : ''}
View{(value && !isEmpty(value)) ? ` #0x${Number(value).toString(16)}` : ''}
</Button>
</Box>
</Stack>
</Container>
)
}
Expand Down
1 change: 1 addition & 0 deletions packages/ui/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"dom.iterable",
"esnext"
],
"types": ["node"],
"allowJs": false,
"skipLibCheck": true,
"strict": true,
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"compilerOptions": {
"target": "es6",
"lib": ["dom", "dom.iterable", "esnext"],
"types": ["node"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
Expand Down

0 comments on commit 8291e65

Please sign in to comment.