Skip to content

Commit

Permalink
refactor: simplify getTopUpQuote into forwardToCheckoutSession PE-5161
Browse files Browse the repository at this point in the history
  • Loading branch information
fedellen committed Dec 7, 2023
1 parent f3cab45 commit b65095a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
6 changes: 2 additions & 4 deletions src/GiftForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from "./constants";
import useDebounce from "./hooks/useDebounce";
import "./GiftForm.css";
import { getTopUpQuote } from "./utils/getTopUpQuote";
import { forwardToCheckoutSession } from "./utils/forwardToCheckoutSession";
import { useWincForOneGiB } from "./hooks/useWincForOneGiB";
import { useCreditsForFiat } from "./hooks/useCreditsForFiat";

Expand Down Expand Up @@ -58,9 +58,7 @@ export function GiftForm({ errorCallback }: GiftFormProps) {
return;
}

getTopUpQuote(usdAmount, recipientEmail).then((topUpQuote) => {
window.location.href = topUpQuote.paymentSession.url;
});
forwardToCheckoutSession(usdAmount, recipientEmail);
};

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { TopUpRawResponse } from "@ardrive/turbo-sdk";
import { paymentServiceUrl } from "../constants";

export async function getTopUpQuote(
export async function forwardToCheckoutSession(
usdAmount: number,
recipientEmail: string,
): Promise<TopUpRawResponse> {
): Promise<void> {
// TODO: support emails on turbo sdk
// return turboFactory.unauthenticated(turboConfig).createCheckoutSession({ amount: USD(usdAmount / 100), email: recipientEmail })
const response = await fetch(
Expand All @@ -14,5 +13,6 @@ export async function getTopUpQuote(
);
const data = await response.json();

return data;
// Send user to checkout session
window.location.href = data.paymentSession.url;
}

0 comments on commit b65095a

Please sign in to comment.