fix sms otp retriver

This commit is contained in:
2026-05-31 00:05:21 +08:00
parent 80bf462d2c
commit 557931892f
6 changed files with 168 additions and 74 deletions

View File

@@ -6,7 +6,9 @@ import {
Text,
StyleSheet,
ActivityIndicator,
Platform,
} from 'react-native';
import { normalizeHintPhone, requestPhoneNumberHint } from '../utils/smsRetriever';
import { WalletType } from 'rnwalletman';
import { useOTPBind } from '../hooks/useOTPBind';
@@ -57,6 +59,29 @@ export const OTPBindUI: React.FC<OTPBindUIProps> = ({
const isLoading = state.loading || state.step === 'processing';
const pickPhoneFromSystem = async () => {
if (Platform.OS !== 'android' || isLoading) return;
try {
const raw = await requestPhoneNumberHint();
const digits = normalizeHintPhone(raw, mobileLength);
if (digits.length === mobileLength) {
actions.setMobile(digits);
if (state.errorMessage) actions.clearError();
}
} catch {
/* 用户取消 */
}
};
const renderPickPhone = () => {
if (Platform.OS !== 'android') return null;
return (
<TouchableOpacity style={styles.linkBtn} onPress={pickPhoneFromSystem} disabled={isLoading}>
<Text style={[styles.linkText, isLoading && styles.linkTextDisabled]}></Text>
</TouchableOpacity>
);
};
const renderResendOtp = () => {
if (!state.otpSent) return null;
const disabled = isLoading || state.resendCountdown > 0;
@@ -98,6 +123,7 @@ export const OTPBindUI: React.FC<OTPBindUIProps> = ({
}}
editable={!state.formStarted && !isLoading}
/>
{!state.formStarted && renderPickPhone()}
{state.formStarted && state.passwordRequired && (
<>
<Text style={styles.label}>{passwordLabel}</Text>
@@ -206,6 +232,7 @@ export const OTPBindUI: React.FC<OTPBindUIProps> = ({
}}
editable={!isLoading}
/>
{renderPickPhone()}
<TouchableOpacity
style={[styles.btn, isLoading && styles.btnDisabled]}
onPress={actions.requestOTP}