Skip to content

Commit

Permalink
fix quote flag (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sladuca authored Jan 16, 2025
1 parent 20cf70a commit 73c58be
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
20 changes: 6 additions & 14 deletions src/lib/Quote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { Row } from "./Row.tsx";
import dayjs from "dayjs";
import { GPUS_PER_NODE } from "./constants.ts";
import React from "react";
import { getPricePerGpuHourFromQuote, getTotalPrice } from "./buy/index.tsx";
import ms from "ms";

export default function QuoteDisplay(props: { quote: Quote }) {
if (!props.quote) {
Expand All @@ -21,27 +23,17 @@ export default function QuoteDisplay(props: { quote: Quote }) {
);
}

const durationSeconds = dayjs(props.quote.end_at).diff(
dayjs(props.quote.start_at),
"seconds"
);
const durationHours = durationSeconds / 3600;
const pricePerHour =
props.quote.price /
durationHours /
GPUS_PER_NODE /
props.quote.quantity /
100;
const priceTotal = props.quote.price / 100;
const pricePerGpuHourCents = getPricePerGpuHourFromQuote(props.quote);
const totalPrice = props.quote.price / 100;

return (
<Box flexDirection="column" paddingBottom={1}>
<Row
headWidth={10}
head="rate"
value={`$${pricePerHour.toFixed(2)}/gpu/hr`}
value={`~$${(pricePerGpuHourCents / 100).toFixed(2)}/gpu/hr`}
/>
<Row headWidth={10} head="total" value={`$${priceTotal.toFixed(2)}`} />
<Row headWidth={10} head="total" value={`$${totalPrice.toFixed(2)}`} />
</Box>
);
}
Expand Down
10 changes: 4 additions & 6 deletions src/lib/buy/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function QuoteComponent(props: { options: SfBuyOptions }) {
}
setQuote(quote);
})();
}, [props.options]);
}, []);

return isLoading ? (
<Box gap={1}>
Expand Down Expand Up @@ -172,8 +172,6 @@ function QuoteAndBuy(props: { options: SfBuyOptions }) {
// submit a quote request, handle loading state
useEffect(() => {
(async () => {
const quote = await getQuoteFromParsedSfBuyOptions(props.options);

// Grab the price per GPU hour, either
let pricePerGpuHour: number | null = parsePricePerGpuHour(
props.options.price
Expand Down Expand Up @@ -230,7 +228,7 @@ function roundEndDate(endDate: Date) {
return dayjs(endDate).add(1, "hour").startOf("hour");
}

function getTotalPrice(
export function getTotalPrice(
pricePerGpuHour: number,
size: number,
durationInHours: number
Expand Down Expand Up @@ -297,7 +295,7 @@ function BuyOrderPreview(props: {
<Row
headWidth={7}
head="rate"
value={`$${(props.price / 100).toFixed(2)}/gpu/hr`}
value={`~$${(props.price / 100).toFixed(2)}/gpu/hr`}
/>
<Row headWidth={7} head="total" value={`$${totalPrice.toFixed(2)}`} />
</Box>
Expand Down Expand Up @@ -567,7 +565,7 @@ export async function placeBuyOrder(options: {
return data;
}

function getPricePerGpuHourFromQuote(quote: NonNullable<Quote>) {
export function getPricePerGpuHourFromQuote(quote: NonNullable<Quote>) {
const durationSeconds = dayjs(quote.end_at).diff(
parseStartAsDate(quote.start_at)
);
Expand Down

0 comments on commit 73c58be

Please sign in to comment.