Skip to content

Commit

Permalink
Fix USD 1e18 bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
0xShay committed Oct 27, 2024
1 parent 935f057 commit 9d46093
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
6 changes: 2 additions & 4 deletions components/custom/EventForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down Expand Up @@ -128,9 +127,8 @@ const EventForm = ({ onSubmit }: EventFormProps) => {

{/* Ticket Price Field */}
<div>
<Label htmlFor="ticketPrice">Ticket Price (in USD cents)</Label>
<Label htmlFor="ticketPrice">Ticket Price (in USD)</Label>
<Input
type="number"
id="ticketPrice"
{...register('ticketPrice', { valueAsNumber: true })}
/>
Expand Down
2 changes: 1 addition & 1 deletion lib/createEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/fetchEventDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 9d46093

Please sign in to comment.