Skip to content

Commit

Permalink
🧑‍💻 Was added the contracts depend of the network
Browse files Browse the repository at this point in the history
  • Loading branch information
salviega committed Sep 26, 2023
1 parent e962f78 commit ade8497
Show file tree
Hide file tree
Showing 9 changed files with 1,379 additions and 8 deletions.
File renamed without changes.
259 changes: 259 additions & 0 deletions src/assets/deployments/mumbai/MeetdAppFactory.json

Large diffs are not rendered by default.

File renamed without changes.
621 changes: 621 additions & 0 deletions src/assets/deployments/polygon/MeetdAppEvent.json

Large diffs are not rendered by default.

File renamed without changes.
453 changes: 453 additions & 0 deletions src/assets/deployments/polygon/MeetdAppNFT.json

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions src/constants/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,38 @@
import meetdAppFactoryJsonMumbai from '@/assets/deployments/mumbai/MeetdAppFactory.json'
import meetdAppEventJsonMumbai from '@/assets/deployments/mumbai/MeetdAppEvent.json'
import meetdAppNFTJsonMumbai from '@/assets/deployments/mumbai/MeetdAppNFT.json'
import meetdAppFactoryJsonPolygon from '@/assets/deployments/polygon/MeetdAppFactory.json'
import meetdAppEventJsonPolygon from '@/assets/deployments/polygon/MeetdAppEvent.json'
import meetdAppNFTJsonPolygon from '@/assets/deployments/polygon/MeetdAppNFT.json'

interface ContractsJson {
meetdAppFactory:
| typeof meetdAppFactoryJsonPolygon
| typeof meetdAppFactoryJsonMumbai
meetdAppEvent:
| typeof meetdAppEventJsonPolygon
| typeof meetdAppEventJsonMumbai
meetdAppNFT: typeof meetdAppNFTJsonPolygon | typeof meetdAppNFTJsonMumbai
}

export const CHAINID = process.env.NEXT_PUBLIC_CHAIN_ID
export const PROVIDER = process.env.NEXT_PUBLIC_ALCHEMY_API_KEY
export const SCAN = (
address: string,
scan: string | undefined = process.env.NEXT_PUBLIC_EVM_EXPLORER
) => `${scan}/${address}`

export const CONTRACTS_JSON = (): ContractsJson => {
if (process.env.NEXT_PUBLIC_ENABLE_TESTNETS === 'true') {
return {
meetdAppEvent: meetdAppEventJsonMumbai,
meetdAppFactory: meetdAppFactoryJsonMumbai,
meetdAppNFT: meetdAppNFTJsonMumbai
}
}
return {
meetdAppEvent: meetdAppEventJsonPolygon,
meetdAppFactory: meetdAppFactoryJsonPolygon,
meetdAppNFT: meetdAppNFTJsonPolygon
}
}
15 changes: 10 additions & 5 deletions src/pages/events/[id]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import PreviousEvents from '@/components/events/PreviousEvents'
import TagsSection from '@/components/events/TagsSection'
import { Flex, useToast } from '@chakra-ui/react'
import { useRouter } from 'next/router'
import MeetdAppFactoryJson from '../../../assets/contracts/MeetdAppFactory.json'
import MeetdAppEventJson from '../../../assets/contracts/MeetdAppEvent.json'
import { CONTRACTS_JSON } from '@/constants/constants'
import { useEffect, useState } from 'react'
import {
MeetdAppEvent,
Expand Down Expand Up @@ -40,6 +39,7 @@ import Loader from '@/components/shared/Loader'
import { useTranslation } from 'react-i18next'

export default function Event(): JSX.Element {
const contractsJson = CONTRACTS_JSON()
const [attendees, setAttendees] = useState<string[]>([])
const [event, setEvent] = useState<Event>(initialEvent)
const [hasTicket, setHasTicket] = useState<boolean>(false)
Expand Down Expand Up @@ -189,9 +189,14 @@ export default function Event(): JSX.Element {
const rpcProvider: ethers.providers.JsonRpcProvider =
new ethers.providers.JsonRpcProvider(PROVIDER)

console.log(
'contractsJson.meetdAppFactory.address: ',
contractsJson.meetdAppFactory.address
)

const meetdAppFactoryContract: MeetdAppFactory = new ethers.Contract(
MeetdAppFactoryJson.address,
MeetdAppFactoryJson.abi,
contractsJson.meetdAppFactory.address,
contractsJson.meetdAppFactory.abi,
rpcProvider
) as MeetdAppFactory

Expand All @@ -203,7 +208,7 @@ export default function Event(): JSX.Element {

const eventContract = new ethers.Contract(
eventContractAdress,
MeetdAppEventJson.abi,
contractsJson.meetdAppEvent.abi,
rpcProvider
) as MeetdAppEvent

Expand Down
7 changes: 4 additions & 3 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Hero from '@/components/home/Hero'
import MiddleSections from '@/components/home/MiddleSections'
import { ethers } from 'ethers'
import { MeetdAppFactory } from '../../@types/typechain-types'
import MeetdAppFactoryJson from '../assets/contracts/MeetdAppFactory.json'
import { CONTRACTS_JSON } from '@/constants/constants'
import Head from 'next/head'
import Navbar from '@/components/shared/Navbar'
import Footer from '@/components/shared/Footer'
Expand All @@ -16,13 +16,14 @@ const metadata = {
}

export default function Home() {
const contractsJson = CONTRACTS_JSON()
const [isLoading, setIsLoading] = useState<boolean>(true)

const fetchActiveEvents = async () => {
setTimeout(() => {
const meetdAppFactoryContract: MeetdAppFactory = new ethers.Contract(
MeetdAppFactoryJson.address,
MeetdAppFactoryJson.abi,
contractsJson.meetdAppFactory.address,
contractsJson.meetdAppFactory.abi,
new ethers.providers.JsonRpcProvider(PROVIDER)
) as MeetdAppFactory

Expand Down

0 comments on commit ade8497

Please sign in to comment.