fix sms otp retriver
This commit is contained in:
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user