fix: defer loading stripe

This commit is contained in:
Maya 2025-08-21 18:11:56 +08:00
parent 2f5fddcc6e
commit 58cdaad889
1 changed files with 11 additions and 22 deletions

View File

@ -23,11 +23,8 @@
import Panel from "$lib/components/visual/Panel.svelte";
import { effects } from "$lib/store/index.svelte";
import { addToast } from "$lib/store/ToastProvider";
import {
loadStripe,
type Stripe,
type StripeElements,
} from "@stripe/stripe-js";
import { loadStripe } from "@stripe/stripe-js/pure";
import { type Stripe, type StripeElements } from "@stripe/stripe-js";
import clsx from "clsx";
import {
CalendarHeartIcon,
@ -67,10 +64,7 @@
if (!res.ok) {
paymentState = "prepay";
addToast(
"error",
m["about.donate.payment_error"](),
);
addToast("error", m["about.donate.payment_error"]());
return;
}
@ -88,10 +82,6 @@
const payDuration = 400;
const transition = "cubic-bezier(0.23, 1, 0.320, 1)";
onMount(async () => {
stripe = await loadStripe(PUB_STRIPE_KEY);
});
const donate = async () => {
if (!stripe || !clientSecret || !elements) return;
@ -102,9 +92,9 @@
const period = submitResult.error.message?.endsWith(".") ? "" : ".";
addToast(
"error",
m["about.donate.payment_failed"]({
m["about.donate.payment_failed"]({
message: submitResult.error.message || "",
period
period,
}),
);
enablePay = true;
@ -124,9 +114,9 @@
const period = res.error.message?.endsWith(".") ? "" : ".";
addToast(
"error",
m["about.donate.payment_failed"]({
m["about.donate.payment_failed"]({
message: res.error.message || "",
period
period,
}),
);
} else {
@ -152,10 +142,7 @@
addToast("success", m["about.donate.thank_you"]());
break;
default:
addToast(
"error",
m["about.donate.donation_error"](),
);
addToast("error", m["about.donate.donation_error"]());
}
goto("/about");
@ -298,7 +285,9 @@
class="btn w-full h-12 bg-accent-red text-black rounded-full mt-4"
onclick={donate}
>
{m["about.donate.donate_amount"]({ amount: amount.toFixed(2) })}
{m["about.donate.donate_amount"]({
amount: amount.toFixed(2),
})}
</button>
</div>
</div>