Skip to content

Commit 1403cb9

Browse files
committed
NFT template React (UX/UI improvement)
1 parent e982c06 commit 1403cb9

22 files changed

Lines changed: 225 additions & 207 deletions

package-lock.json

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"@types/node": "^20.11.17",
2424
"@types/react": "^18.2.22",
2525
"@types/react-dom": "^18.2.7",
26+
"@types/react-modal": "^3.16.3",
2627
"@vitejs/plugin-react": "^4.1.0",
2728
"@wagmi/cli": "^2.1.0",
2829
"autoprefixer": "^10.4.17",

src/components/Btn.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const Btn = ({
55
loading,
66
onClick,
77
children,
8-
disabled = false,
8+
disabled,
99
...attrs
1010
}: {
1111
[x: string]: any
@@ -24,7 +24,7 @@ const Btn = ({
2424
}
2525

2626
return (
27-
<button {...attrs} className="relative" onClick={(e) => handleClick(e)}>
27+
<button {...attrs} className={disabled ? 'relative disabled' : 'relative'} onClick={(e) => handleClick(e)}>
2828
{loading && <Spinner />}
2929
<span className={loading ? 'opacity-0' : ''}>{children}</span>
3030
</button>

src/components/CollectionInfo.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import { constants, ethers } from 'ethers'
22
import { useEffect, useState } from 'react'
33
import Mint from './Mint'
44
import { CHAIN_ID } from '../lib/config'
5-
import useWeb3Provider from '../hooks/useWeb3Provider'
5+
import { useWeb3Context } from '../context/Web3Context'
66
import MintNestable from './MintNestable'
77

88
interface CollectionInfoProps {
99
nftId: number
1010
}
1111

1212
export default function CollectionInfo({ nftId }: CollectionInfoProps) {
13-
const { state } = useWeb3Provider()
13+
const { state } = useWeb3Context()
1414

1515
const [totalSupply, setTotalSupply] = useState(0)
1616
const [maxSupply, setMaySupply] = useState(0)
@@ -67,11 +67,11 @@ export default function CollectionInfo({ nftId }: CollectionInfoProps) {
6767
function collectionLink() {
6868
switch (CHAIN_ID) {
6969
case '0x504':
70-
return `https://moonbeam.moonscan.io/address/${state.collectionInfo.address}`
70+
return `https://moonbeam.moonscan.io/address/${state.collectionInfo?.address}`
7171
case '0x507':
72-
return `https://moonbase.moonscan.io/address/${state.collectionInfo.address}`
72+
return `https://moonbase.moonscan.io/address/${state.collectionInfo?.address}`
7373
case '0x250':
74-
return `https://astar.subscan.io/address/${state.collectionInfo.address}`
74+
return `https://astar.subscan.io/address/${state.collectionInfo?.address}`
7575
default:
7676
console.warn('Missing chainId')
7777
return 'https://moonbeam.moonscan.io'

src/components/IconWallet.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1-
import React from 'react'
2-
3-
export default function IconWallet () {
1+
export default function IconWallet() {
42
return (
5-
<svg
6-
xmlns="http://www.w3.org/2000/svg"
7-
width="24"
8-
height="25"
9-
viewBox="0 0 24 25"
10-
fill="none"
11-
>
3+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="25" viewBox="0 0 24 25" fill="none">
124
<path
135
d="M4 3C2.89 3 2 3.9 2 5V19C2 19.5304 2.21071 20.0391 2.58579 20.4142C2.96086 20.7893 3.46957 21 4 21H18C18.5304 21 19.0391 20.7893 19.4142 20.4142C19.7893 20.0391 20 19.5304 20 19V16.72C20.59 16.37 21 15.74 21 15V9C21 8.26 20.59 7.63 20 7.28V5C20 4.46957 19.7893 3.96086 19.4142 3.58579C19.0391 3.21071 18.5304 3 18 3H4ZM4 5H18V7H12C11.4696 7 10.9609 7.21071 10.5858 7.58579C10.2107 7.96086 10 8.46957 10 9V15C10 15.5304 10.2107 16.0391 10.5858 16.4142C10.9609 16.7893 11.4696 17 12 17H18V19H4V5ZM12 9H19V15H12V9ZM15 10.5C14.6022 10.5 14.2206 10.658 13.9393 10.9393C13.658 11.2206 13.5 11.6022 13.5 12C13.5 12.3978 13.658 12.7794 13.9393 13.0607C14.2206 13.342 14.6022 13.5 15 13.5C15.3978 13.5 15.7794 13.342 16.0607 13.0607C16.342 12.7794 16.5 12.3978 16.5 12C16.5 11.6022 16.342 11.2206 16.0607 10.9393C15.7794 10.658 15.3978 10.5 15 10.5Z"
146
fill="currentColor"

src/components/Main.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
import useWeb3Provider from '../hooks/useWeb3Provider'
1+
import { useEffect } from 'react'
2+
import { ethers } from 'ethers'
3+
import { toast } from 'react-toastify'
4+
5+
import { useWeb3Context } from '../context/Web3Context'
26
import Btn from './Btn'
37
import NftGallery from './Nft/NftGallery'
48
import CollectionInfo from './CollectionInfo'
59
import WalletConnect from './WalletConnect'
6-
import { toast } from 'react-toastify'
710
import {
811
addChain,
912
changeChain,
@@ -13,11 +16,9 @@ import {
1316
metamaskNotSupportedMessage
1417
} from '../lib/utils'
1518
import { CHAIN_ID, CONTRACT_ADDRESS } from '../lib/config'
16-
import { ethers } from 'ethers'
17-
import { useEffect } from 'react'
1819

1920
export default function Main() {
20-
const { state, setState, filterNfts, initContract, getCollectionInfo, getMyNftIDs, getNfts } = useWeb3Provider()
21+
const { state, setState, filterNfts, initContract, getCollectionInfo, getMyNftIDs, getNfts } = useWeb3Context()
2122

2223
const connectWallet = async () => {
2324
if (state.isAuthenticated) return
@@ -143,7 +144,7 @@ export default function Main() {
143144
)}
144145

145146
{/* Collection loaded */}
146-
{state.collectionInfo && (
147+
{state.collectionInfo?.address && (
147148
<div>
148149
{(() => {
149150
if (Number(state.collectionInfo.totalSupply) === 0) {

src/components/Mint.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import Spinner from './Spinner'
44
import { transactionError } from '../lib/utils/errors'
55
import { checkInputAmount, getContract } from '../lib/utils'
66
import { toast } from 'react-toastify'
7-
import useWeb3Provider from '../hooks/useWeb3Provider'
7+
import { useWeb3Context } from '../context/Web3Context'
88
import { CONTRACT_ADDRESS } from '../lib/config'
99

1010
export default function Mint() {
11-
const { state, refreshNfts } = useWeb3Provider()
11+
const { state, refreshNfts } = useWeb3Context()
1212

1313
const [loading, setLoading] = useState(false)
1414
const [amount, setAmount] = useState(1)
@@ -40,6 +40,7 @@ export default function Mint() {
4040
toast('Token minting has started', { type: 'success' })
4141

4242
await tx.wait()
43+
4344
await refreshNfts(nftContract)
4445
} catch (e) {
4546
transactionError('Unsuccessful mint', e)

src/components/MintNestable.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { BigNumber } from 'ethers'
22
import { BaseSyntheticEvent, useState } from 'react'
33
import { toast } from 'react-toastify'
44

5-
import useWeb3Provider from '../hooks/useWeb3Provider'
5+
import { useWeb3Context } from '../context/Web3Context'
66
import { CONTRACT_ADDRESS } from '../lib/config'
77
import { transactionError } from '../lib/utils/errors'
88
import { checkInputAddress, getContract, isCollectionNestable } from '../lib/utils'
@@ -13,7 +13,7 @@ interface MintNestableProps {
1313
}
1414

1515
export default function MintNestable({ nftId }: MintNestableProps) {
16-
const { state, getSigner, refreshNfts } = useWeb3Provider()
16+
const { state, getPendingChildren, getSigner, refreshNfts } = useWeb3Context()
1717

1818
const [loading, setLoading] = useState(false)
1919
const [address, setAddress] = useState('')
@@ -49,6 +49,8 @@ export default function MintNestable({ nftId }: MintNestableProps) {
4949
toast('Token minting has started', { type: 'success' })
5050

5151
await tx.wait()
52+
53+
getPendingChildren(nftId)
5254
await refreshNfts(nftContract)
5355
} catch (e) {
5456
transactionError('Unsuccessful mint', e)
@@ -84,6 +86,8 @@ export default function MintNestable({ nftId }: MintNestableProps) {
8486
toast('Token minting has started', { type: 'success' })
8587

8688
await tx.wait()
89+
90+
getPendingChildren(nftId)
8791
await refreshNfts(childNftContract)
8892
} catch (e) {
8993
console.log(e)

src/components/Nft/NftCard.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import { useMemo, useState } from 'react'
2-
import Modal from 'react-modal'
32

4-
import useWeb3Provider from '../../hooks/useWeb3Provider'
3+
import { useWeb3Context } from '../../context/Web3Context'
54
import ScrollLock from '../../lib/utils/scroll-lock'
65
import Header from '../Header'
76
import NftNestable from './NftNestable'
87

8+
// @ts-ignore
9+
import Modal from 'react-modal'
910
interface NftProps {
1011
nft: Nft
1112
open?: Boolean
1213
}
1314

1415
export default function NftCard({ nft, open }: NftProps) {
15-
const { state } = useWeb3Provider()
16+
const { state } = useWeb3Context()
1617
const [isModalOpen, setIsOpen] = useState(false)
1718

1819
const isMyNFT = useMemo(() => {

src/components/Nft/NftGallery.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { useEffect, useMemo } from 'react'
2-
import useWeb3Provider from '../../hooks/useWeb3Provider'
2+
import { useWeb3Context } from '../../context/Web3Context'
33
import NftCard from './NftCard'
44
import Spinner from '../Spinner'
55

66
export default function NftGallery() {
7-
const { state, setState } = useWeb3Provider()
7+
const { state, setState } = useWeb3Context()
88

99
const nfts = useMemo(() => {
1010
return state.filterByWallet ? state.nfts.filter((item) => state.myNftIDs.includes(item.id)) : state.nfts

0 commit comments

Comments
 (0)