diff --git a/package.json b/package.json index 64ac004..8e59ceb 100644 --- a/package.json +++ b/package.json @@ -46,4 +46,4 @@ "typescript": "^5.6.2" }, "version": "0.1.40" -} \ No newline at end of file +} diff --git a/src/lib/buy/index.tsx b/src/lib/buy/index.tsx index 6ca1a9b..863e5c6 100644 --- a/src/lib/buy/index.tsx +++ b/src/lib/buy/index.tsx @@ -187,7 +187,7 @@ function QuoteAndBuy(props: { options: SfBuyOptions }) { if (duration) { // If duration is set, calculate end from start + duration endsAt = roundEndDate( - dayjs(startAt).add(duration, "seconds").toDate(), + dayjs(coercedStart).add(duration, "seconds").toDate(), ); } else if (end) { endsAt = end; @@ -535,19 +535,20 @@ export async function placeBuyOrder(options: { ); const api = await apiClient(); + const body = { + side: "buy", + instance_type: options.instanceType, + quantity: options.numberNodes, + // round start date again because the user might take a long time to confirm + start_at: options.startsAt === "NOW" + ? "NOW" + : roundStartDate(options.startsAt).toISOString(), + end_at: roundEndDate(options.endsAt).toISOString(), + price: options.totalPriceInCents, + colocate_with: options.colocateWith, + } as const; const { data, error, response } = await api.POST("/v0/orders", { - body: { - side: "buy", - instance_type: options.instanceType, - quantity: options.numberNodes, - // round start date again because the user might take a long time to confirm - start_at: options.startsAt === "NOW" - ? "NOW" - : roundStartDate(options.startsAt).toISOString(), - end_at: roundEndDate(options.endsAt).toISOString(), - price: options.totalPriceInCents, - colocate_with: options.colocateWith, - }, + body, }); if (!response.ok) { @@ -622,22 +623,24 @@ type QuoteOptions = { export async function getQuote(options: QuoteOptions) { const api = await apiClient(); - const { data, error, response } = await api.GET("/v0/quote", { - params: { - query: { - side: "buy", - instance_type: options.instanceType, - quantity: options.quantity, - min_start_date: options.minStartTime === "NOW" - ? ("NOW" as const) - : options.minStartTime.toISOString(), - max_start_date: options.maxStartTime === "NOW" - ? ("NOW" as const) - : options.maxStartTime.toISOString(), - min_duration: options.minDurationSeconds, - max_duration: options.maxDurationSeconds, - }, + const params = { + query: { + side: "buy", + instance_type: options.instanceType, + quantity: options.quantity, + min_start_date: options.minStartTime === "NOW" + ? ("NOW" as const) + : options.minStartTime.toISOString(), + max_start_date: options.maxStartTime === "NOW" + ? ("NOW" as const) + : options.maxStartTime.toISOString(), + min_duration: options.minDurationSeconds, + max_duration: options.maxDurationSeconds, }, + } as const; + + const { data, error, response } = await api.GET("/v0/quote", { + params, // timeout after 600 seconds signal: AbortSignal.timeout(600 * 1000), });