Files
PolyWeather/frontend/components/account/usePaymentState.ts
T
2569718930@qq.com 89394e12ef 拆分 AccountCenter 超大组件:提取类型、常量、钱包、支付等独立模块
- AccountCenter.tsx 从 3565 行缩减约 1000 行
- 新增 8 个模块:types / constants / formatters / account-copy / wallet / payment-utils / usePaymentState / AccountInfoRow
- 同步更新 paymentShell 测试

Confidence: high
2026-05-23 23:30:48 +08:00

75 lines
2.0 KiB
TypeScript

import { useCallback, useState } from "react";
import type { CreatedIntent } from "./types";
export type PaymentTxValidationState = {
loading: boolean;
checked: boolean;
valid?: boolean;
reason?: string;
detail?: string;
checks?: Record<string, unknown>;
};
export function usePaymentState() {
const [paymentBusy, setPaymentBusy] = useState(false);
const [paymentInfo, setPaymentInfo] = useState("");
const [paymentError, setPaymentError] = useState("");
const [lastIntentId, setLastIntentId] = useState("");
const [lastTxHash, setLastTxHash] = useState("");
const [telegramBindOpening, setTelegramBindOpening] = useState(false);
const [manualPayment, setManualPayment] = useState<
CreatedIntent["direct_payment"] | null
>(null);
const [manualTxHash, setManualTxHash] = useState("");
const [txValidation, setTxValidation] = useState<PaymentTxValidationState>({
loading: false,
checked: false,
});
const [paymentMethodTab, setPaymentMethodTab] = useState<"wallet" | "manual">(
"wallet",
);
const [lastPaymentStartedAt, setLastPaymentStartedAt] = useState(0);
const clearPaymentMessages = useCallback(() => {
setPaymentError("");
setPaymentInfo("");
}, []);
const clearPaymentState = useCallback(() => {
setLastIntentId("");
setLastTxHash("");
setManualPayment(null);
setManualTxHash("");
setLastPaymentStartedAt(0);
setTxValidation({ loading: false, checked: false });
}, []);
return {
paymentBusy,
setPaymentBusy,
paymentInfo,
setPaymentInfo,
paymentError,
setPaymentError,
lastIntentId,
setLastIntentId,
lastTxHash,
setLastTxHash,
telegramBindOpening,
setTelegramBindOpening,
manualPayment,
setManualPayment,
manualTxHash,
setManualTxHash,
txValidation,
setTxValidation,
paymentMethodTab,
setPaymentMethodTab,
lastPaymentStartedAt,
setLastPaymentStartedAt,
clearPaymentMessages,
clearPaymentState,
};
}