fix(billing): remove redundant account bootstrap request
Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -109,24 +109,6 @@ export function useBillingPanel(input: {
|
||||
? activeSubscription.productCode
|
||||
: null;
|
||||
|
||||
const fetchAccountData = useCallback(async (): Promise<BillingAccount | null> => {
|
||||
try {
|
||||
const response = await fetch("/api/account", { cache: "no-store" });
|
||||
if (response.status === 401) {
|
||||
window.location.assign("/login");
|
||||
return null;
|
||||
}
|
||||
const payload = await response.json().catch(() => null);
|
||||
if (!response.ok) throw new Error(payload?.error || "暂时无法读取账户信息");
|
||||
const next = toBillingAccount(payload as Account);
|
||||
setAccountError("");
|
||||
return next;
|
||||
} catch (caught) {
|
||||
setAccountError(caught instanceof Error ? caught.message : "暂时无法读取账户信息");
|
||||
return null;
|
||||
}
|
||||
}, []);
|
||||
|
||||
const resetPaymentState = useCallback(() => {
|
||||
setPaymentEnabled(false);
|
||||
setPaymentPackages([]);
|
||||
@@ -216,8 +198,7 @@ export function useBillingPanel(input: {
|
||||
setRedeemCode("");
|
||||
setRedeemDone(true);
|
||||
setRedeemMessage(result.message || `本次到账 ${awarded} 点,最新余额 ${result.credits} 点。`);
|
||||
const refreshed = await fetchAccountData();
|
||||
notifyBalanceChanged(refreshed?.credits ?? result.credits);
|
||||
notifyBalanceChanged(result.credits);
|
||||
} catch (caught) {
|
||||
setRedeemError(caught instanceof Error ? caught.message : "兑换失败,请稍后重试");
|
||||
} finally {
|
||||
@@ -281,8 +262,9 @@ export function useBillingPanel(input: {
|
||||
status: paid ? "paid" : failed ? "failed" : "pending",
|
||||
} : current);
|
||||
if (paid) {
|
||||
const refreshed = await fetchAccountData();
|
||||
notifyBalanceChanged(refreshed?.credits ?? 0);
|
||||
if (typeof payload.credits === "number") {
|
||||
notifyBalanceChanged(payload.credits);
|
||||
}
|
||||
}
|
||||
};
|
||||
let timer = 0;
|
||||
@@ -308,7 +290,7 @@ export function useBillingPanel(input: {
|
||||
stopPolling();
|
||||
document.removeEventListener("visibilitychange", onVisibilityChange);
|
||||
};
|
||||
}, [fetchAccountData, paymentOrder]);
|
||||
}, [paymentOrder]);
|
||||
|
||||
return {
|
||||
account: toBillingAccount(seedAccount),
|
||||
|
||||
@@ -3,5 +3,7 @@ export function loadBillingPanel() {
|
||||
}
|
||||
|
||||
export function prefetchBillingPanel(): void {
|
||||
void loadBillingPanel();
|
||||
// Hover/pointer prefetch is opportunistic. An offline chunk failure must not
|
||||
// become an unhandled rejection handled by StaleClientRecovery as a reload.
|
||||
void loadBillingPanel().catch(() => undefined);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user