-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from Ayush272002/bug-usd
Fetch events on homepage and abstract out files
- Loading branch information
Showing
6 changed files
with
93 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { ethers } from "ethers"; | ||
import { getContract } from "./ethers"; | ||
|
||
interface Event { | ||
eventId: number; | ||
name: string; | ||
description: string; | ||
location: string; | ||
capacity: number; | ||
ticketsSold: number; | ||
ticketPrice: number; | ||
eventStartDate: number; | ||
eventEndDate: number; | ||
images: string[]; | ||
eventHost: string; | ||
} | ||
|
||
export const fetchEvents: () => Promise<Event[] | undefined> = async () => { | ||
try { | ||
console.log('Starting events call'); | ||
if (typeof window.ethereum === 'undefined') { | ||
console.error('Ethereum provider not found'); | ||
return; | ||
} | ||
|
||
console.log('Connecting to contract'); | ||
const contract = getContract(); | ||
const eventCount = await contract.eventCounter(); | ||
const eventsData: Event[] = []; | ||
|
||
for (let i = 0; i < eventCount; i++) { | ||
const event = await contract.events(i); | ||
const images = await contract.getEventImages(i); | ||
eventsData.push({ | ||
eventId: i, | ||
name: event.name, | ||
description: event.description, | ||
location: event.location, | ||
capacity: event.capacity.toNumber(), | ||
ticketsSold: event.ticketsSold.toNumber(), | ||
ticketPrice: event.ticketPrice.toNumber() / 100, | ||
eventStartDate: event.eventStartDate.toNumber(), | ||
eventEndDate: event.eventEndDate.toNumber(), | ||
images: images, | ||
eventHost: event.eventHost, | ||
}); | ||
} | ||
|
||
return eventsData; | ||
} catch (error) { | ||
console.error('Failed to fetch events:', error); | ||
} | ||
} |