Skip to content

Commit

Permalink
..
Browse files Browse the repository at this point in the history
  • Loading branch information
adetyaz committed Jul 8, 2024
1 parent 2470ccb commit 9e0b0ce
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 88 deletions.
File renamed without changes
8 changes: 4 additions & 4 deletions src/app/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ export default function Home({ params }: { params: { id: string } }) {
fetchPhygitalData()

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

const removePrefix = (uri: any) => {
Expand Down
145 changes: 74 additions & 71 deletions src/components/claim-nft.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ 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 Moralis from 'moralis'
// import abi from '@/lib/abi'
import { X } from 'lucide-react'

Expand All @@ -16,93 +16,96 @@ 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 chainId = useChainId()

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

// useEffect(() => {
// const fetch = async () => {
// try {
// await Moralis.start({
// apiKey: process.env.NEXT_PUBLIC_MORALIS_API_KEY,
// })
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: '0x771C15e87272d6A57900f009Cd833b38dd7869e5',
// address: contractAddress,
// abi: {
// anonymous: false,
// inputs: [
// {
// internalType: 'address',
// name: 'phygitalcontractAddr',
// type: 'address',
// },
// {
// internalType: 'uint256',
// name: 'amount',
// type: 'uint256',
// },
// {
// internalType: 'uint256',
// name: 'tokenId',
// type: 'uint256',
// },
// { internalType: 'bytes', name: 'data', type: 'bytes' },
// { internalType: 'string', name: '_uri', type: 'string' },
// ],
// name: 'createFanToken',
// outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
// stateMutability: 'nonpayable',
// type: 'function',
// },
// })
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]) {
// setToken(response.raw.result[0].data.currentIndex)
// }
// } catch (e) {
// console.error(e)
// }
// }
// 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()

// fetch()
// }, [])
console.log(sold)
}, [])

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

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

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

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

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

// const result = await tx.wait()
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
// }
// }
// 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 removePrefix = (uri) => {
return uri?.substring(7, uri.length)
Expand Down
23 changes: 10 additions & 13 deletions src/components/voice-assistant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const VoiceAssistant = ({ productInfo, brandName }: any) => {
you are a brand and products spokesperson for ${brandName}, use this to answer questions "${productInfo}". Respond to inquiries with clear, concise answers under 20 words, use information shared only.`,
},
])
const [gender, setGender] = useState('female')

useEffect(() => {
const recognition = new (window as any).webkitSpeechRecognition()
Expand Down Expand Up @@ -98,14 +99,16 @@ export const VoiceAssistant = ({ productInfo, brandName }: any) => {
const utterance = new SpeechSynthesisUtterance(text)

const voices = synth.getVoices()
const femaleVoice = voices.find(
(voice) => /female/i.test(voice.name) || /woman/i.test(voice.name)
const selectedVoice = voices.find(
(voice) =>
(gender === 'female' && /female/i.test(voice.name)) ||
(gender === 'male' && /male/i.test(voice.name))
)

if (femaleVoice) {
utterance.voice = femaleVoice
if (selectedVoice) {
utterance.voice = selectedVoice
} else if (voices.length > 0) {
// Fallback to the first voice if no female voice is found
// Fallback to the first voice if no matching gender voice is found
utterance.voice = voices[0]
}

Expand All @@ -122,18 +125,12 @@ export const VoiceAssistant = ({ productInfo, brandName }: any) => {
<div className='flex flex-col justify-center items-center text-center'>
{transcript && (
<div className='mb-4 bg-black text-white p-4 rounded-md w-3/4'>
<p>
User:
{transcript}
</p>
<p>User: &nbsp;{transcript}</p>
</div>
)}
{response && (
<div className='mb-4 bg-black text-white p-4 rounded-md w-3/4'>
<p>
Assistant:
{response}
</p>
<p>Assistant: &nbsp;{response}</p>
</div>
)}
<div>
Expand Down

0 comments on commit 9e0b0ce

Please sign in to comment.