This commit is contained in:
2026-05-28 03:06:19 +08:00
parent d7e16ee9c4
commit 6eaa171ba4
8 changed files with 76 additions and 9 deletions

View File

@@ -12,6 +12,8 @@ export interface OTPBindCallbacks {
export interface OTPBindState {
mobile: string;
otp: string;
password: string;
needPassword: boolean;
step: 'mobile' | 'otp' | 'processing';
loading: boolean;
otpData: any;
@@ -21,6 +23,7 @@ export interface OTPBindState {
export interface OTPBindActions {
setMobile: (mobile: string) => void;
setOtp: (otp: string) => void;
setPassword: (password: string) => void;
requestOTP: () => Promise<void>;
verifyOTP: () => Promise<void>;
resetToMobile: () => void;
@@ -39,6 +42,8 @@ export function useOTPBind(
): [OTPBindState, OTPBindActions] {
const [mobile, setMobile] = useState('');
const [otp, setOtp] = useState('');
const [password, setPassword] = useState('');
const [needPassword, setNeedPassword] = useState(false);
const [step, setStep] = useState<'mobile' | 'otp' | 'processing'>('mobile');
const [loading, setLoading] = useState(false);
const [otpData, setOtpData] = useState<any>(null);
@@ -82,6 +87,7 @@ export function useOTPBind(
if (response.success) {
setOtpData(response.data);
setNeedPassword(!!response.data?.needPassword);
setStep('otp');
setErrorMessage('');
} else {
@@ -107,6 +113,12 @@ export function useOTPBind(
onError(msg);
return;
}
if (needPassword && !password.trim()) {
const msg = '请输入 Amazon 账号密码';
setErrorMessage(msg);
onError(msg);
return;
}
setLoading(true);
setErrorMessage('');
@@ -117,6 +129,7 @@ export function useOTPBind(
const response = await onVerifyOTP(walletType, {
mobile,
otp,
password: needPassword ? password : undefined,
...additionalParams,
...(otpData || {}),
});
@@ -144,11 +157,13 @@ export function useOTPBind(
const resetToMobile = () => {
setStep('mobile');
setOtp('');
setPassword('');
setNeedPassword(false);
setErrorMessage('');
};
return [
{ mobile, otp, step, loading, otpData, errorMessage },
{ setMobile, setOtp, requestOTP, verifyOTP, resetToMobile, clearError },
{ mobile, otp, password, needPassword, step, loading, otpData, errorMessage },
{ setMobile, setOtp, setPassword, requestOTP, verifyOTP, resetToMobile, clearError },
];
}