Revert "fix: defer loading stripe"

This reverts commit 58cdaad889.
This commit is contained in:
Maya 2025-09-03 00:07:11 +08:00
parent 237aa402cf
commit ce88e01a22
1 changed files with 22 additions and 11 deletions

View File

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