Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ntend into develop
  • Loading branch information
scguaquetam committed Sep 26, 2023
2 parents db5fa23 + a63f3d5 commit 9d9ed43
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 28 deletions.
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
NEXT_PUBLIC_ALCHEMY_API_KEY=''
NEXT_PUBLIC_CHAIN_ID=''
NEXT_PUBLIC_ENABLE_TESTNETS=''
NEXT_PUBLIC_EVM_EXPLORER=''
38 changes: 24 additions & 14 deletions src/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,34 @@ interface ContractsJson {
meetdAppNFT: typeof meetdAppNFTJsonPolygon | typeof meetdAppNFTJsonMumbai
}

export const CHAINID = process.env.NEXT_PUBLIC_CHAIN_ID
const mumbaiContracts: ContractsJson = {
meetdAppFactory: meetdAppFactoryJsonMumbai,
meetdAppEvent: meetdAppEventJsonMumbai,
meetdAppNFT: meetdAppNFTJsonMumbai
}

const polygonContracts: ContractsJson = {
meetdAppFactory: meetdAppFactoryJsonPolygon,
meetdAppEvent: meetdAppEventJsonPolygon,
meetdAppNFT: meetdAppNFTJsonPolygon
}

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
}
const setChainId = () =>
process.env.NEXT_PUBLIC_ENABLE_TESTNETS === 'true' ? 80001 : 137

export const CHAINID = setChainId()

const setContractsJson = (): ContractsJson => {
return process.env.NEXT_PUBLIC_ENABLE_TESTNETS === 'true'
? mumbaiContracts
: polygonContracts
}

export const CONTRACTS_JSON = setContractsJson()
12 changes: 3 additions & 9 deletions src/pages/events/[id]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ 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,14 +188,9 @@ 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(
contractsJson.meetdAppFactory.address,
contractsJson.meetdAppFactory.abi,
CONTRACTS_JSON.meetdAppFactory.address,
CONTRACTS_JSON.meetdAppFactory.abi,
rpcProvider
) as MeetdAppFactory

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

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

Expand Down
10 changes: 6 additions & 4 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ 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(
contractsJson.meetdAppFactory.address,
contractsJson.meetdAppFactory.abi,
const rpcProvider: ethers.providers.JsonRpcProvider =
new ethers.providers.JsonRpcProvider(PROVIDER)

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

setIsLoading(false)
Expand Down

0 comments on commit 9d9ed43

Please sign in to comment.