From 9d460935c76869d13c831bc1890837ec0f42f94f Mon Sep 17 00:00:00 2001 From: Shay Patel Date: Sun, 27 Oct 2024 06:24:45 +0000 Subject: [PATCH] Fix USD 1e18 bugs --- components/custom/EventForm.tsx | 6 ++---- lib/createEvent.ts | 2 +- lib/fetchEventDetails.ts | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/components/custom/EventForm.tsx b/components/custom/EventForm.tsx index f6dfe64..4b826c0 100644 --- a/components/custom/EventForm.tsx +++ b/components/custom/EventForm.tsx @@ -19,8 +19,7 @@ const eventSchema = z .refine(Number.isInteger, { message: 'Capacity must be an integer' }), ticketPrice: z .number({ invalid_type_error: 'Ticket price must be a number' }) - .min(0, { message: 'Ticket price must be at least 0' }) - .refine(Number.isInteger, { message: 'Ticket price must be in cents' }), + .min(0, { message: 'Ticket price must be at least 0' }), location: z.string().min(1, { message: 'Location is required' }), eventStartTime: z.preprocess( (val) => @@ -128,9 +127,8 @@ const EventForm = ({ onSubmit }: EventFormProps) => { {/* Ticket Price Field */}
- + diff --git a/lib/createEvent.ts b/lib/createEvent.ts index 7bfca92..d5b64d2 100644 --- a/lib/createEvent.ts +++ b/lib/createEvent.ts @@ -60,7 +60,7 @@ export const createEvent = async ({ description, location, capacity, - ethers.utils.parseEther(ticketPrice.toString()), + Math.floor(ticketPrice * 100), Math.floor(startDate.getTime() / 1000), Math.floor(endDate.getTime() / 1000), images diff --git a/lib/fetchEventDetails.ts b/lib/fetchEventDetails.ts index 4fe42d2..4c08c3c 100644 --- a/lib/fetchEventDetails.ts +++ b/lib/fetchEventDetails.ts @@ -53,7 +53,7 @@ export const fetchEventDetails = async ({ name: eventData.name, date: eventData.eventStartDate.toNumber(), location: eventData.location, - ticketPrice: eventData.ticketPrice.div(ethers.BigNumber.from("1000000000000000000")).toNumber() / 100, + ticketPrice: eventData.ticketPrice.toNumber() / 100, description: eventData.description, capacity: eventData.capacity.toNumber(), ticketsSold: eventData.ticketsSold.toNumber(),