Skip to content

Commit

Permalink
⚡ Was added dynamic routing
Browse files Browse the repository at this point in the history
  • Loading branch information
salviega committed Sep 24, 2023
1 parent d85bc63 commit cb655b2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 19 deletions.
4 changes: 3 additions & 1 deletion src/components/home/Events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export default function Events(props: Props): React.ReactNode {
const { isLoading } = props
const { t } = useTranslation()

const eventId: string = 'mC8cCmWH5Ws8IZQy'

return (
<>
<Flex
Expand Down Expand Up @@ -47,7 +49,7 @@ export default function Events(props: Props): React.ReactNode {
>
<Link
href={{
pathname: `/events/${first_event.id}`
pathname: `/events/${eventId}`
}}
>
<GridItem
Expand Down
17 changes: 17 additions & 0 deletions src/functions/dto/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Event, EventDTO } from '@/models/event.model'
import { BigNumber } from 'ethers'

export function mapDTOtoEvent(eventDTO: EventDTO): Event {
return {
Expand All @@ -15,3 +16,19 @@ export function mapDTOtoEvent(eventDTO: EventDTO): Event {
nftAddress: eventDTO.nftAddress
}
}

export function mapEventToDTO(event: Event): EventDTO {
return {
id: event.id,
name: event.name,
description: event.description,
location: event.location,
totalTickets: BigNumber.from(event.totalTickets),
remainingTickets: BigNumber.from(event.remainingTickets),
startTime: BigNumber.from(event.startTime),
endTime: BigNumber.from(event.endTime),
reedemableTime: BigNumber.from(event.reedemableTime),
ownerAddress: event.ownerAddress,
nftAddress: event.nftAddress
}
}
14 changes: 8 additions & 6 deletions src/pages/events/[id]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,17 @@ const initialEvent: Event = {
function Event(): JSX.Element {
const [event, setEvent] = useState<Event>(initialEvent)
const [isBuyTicketLoading, setIsBuyTicketLoading] = useState<boolean>(false)
const [hasTicket, setHasTicket] = useState<boolean>(false)
const [isLoading, setIsLoading] = useState<boolean>(true)
const [hasTicket, setHasTicket] = useState<boolean>(false)
const [meetdAppEventContract, setMeetdAppEventContract] =
useState<MeetdAppEvent | null>(null)
const [owner, setOwner] = useState<string | undefined>(undefined)

const router = useRouter()

// TODO: generate nanoId
const slug: string | string[] | undefined = router.query?.id
const splitedPath: string[] = router.asPath.split('/')
const id = splitedPath[splitedPath.length - 1]

const { address } = useAccount()
const { chain } = useNetwork()
Expand Down Expand Up @@ -124,7 +125,7 @@ function Event(): JSX.Element {
}

const fetchEventInformation = async () => {
setTimeout(async () => {
try {
const rpcProvider: ethers.providers.JsonRpcProvider =
new ethers.providers.JsonRpcProvider(PROVIDER)

Expand All @@ -134,8 +135,7 @@ function Event(): JSX.Element {
rpcProvider
) as MeetdAppFactory

const eventId: string = 'mC8cCmWH5Ws8IZQy'
const bytesEventId = ethers.utils.toUtf8Bytes(eventId)
const bytesEventId = ethers.utils.toUtf8Bytes(id as string)
const hashBytes32EventId = ethers.utils.keccak256(bytesEventId)

const eventContractAdress: string =
Expand Down Expand Up @@ -172,7 +172,9 @@ function Event(): JSX.Element {

setMeetdAppEventContract(eventContract)
setIsLoading(false)
}, 1000)
} catch (error) {
router.push('/404')
}
}

useEffect(() => {
Expand Down
12 changes: 0 additions & 12 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,6 @@ export default function Home() {

useEffect(() => {
fetchActiveEvents()
// const ethereum = (window as any).ethereum

// if (
// typeof ethereum !== 'undefined' &&
// typeof ethereum === 'object' &&
// typeof ethereum.web3 !== 'undefined'
// ) {
// // MetaMask is installed and web3 is available
// } else {
// // MetaMask is not installed or web3 is not available
// console.log('MetaMask no está instalado en este navegador.')
// }
}, [])

return (
Expand Down

0 comments on commit cb655b2

Please sign in to comment.