自动读取短信
This commit is contained in:
@@ -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]);
|
||||
|
||||
Reference in New Issue
Block a user