Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pop #1

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 6 additions & 18 deletions src/components/FetchCandyMachine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ import { FC, useEffect, useState } from "react"
import styles from "../styles/custom.module.css"

export const FetchCandyMachine: FC = () => {
const [candyMachineAddress, setCandyMachineAddress] = useState(
"9tQLFyLeaUwQ1PN2YDiFztZDxu4KT6px8CBYEapkshAD"
)
const [candyMachineAddress, setCandyMachineAddress] = useState(null)
const [candyMachineData, setCandyMachineData] = useState(null)
const [pageItems, setPageItems] = useState(null)
const [page, setPage] = useState(1)


const { connection } = useConnection()
const metaplex = Metaplex.make(connection)

Expand Down Expand Up @@ -61,23 +60,12 @@ export const FetchCandyMachine: FC = () => {
}
}

// next page
const next = async () => {
setPage(page + 1)
}

// fetch placeholder candy machine on load
useEffect(() => {
fetchCandyMachine()
}, [])
const getPage = async (page, perPage) => {}

// fetch metadata for NFTs when page or candy machine changes
useEffect(() => {
if (!candyMachineData) {
return
}
getPage(page, 9)
}, [candyMachineData, page])
const prev = async () => {}

const next = async () => {}

return (
<div>
Expand Down
50 changes: 2 additions & 48 deletions src/components/FetchNft.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,7 @@ import { FC, useEffect, useState } from "react"
import styles from "../styles/custom.module.css"

export const FetchNft: FC = () => {
const [nftData, setNftData] = useState(null)
const fetchNfts = async () => {}

const { connection } = useConnection()
const wallet = useWallet()
const metaplex = Metaplex.make(connection).use(walletAdapterIdentity(wallet))

// fetch nfts
const fetchNfts = async () => {
if (!wallet.connected) {
return
}

// fetch NFTs for connected wallet
const nfts = await metaplex
.nfts()
.findAllByOwner({ owner: wallet.publicKey })
.run()

// fetch off chain metadata for each NFT
let nftData = []
for (let i = 0; i < nfts.length; i++) {
let fetchResult = await fetch(nfts[i].uri)
let json = await fetchResult.json()
nftData.push(json)
}

// set state
setNftData(nftData)
}

// fetch nfts when connected wallet changes
useEffect(() => {
fetchNfts()
}, [wallet])

return (
<div>
{nftData && (
<div className={styles.gridNFT}>
{nftData.map((nft) => (
<div>
<ul>{nft.name}</ul>
<img src={nft.image} />
</div>
))}
</div>
)}
</div>
)
return <div></div>
}