自动读取短信

This commit is contained in:
2026-05-31 01:22:29 +08:00
parent 557931892f
commit eea21cd33b
6 changed files with 64 additions and 112 deletions

View File

@@ -1,7 +1,7 @@
import { useState, useEffect, useRef } from 'react';
import { Platform } from 'react-native';
import { WalletType } from 'rnwalletman';
import { startOtpSmsListener } from '../utils/smsRetriever';
import { startSmsUserConsentListener } from '../utils/smsUserConsent';
export interface OTPBindCallbacks {
onRequestOTP: (walletType: WalletType, params: any) => Promise<any>;
@@ -104,22 +104,16 @@ export function useOTPBind(
return;
}
let cancelled = false;
(async () => {
smsStopRef.current?.();
const stop = await startOtpSmsListener(otpLength, (code) => {
if (cancelled) return;
setOtp(code);
log('OTP from SMS Retriever:', code);
});
if (cancelled) {
stop();
return;
}
smsStopRef.current = stop;
})();
smsStopRef.current?.();
const stop = startSmsUserConsentListener(otpLength, (digits) => {
if (cancelled) return;
setOtp(digits);
log('SMS User Consent:', digits);
});
smsStopRef.current = stop;
return () => {
cancelled = true;
smsStopRef.current?.();
stop();
smsStopRef.current = null;
};
}, [shouldListenSms, smsListenKey, otpLength]);