自动读取短信
This commit is contained in:
@@ -6,9 +6,7 @@ import {
|
||||
Text,
|
||||
StyleSheet,
|
||||
ActivityIndicator,
|
||||
Platform,
|
||||
} from 'react-native';
|
||||
import { normalizeHintPhone, requestPhoneNumberHint } from '../utils/smsRetriever';
|
||||
import { WalletType } from 'rnwalletman';
|
||||
import { useOTPBind } from '../hooks/useOTPBind';
|
||||
|
||||
@@ -59,29 +57,6 @@ 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;
|
||||
@@ -123,7 +98,6 @@ export const OTPBindUI: React.FC<OTPBindUIProps> = ({
|
||||
}}
|
||||
editable={!state.formStarted && !isLoading}
|
||||
/>
|
||||
{!state.formStarted && renderPickPhone()}
|
||||
{state.formStarted && state.passwordRequired && (
|
||||
<>
|
||||
<Text style={styles.label}>{passwordLabel}</Text>
|
||||
@@ -160,6 +134,7 @@ export const OTPBindUI: React.FC<OTPBindUIProps> = ({
|
||||
{state.otpSent && (
|
||||
<>
|
||||
<Text style={styles.hint}>OTP sent to {state.mobile}</Text>
|
||||
<Text style={styles.consentHint}>收到短信后点「允许」可填入验证码</Text>
|
||||
<Text style={styles.label}>Verification code</Text>
|
||||
<TextInput
|
||||
style={[styles.input, !!state.errorMessage && styles.inputError]}
|
||||
@@ -232,7 +207,6 @@ export const OTPBindUI: React.FC<OTPBindUIProps> = ({
|
||||
}}
|
||||
editable={!isLoading}
|
||||
/>
|
||||
{renderPickPhone()}
|
||||
<TouchableOpacity
|
||||
style={[styles.btn, isLoading && styles.btnDisabled]}
|
||||
onPress={actions.requestOTP}
|
||||
@@ -251,6 +225,7 @@ export const OTPBindUI: React.FC<OTPBindUIProps> = ({
|
||||
{showOtp && (
|
||||
<>
|
||||
<Text style={styles.hint}>OTP sent to {state.mobile}</Text>
|
||||
<Text style={styles.consentHint}>收到短信后点「允许」可填入验证码</Text>
|
||||
{!!state.errorMessage && (
|
||||
<Text style={styles.errorText}>{state.errorMessage}</Text>
|
||||
)}
|
||||
@@ -338,6 +313,13 @@ const styles = StyleSheet.create({
|
||||
textAlign: 'center',
|
||||
marginBottom: 14,
|
||||
},
|
||||
consentHint: {
|
||||
fontSize: 11,
|
||||
color: '#888',
|
||||
textAlign: 'center',
|
||||
marginTop: -8,
|
||||
marginBottom: 12,
|
||||
},
|
||||
input: {
|
||||
borderWidth: 1.5,
|
||||
borderColor: '#e0e0e0',
|
||||
|
||||
Reference in New Issue
Block a user