From f6e4880e2b5858b0e5edbc187410d35be6cde5ed Mon Sep 17 00:00:00 2001 From: Charles Garrett Date: Tue, 23 Jul 2024 12:23:22 -0400 Subject: [PATCH 1/3] chore: Ensure that required ticket metadata sales start/end date are included in payload --- apps/ticketing/src/pages/events/new.tsx | 24 +++++++++++++++++++ apps/ticketing/src/utils/helpers.ts | 31 ++++++++++--------------- 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/apps/ticketing/src/pages/events/new.tsx b/apps/ticketing/src/pages/events/new.tsx index 16d5c83..0adfda1 100644 --- a/apps/ticketing/src/pages/events/new.tsx +++ b/apps/ticketing/src/pages/events/new.tsx @@ -146,6 +146,12 @@ const CreateEvent: NextPageWithLayout = () => { const placeHolderTicket: TicketInfoFormMetadata = { name: 'General Admission', denomination: 'Near', + salesValidThrough: { + startDate: Date.now(), // Milliseconds from Unix Epoch + startTime: '00:00', // Raw 24 hour time string such as 18:00 + endDate: new Date().setDate(Date.now() + 14), // Milliseconds from start date + endTime: '00:00', + }, }; useEffect(() => { @@ -457,6 +463,24 @@ const CreateEvent: NextPageWithLayout = () => { })} /> + + + + diff --git a/apps/ticketing/src/utils/helpers.ts b/apps/ticketing/src/utils/helpers.ts index 24d3b90..f7f4bac 100644 --- a/apps/ticketing/src/utils/helpers.ts +++ b/apps/ticketing/src/utils/helpers.ts @@ -22,7 +22,7 @@ export interface TicketInfoFormMetadata { priceFiat?: string; description?: string | undefined; artwork?: FileList; - salesValidThrough?: DateAndTimeInfo; + salesValidThrough: DateAndTimeInfo; passValidThrough?: DateAndTimeInfo; } @@ -51,7 +51,7 @@ export interface TicketMetadataExtra { priceNear?: string; priceFiat?: string; maxSupply?: number; - salesValidThrough?: DateAndTimeInfo; + salesValidThrough: DateAndTimeInfo; passValidThrough?: DateAndTimeInfo; } @@ -268,10 +268,7 @@ export const estimateCosts = ({ formData }: { formData: FormSchema }) => { const drop_ids: string[] = []; const drop_configs: any = []; const asset_datas: any = []; - const ticket_information: Record< - string, - { max_tickets: number; price: string; sale_start?: number; sale_end?: number } - > = {}; + const ticket_information: Record = {}; for (const ticket of formData.tickets) { const dropId = `${Date.now().toString()}-${ticket.name.replaceAll(' ', '').toLocaleLowerCase()}`; @@ -279,11 +276,6 @@ export const estimateCosts = ({ formData }: { formData: FormSchema }) => { ticket_information[`${dropId}`] = { max_tickets: ticket.maxSupply ?? 0, price: parseNearAmount(ticket.priceNear || '0')!.toString(), - sale_start: Date.now() || undefined, - sale_end: Date.parse(formData.date) || undefined, - // ------------ pattern for allowing start and end sales date individually for each ticket - // sale_start: ticket.salesValidThrough.startDate || undefined, - // sale_end: ticket.salesValidThrough.endDate || undefined, }; const dropConfig = { @@ -302,7 +294,7 @@ export const estimateCosts = ({ formData }: { formData: FormSchema }) => { }, ]; - drop_ids.push(dropId); + drop_ids.push(dropId); //why do we do all this if we're just calculating & returning the estimated costs? asset_datas.push(assetData); drop_configs.push(dropConfig); } @@ -378,7 +370,7 @@ export const createPayload = async ({ const asset_datas: any = []; const ticket_information: Record< string, - { max_tickets: number; price: string; sale_start?: number; sale_end?: number } + { max_tickets: number; price: string; sale_start: number; sale_end: number } > = {}; for (const ticket of formData.tickets) { @@ -397,7 +389,11 @@ export const createPayload = async ({ // price: parseNearAmount(ticket.price)!.toString(), priceNear: ticket.priceNear, priceFiat: ticket.priceFiat, - salesValidThrough: ticket.salesValidThrough, + salesValidThrough: { + ...ticket.salesValidThrough, + startDate: Date.parse(ticket.salesValidThrough.startDate.toString()), + endDate: Date.parse(ticket.salesValidThrough.endDate!.toString()), + }, passValidThrough: ticket.passValidThrough, maxSupply: ticket.maxSupply, limitPerUser: ticket.maxPurchases, @@ -414,11 +410,8 @@ export const createPayload = async ({ ticket_information[`${dropId}`] = { max_tickets: ticket.maxSupply ?? 0, price: parseNearAmount(ticket.priceNear || '0')!.toString(), - sale_start: Date.now() || undefined, - sale_end: Date.parse(formData.date) || undefined, - // ------------ pattern for allowing start and end sales date individually for each ticket - // sale_start: ticket.salesValidThrough.startDate || undefined, - // sale_end: ticket.salesValidThrough.endDate || undefined, + sale_start: Date.parse(ticket.salesValidThrough.startDate.toString()), + sale_end: Date.parse(ticket.salesValidThrough.endDate!.toString()), }; const dropConfig = { From 4f89d6828558aff00e65cb02998d0da58644e92f Mon Sep 17 00:00:00 2001 From: Charles Garrett Date: Tue, 23 Jul 2024 12:24:38 -0400 Subject: [PATCH 2/3] chore: incremental step towards complete ticketing flow - redirect to stripe for paid tickets --- apps/ticketing/src/utils/purchase.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/apps/ticketing/src/utils/purchase.ts b/apps/ticketing/src/utils/purchase.ts index 40ffed8..6bcca5a 100644 --- a/apps/ticketing/src/utils/purchase.ts +++ b/apps/ticketing/src/utils/purchase.ts @@ -47,13 +47,6 @@ type PurchaseTicketOptions = { viewAccount: Account | null; }; -type PurchaseWorkerResponse = { - tickets: { - public_key: string; - secret_key: string; - }[]; -}; - type PurchasedTicket = { secretKey: string; }; @@ -138,8 +131,13 @@ export async function purchaseTickets({ }); if (response.ok) { - const data = (await response.json()) as PurchaseWorkerResponse; - data.tickets.forEach((t) => purchases.push({ secretKey: t.secret_key })); + const data = await response.json(); + if (!ticketIsFree) { + // redirect to stripe for checkout + window.location.href = data.stripe_url; + } else { + data.tickets.forEach((t: { secret_key: any }) => purchases.push({ secretKey: t.secret_key })); + } } else { /* TODO: We'll need to think through how we redirect to Stripe after exiting this loop. From cce4449cb452e02907f61b823e9daa54bc56553d Mon Sep 17 00:00:00 2001 From: Charles Garrett Date: Wed, 24 Jul 2024 12:37:22 -0400 Subject: [PATCH 3/3] prettier --- apps/ticketing/src/utils/helpers.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/apps/ticketing/src/utils/helpers.ts b/apps/ticketing/src/utils/helpers.ts index bd7ffba..a58820e 100644 --- a/apps/ticketing/src/utils/helpers.ts +++ b/apps/ticketing/src/utils/helpers.ts @@ -310,10 +310,8 @@ export const createPayload = async ({ const drop_ids: string[] = []; const drop_configs: any = []; const asset_datas: any = []; - const marketTicketInfo: Record< - string, - { max_tickets: number; price: string; sale_start: number; sale_end: number } - > = {}; + const marketTicketInfo: Record = + {}; for (const ticket of formData.tickets) { const dropId = `${Date.now().toString()}-${ticket.name.replaceAll(' ', '').toLocaleLowerCase()}`;