Skip to content

Commit

Permalink
feat: api update
Browse files Browse the repository at this point in the history
  • Loading branch information
adetyaz committed Jul 18, 2024
1 parent f9512de commit 02d1031
Show file tree
Hide file tree
Showing 7 changed files with 810 additions and 107 deletions.
7 changes: 2 additions & 5 deletions src/app/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default function Home({ params }: { params: { id: string } }) {
const webdata = await webxr.json()
const avatardata = await avatarRes.json()

// console.log(data)
console.log(data)
// console.log(webdata)

setProductInfo(data.product_info)
Expand All @@ -66,12 +66,9 @@ export default function Home({ params }: { params: { id: string } }) {

useEffect(() => {
fetchPhygitalData()

// if (account.address) {
setTimeout(() => {
setUnlockClaimed(true)
// // // setUnlocked(false)
}, 30000)
}, 3000)
}, [])

const removePrefix = (uri: any) => {
Expand Down
108 changes: 18 additions & 90 deletions src/components/claim-nft.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,107 +4,34 @@ import { ClaimNftPopUp } from './claim-nft-popup'
import Image from 'next/image'
import { useAccount, useChainId } from 'wagmi'
import { ToastContainer, toast } from 'react-toastify'
// import { useCapabilities, useWriteContracts } from 'wagmi/experimental'
import { useMemo, useState, useEffect } from 'react'
import Moralis from 'moralis'
// import abi from '@/lib/abi'
import { simulateContract, writeContract } from '@wagmi/core'
import { useState } from 'react'
import { X } from 'lucide-react'

import { ConnectWallet } from './connect-wallet'
import { rainbowconfig } from '@/lib/wagmi'
import reward from '@/lib/reward.json'

export const ClaimNft = ({ onClose, freeNft, brandName, contractAddress }) => {
const [claimNft, setClaimNft] = useState(false)
// const [loading, setLoading] = useState(false)
// const [token, setToken] = useState(0)
const [sold, setsold] = useState(0)
const account = useAccount()
const chainId = useChainId()

const handleClick = () => {
console.log('yes')
onClose(false)
}

const fetch = async () => {
try {
await Moralis.start({
apiKey: process.env.NEXT_PUBLIC_MORALIS_API_KEY,
})

const response = await Moralis.EvmApi.events.getContractEvents({
chain: chainId,
order: 'DESC',
topic:
'0x328ff68d0e66694e405c9f8fc906a346b345aa1f87ec216eaa82f2c654d0d34a',
address: contractAddress,
abi: {
anonymous: false,
inputs: [
{
indexed: false,
name: 'currentIndex',
type: 'uint256',
internal_type: 'uint256',
},
{
indexed: false,
name: 'quantity',
type: 'uint256',
internal_type: 'uint256',
},
{
indexed: true,
name: 'creator',
type: 'address',
internal_type: 'address',
},
],
name: 'PhygitalAAssetCreated',
type: 'event',
},
})

// console.log("response", response.raw, response.raw.result[0].data.currentIndex);
if (response.raw.result[0]) {
setsold(response.raw.result[0].data.currentIndex)
}
} catch (e) {
console.error(e)
}
}

useEffect(() => {
fetch()

console.log(sold)
}, [])

const delegateToken = async () => {
setLoading(true)

try {
console.log('ethers', ethers)

if (typeof window !== 'undefined' && window.ethereum) {
const provider = new ethers.providers.Web3Provider(window.ethereum)

const contract = new ethers.Contract(
contractAddress,
abi,
provider.getSigner()
)

const tx = await contract.mint(contractAddress, 1, token, [])

const result = await tx.wait()

// console.log("Result:", result);
setLoading(false)
}
} catch (error) {
console.error('Error handling buy asset:', error)
setLoading(false) // Set loading state to false in case of error
}
const createFanToken = async () => {
console.log('running...')
const abi = reward.abi
const { request } = await simulateContract(rainbowconfig, {
abi,
address: '0x09b6206ff5f662ACbc68286DBbe43b9fB873a955',
// address: '0x771C15e87272d6A57900f009Cd833b38dd7869e5',
functionName: 'createFanToken',
args: [String(contractAddress), 1, 1, '0x0', 'www.xyz.com'],
})
const hash = await writeContract(rainbowconfig, request)

console.log(hash)
}

const removePrefix = (uri) => {
Expand Down Expand Up @@ -243,6 +170,7 @@ export const ClaimNft = ({ onClose, freeNft, brandName, contractAddress }) => {
if (!account.address) {
toast.warning('Connect or Create a wallet')
} else {
createFanToken()
}
}}
>
Expand Down
22 changes: 16 additions & 6 deletions src/components/leaderboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,22 @@ const Leaderboard = () => {
const getBrands = async () => {
const baseUri = process.env.NEXT_PUBLIC_URI || 'https://app.myriadflow.com'

const avatar = await fetch(`${baseUri}/avatars/all`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
})
localStorage.setItem(
'BaseSepoliaChain',
'554b4903-9a06-4031-98f4-48276c427f78'
)
const chaintype = localStorage.getItem('BaseSepoliaChain')

const avatar = await fetch(
`${baseUri}/avatars/all/${chaintype}
`,
{
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
}
)
const avatardata = await avatar.json()
// setAvatar(avatardata);
setAvatar([...avatardata].reverse())
Expand Down
4 changes: 2 additions & 2 deletions src/lib/abi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
;[
export const abi = [
{
inputs: [
{ internalType: 'string', name: 'baseURI', type: 'string' },
Expand Down Expand Up @@ -388,4 +388,4 @@
stateMutability: 'view',
type: 'function',
},
]
] as const
Loading

0 comments on commit 02d1031

Please sign in to comment.